public function testCreateRoleThrowsLimitationValidationException()
{
$limitationMock = $this->getMock('eZ\\Publish\\API\\Repository\\Values\\User\\Limitation\\RoleLimitation');
$limitationTypeMock = $this->getMock('eZ\\Publish\\SPI\\Limitation\\Type');
$limitationMock->expects($this->any())->method('getIdentifier')->will($this->returnValue('mockIdentifier'));
$limitationTypeMock->expects($this->once())->method('acceptValue')->with($this->equalTo($limitationMock));
$limitationTypeMock->expects($this->once())->method('validate')->with($this->equalTo($limitationMock))->will($this->returnValue(array(42)));
$settings = array('policyMap' => array('mockModule' => array('mockFunction' => array('mockIdentifier' => true))), 'limitationTypes' => array('mockIdentifier' => $limitationTypeMock));
$roleServiceMock = $this->getPartlyMockedRoleService(array('loadRoleByIdentifier'), $settings);
$repository = $this->getRepositoryMock();
/** @var \eZ\Publish\API\Repository\Values\User\RoleCreateStruct $roleCreateStructMock */
$roleCreateStructMock = $this->getMock('eZ\\Publish\\API\\Repository\\Values\\User\\RoleCreateStruct');
$policyCreateStructMock = $this->getMock('eZ\\Publish\\API\\Repository\\Values\\User\\PolicyCreateStruct');
/* @var \eZ\Publish\API\Repository\Values\User\PolicyCreateStruct $policyCreateStructMock */
$policyCreateStructMock->module = 'mockModule';
$policyCreateStructMock->function = 'mockFunction';
$roleCreateStructMock->identifier = 'mockIdentifier';
$roleServiceMock->expects($this->once())->method('loadRoleByIdentifier')->with($this->equalTo('mockIdentifier'))->will($this->throwException(new NotFoundException('Role', 'mockIdentifier')));
/* @var \PHPUnit_Framework_MockObject_MockObject $roleCreateStructMock */
$roleCreateStructMock->expects($this->once())->method('getPolicies')->will($this->returnValue(array($policyCreateStructMock)));
/* @var \PHPUnit_Framework_MockObject_MockObject $policyCreateStructMock */
$policyCreateStructMock->expects($this->once())->method('getLimitations')->will($this->returnValue(array($limitationMock)));
$repository->expects($this->once())->method('hasAccess')->with($this->equalTo('role'), $this->equalTo('create'))->will($this->returnValue(true));
/* @var \eZ\Publish\API\Repository\Values\User\RoleCreateStruct $roleCreateStructMock */
$roleServiceMock->createRole($roleCreateStructMock);
}