public function testHasAccessReturnsException(array $roles, array $roleAssignments)
{
/** @var $userHandlerMock \PHPUnit_Framework_MockObject_MockObject */
$userHandlerMock = $this->getPersistenceMock()->userHandler();
$roleDomainMapper = $this->getRoleDomainMapperMock();
$permissionResolverMock = $this->getPermissionResolverMock(['getCurrentUserReference']);
$permissionResolverMock->expects($this->once())->method('getCurrentUserReference')->will($this->returnValue(new UserReference(14)));
$userHandlerMock->expects($this->once())->method('loadRoleAssignmentsByGroupId')->with($this->isType('integer'), $this->equalTo(true))->will($this->returnValue($roleAssignments));
foreach ($roleAssignments as $at => $roleAssignment) {
$userHandlerMock->expects($this->at($at + 1))->method('loadRole')->with($roleAssignment->roleId)->will($this->returnValue($roles[$roleAssignment->roleId]));
}
$count = 0;
/* @var $roleAssignments \eZ\Publish\SPI\Persistence\User\RoleAssignment[] */
foreach ($roleAssignments as $i => $roleAssignment) {
$permissionSet = array('limitation' => null);
foreach ($roles[$roleAssignment->roleId]->policies as $k => $policy) {
$policyName = 'policy-' . $i . '-' . $k;
if ($policy->limitations === 'notfound') {
$return = $this->throwException(new LimitationNotFoundException('notfound'));
} else {
$return = $this->returnValue($policyName);
$permissionSet['policies'][] = $policyName;
}
$roleDomainMapper->expects($this->at($count++))->method('buildDomainPolicyObject')->with($policy)->will($return);
if ($policy->limitations === 'notfound') {
break 2;
// no more execution after exception
}
}
}
$permissionResolverMock->hasAccess('test-module', 'test-function');
}