@@ 498-525 (lines=28) @@ | ||
495 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testRemoveRoleAssignment |
|
496 | * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testCreateUser |
|
497 | */ |
|
498 | public function testRemoveRoleAssignmentThrowsUnauthorizedException() |
|
499 | { |
|
500 | $this->expectException(\eZ\Publish\API\Repository\Exceptions\UnauthorizedException::class); |
|
501 | ||
502 | $repository = $this->getRepository(); |
|
503 | $roleService = $repository->getRoleService(); |
|
504 | $permissionResolver = $repository->getPermissionResolver(); |
|
505 | ||
506 | /* BEGIN: Use Case */ |
|
507 | $user = $this->createUserVersion1(); |
|
508 | ||
509 | $role = $this->createRole(); |
|
510 | ||
511 | // Assign new role to "Editor" user |
|
512 | $roleService->assignRoleToUser($role, $user); |
|
513 | ||
514 | // Set "Editor" user as current user. |
|
515 | $permissionResolver->setCurrentUserReference($user); |
|
516 | $roleAssignments = $roleService->getRoleAssignmentsForUser($user); |
|
517 | ||
518 | // This call will fail with an "UnauthorizedException" |
|
519 | foreach ($roleAssignments as $roleAssignment) { |
|
520 | if ($roleAssignment->role->id === $role->id) { |
|
521 | $roleService->removeRoleAssignment($roleAssignment); |
|
522 | } |
|
523 | } |
|
524 | /* END: Use Case */ |
|
525 | } |
|
526 | ||
527 | /** |
|
528 | * Test for the getRoleAssignments() method. |
@@ 1963-1990 (lines=28) @@ | ||
1960 | * @see \eZ\Publish\API\Repository\RoleService::removeRoleAssignment() |
|
1961 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAssignRoleToUser |
|
1962 | */ |
|
1963 | public function testRemoveRoleAssignment() |
|
1964 | { |
|
1965 | $repository = $this->getRepository(); |
|
1966 | $roleService = $repository->getRoleService(); |
|
1967 | ||
1968 | /* BEGIN: Use Case */ |
|
1969 | $user = $this->createUserVersion1(); |
|
1970 | ||
1971 | // Load the existing "Member" role |
|
1972 | $role = $roleService->loadRoleByIdentifier('Member'); |
|
1973 | ||
1974 | // Assign the "Member" role to the newly created user |
|
1975 | $roleService->assignRoleToUser($role, $user); |
|
1976 | ||
1977 | // Unassign user from role |
|
1978 | $roleAssignments = $roleService->getRoleAssignmentsForUser($user); |
|
1979 | foreach ($roleAssignments as $roleAssignment) { |
|
1980 | if ($roleAssignment->role->id === $role->id) { |
|
1981 | $roleService->removeRoleAssignment($roleAssignment); |
|
1982 | } |
|
1983 | } |
|
1984 | // The assignments array will not contain the new role<->user assignment |
|
1985 | $roleAssignments = $roleService->getRoleAssignments($role); |
|
1986 | /* END: Use Case */ |
|
1987 | ||
1988 | // Members + Editors + Partners |
|
1989 | $this->assertCount(3, $roleAssignments); |
|
1990 | } |
|
1991 | ||
1992 | /** |
|
1993 | * Test for the getRoleAssignmentsForUser() method. |