| @@ 2124-2156 (lines=33) @@ | ||
| 2121 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAssignRoleToUser |
|
| 2122 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testLoadRoleByIdentifier |
|
| 2123 | */ |
|
| 2124 | public function testAssignRoleToUserThrowsInvalidArgumentException() |
|
| 2125 | { |
|
| 2126 | $this->expectException(\eZ\Publish\API\Repository\Exceptions\InvalidArgumentException::class); |
|
| 2127 | ||
| 2128 | $repository = $this->getRepository(); |
|
| 2129 | ||
| 2130 | /* BEGIN: Use Case */ |
|
| 2131 | $roleService = $repository->getRoleService(); |
|
| 2132 | ||
| 2133 | // Load the existing "Anonymous" role |
|
| 2134 | $role = $roleService->loadRoleByIdentifier('Anonymous'); |
|
| 2135 | ||
| 2136 | // Get current user |
|
| 2137 | $currentUser = $repository->getCurrentUser(); |
|
| 2138 | ||
| 2139 | // Assign the "Anonymous" role to the current user |
|
| 2140 | try { |
|
| 2141 | $roleService->assignRoleToUser( |
|
| 2142 | $role, |
|
| 2143 | $currentUser |
|
| 2144 | ); |
|
| 2145 | } catch (Exception $e) { |
|
| 2146 | $this->fail('Got exception at first valid attempt to assign role'); |
|
| 2147 | } |
|
| 2148 | ||
| 2149 | // Re-Assign the "Anonymous" role to the current user |
|
| 2150 | // This call will fail with an InvalidArgumentException, because limitation is already assigned |
|
| 2151 | $roleService->assignRoleToUser( |
|
| 2152 | $role, |
|
| 2153 | $currentUser |
|
| 2154 | ); |
|
| 2155 | /* END: Use Case */ |
|
| 2156 | } |
|
| 2157 | ||
| 2158 | /** |
|
| 2159 | * Test for the assignRoleToUser() method. |
|
| @@ 538-559 (lines=22) @@ | ||
| 535 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testUnassignRoleFromUser |
|
| 536 | * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testCreateUser |
|
| 537 | */ |
|
| 538 | public function testUnassignRoleFromUserThrowsUnauthorizedException() |
|
| 539 | { |
|
| 540 | $this->expectException(\eZ\Publish\API\Repository\Exceptions\UnauthorizedException::class); |
|
| 541 | ||
| 542 | $repository = $this->getRepository(); |
|
| 543 | $roleService = $repository->getRoleService(); |
|
| 544 | ||
| 545 | /* BEGIN: Use Case */ |
|
| 546 | $user = $this->createUserVersion1(); |
|
| 547 | ||
| 548 | $role = $this->createRole(); |
|
| 549 | ||
| 550 | // Assign new role to "Editor" user |
|
| 551 | $roleService->assignRoleToUser($role, $user); |
|
| 552 | ||
| 553 | // Set "Editor" user as current user. |
|
| 554 | $repository->setCurrentUser($user); |
|
| 555 | ||
| 556 | // This call will fail with an "UnauthorizedException" |
|
| 557 | $roleService->unassignRoleFromUser($role, $user); |
|
| 558 | /* END: Use Case */ |
|
| 559 | } |
|
| 560 | ||
| 561 | /** |
|
| 562 | * Test for the getRoleAssignments() method. |
|