|
@@ 1912-1932 (lines=21) @@
|
| 1909 |
|
* @see \eZ\Publish\API\Repository\RoleService::assignRoleToUser() |
| 1910 |
|
* @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testGetRoleAssignments |
| 1911 |
|
*/ |
| 1912 |
|
public function testAssignRoleToUser() |
| 1913 |
|
{ |
| 1914 |
|
$repository = $this->getRepository(); |
| 1915 |
|
$roleService = $repository->getRoleService(); |
| 1916 |
|
|
| 1917 |
|
/* BEGIN: Use Case */ |
| 1918 |
|
$user = $this->createUserVersion1(); |
| 1919 |
|
|
| 1920 |
|
// Load the existing "Administrator" role |
| 1921 |
|
$role = $roleService->loadRoleByIdentifier('Administrator'); |
| 1922 |
|
|
| 1923 |
|
// Assign the "Administrator" role to the newly created user |
| 1924 |
|
$roleService->assignRoleToUser($role, $user); |
| 1925 |
|
|
| 1926 |
|
// The assignments array will contain the new role<->user assignment |
| 1927 |
|
$roleAssignments = $roleService->getRoleAssignments($role); |
| 1928 |
|
/* END: Use Case */ |
| 1929 |
|
|
| 1930 |
|
// Administrator + Example User |
| 1931 |
|
$this->assertEquals(2, count($roleAssignments)); |
| 1932 |
|
} |
| 1933 |
|
|
| 1934 |
|
/** |
| 1935 |
|
* Test for the assignRoleToUser() method. |
|
@@ 2085-2115 (lines=31) @@
|
| 2082 |
|
* @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAssignRoleToUser |
| 2083 |
|
* @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testLoadRoleByIdentifier |
| 2084 |
|
*/ |
| 2085 |
|
public function testAssignRoleToUserThrowsInvalidArgumentException() |
| 2086 |
|
{ |
| 2087 |
|
$repository = $this->getRepository(); |
| 2088 |
|
|
| 2089 |
|
/* BEGIN: Use Case */ |
| 2090 |
|
$roleService = $repository->getRoleService(); |
| 2091 |
|
|
| 2092 |
|
// Load the existing "Anonymous" role |
| 2093 |
|
$role = $roleService->loadRoleByIdentifier('Anonymous'); |
| 2094 |
|
|
| 2095 |
|
// Get current user |
| 2096 |
|
$currentUser = $repository->getCurrentUser(); |
| 2097 |
|
|
| 2098 |
|
// Assign the "Anonymous" role to the current user |
| 2099 |
|
try { |
| 2100 |
|
$roleService->assignRoleToUser( |
| 2101 |
|
$role, |
| 2102 |
|
$currentUser |
| 2103 |
|
); |
| 2104 |
|
} catch (Exception $e) { |
| 2105 |
|
$this->fail('Got exception at first valid attempt to assign role'); |
| 2106 |
|
} |
| 2107 |
|
|
| 2108 |
|
// Re-Assign the "Anonymous" role to the current user |
| 2109 |
|
// This call will fail with an InvalidArgumentException, because limitation is already assigned |
| 2110 |
|
$roleService->assignRoleToUser( |
| 2111 |
|
$role, |
| 2112 |
|
$currentUser |
| 2113 |
|
); |
| 2114 |
|
/* END: Use Case */ |
| 2115 |
|
} |
| 2116 |
|
|
| 2117 |
|
/** |
| 2118 |
|
* Test for the assignRoleToUser() method. |
|
@@ 2327-2347 (lines=21) @@
|
| 2324 |
|
* @see \eZ\Publish\API\Repository\RoleService::assignRoleToUserGroup() |
| 2325 |
|
* @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testGetRoleAssignments |
| 2326 |
|
*/ |
| 2327 |
|
public function testAssignRoleToUserGroup() |
| 2328 |
|
{ |
| 2329 |
|
$repository = $this->getRepository(); |
| 2330 |
|
$roleService = $repository->getRoleService(); |
| 2331 |
|
|
| 2332 |
|
/* BEGIN: Use Case */ |
| 2333 |
|
$userGroup = $this->createUserGroupVersion1(); |
| 2334 |
|
|
| 2335 |
|
// Load the existing "Administrator" role |
| 2336 |
|
$role = $roleService->loadRoleByIdentifier('Administrator'); |
| 2337 |
|
|
| 2338 |
|
// Assign the "Administrator" role to the newly created user group |
| 2339 |
|
$roleService->assignRoleToUserGroup($role, $userGroup); |
| 2340 |
|
|
| 2341 |
|
// The assignments array will contain the new role<->group assignment |
| 2342 |
|
$roleAssignments = $roleService->getRoleAssignments($role); |
| 2343 |
|
/* END: Use Case */ |
| 2344 |
|
|
| 2345 |
|
// Administrator + Example Group |
| 2346 |
|
$this->assertEquals(2, count($roleAssignments)); |
| 2347 |
|
} |
| 2348 |
|
|
| 2349 |
|
/** |
| 2350 |
|
* Test for the assignRoleToUserGroup() method. |