|
@@ 652-673 (lines=22) @@
|
| 649 |
|
* @see \eZ\Publish\API\Repository\RoleService::loadRoleByIdentifier() |
| 650 |
|
* @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testCreateRole |
| 651 |
|
*/ |
| 652 |
|
public function testLoadRoleByIdentifier() |
| 653 |
|
{ |
| 654 |
|
$repository = $this->getRepository(); |
| 655 |
|
|
| 656 |
|
/* BEGIN: Use Case */ |
| 657 |
|
|
| 658 |
|
$roleService = $repository->getRoleService(); |
| 659 |
|
$roleCreate = $roleService->newRoleCreateStruct('roleName'); |
| 660 |
|
|
| 661 |
|
// @todo uncomment when support for multilingual names and descriptions is added EZP-24776 |
| 662 |
|
// $roleCreate->mainLanguageCode = 'eng-US'; |
| 663 |
|
|
| 664 |
|
$roleDraft = $roleService->createRole($roleCreate); |
| 665 |
|
$roleService->publishRoleDraft($roleDraft); |
| 666 |
|
|
| 667 |
|
// Load the newly created role by its identifier |
| 668 |
|
$role = $roleService->loadRoleByIdentifier('roleName'); |
| 669 |
|
|
| 670 |
|
/* END: Use Case */ |
| 671 |
|
|
| 672 |
|
$this->assertEquals('roleName', $role->identifier); |
| 673 |
|
} |
| 674 |
|
|
| 675 |
|
/** |
| 676 |
|
* Test for the loadRoleByIdentifier() method. |
|
@@ 1892-1912 (lines=21) @@
|
| 1889 |
|
* @see \eZ\Publish\API\Repository\RoleService::assignRoleToUser() |
| 1890 |
|
* @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testGetRoleAssignments |
| 1891 |
|
*/ |
| 1892 |
|
public function testAssignRoleToUser() |
| 1893 |
|
{ |
| 1894 |
|
$repository = $this->getRepository(); |
| 1895 |
|
$roleService = $repository->getRoleService(); |
| 1896 |
|
|
| 1897 |
|
/* BEGIN: Use Case */ |
| 1898 |
|
$user = $this->createUserVersion1(); |
| 1899 |
|
|
| 1900 |
|
// Load the existing "Administrator" role |
| 1901 |
|
$role = $roleService->loadRoleByIdentifier('Administrator'); |
| 1902 |
|
|
| 1903 |
|
// Assign the "Administrator" role to the newly created user |
| 1904 |
|
$roleService->assignRoleToUser($role, $user); |
| 1905 |
|
|
| 1906 |
|
// The assignments array will contain the new role<->user assignment |
| 1907 |
|
$roleAssignments = $roleService->getRoleAssignments($role); |
| 1908 |
|
/* END: Use Case */ |
| 1909 |
|
|
| 1910 |
|
// Administrator + Example User |
| 1911 |
|
$this->assertEquals(2, count($roleAssignments)); |
| 1912 |
|
} |
| 1913 |
|
|
| 1914 |
|
/** |
| 1915 |
|
* Test for the assignRoleToUser() method. |
|
@@ 2065-2095 (lines=31) @@
|
| 2062 |
|
* @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAssignRoleToUser |
| 2063 |
|
* @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testLoadRoleByIdentifier |
| 2064 |
|
*/ |
| 2065 |
|
public function testAssignRoleToUserThrowsInvalidArgumentException() |
| 2066 |
|
{ |
| 2067 |
|
$repository = $this->getRepository(); |
| 2068 |
|
|
| 2069 |
|
/* BEGIN: Use Case */ |
| 2070 |
|
$roleService = $repository->getRoleService(); |
| 2071 |
|
|
| 2072 |
|
// Load the existing "Anonymous" role |
| 2073 |
|
$role = $roleService->loadRoleByIdentifier('Anonymous'); |
| 2074 |
|
|
| 2075 |
|
// Get current user |
| 2076 |
|
$currentUser = $repository->getCurrentUser(); |
| 2077 |
|
|
| 2078 |
|
// Assign the "Anonymous" role to the current user |
| 2079 |
|
try { |
| 2080 |
|
$roleService->assignRoleToUser( |
| 2081 |
|
$role, |
| 2082 |
|
$currentUser |
| 2083 |
|
); |
| 2084 |
|
} catch (Exception $e) { |
| 2085 |
|
$this->fail('Got exception at first valid attempt to assign role'); |
| 2086 |
|
} |
| 2087 |
|
|
| 2088 |
|
// Re-Assign the "Anonymous" role to the current user |
| 2089 |
|
// This call will fail with an InvalidArgumentException, because limitation is already assigned |
| 2090 |
|
$roleService->assignRoleToUser( |
| 2091 |
|
$role, |
| 2092 |
|
$currentUser |
| 2093 |
|
); |
| 2094 |
|
/* END: Use Case */ |
| 2095 |
|
} |
| 2096 |
|
|
| 2097 |
|
/** |
| 2098 |
|
* Test for the assignRoleToUser() method. |
|
@@ 2307-2327 (lines=21) @@
|
| 2304 |
|
* @see \eZ\Publish\API\Repository\RoleService::assignRoleToUserGroup() |
| 2305 |
|
* @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testGetRoleAssignments |
| 2306 |
|
*/ |
| 2307 |
|
public function testAssignRoleToUserGroup() |
| 2308 |
|
{ |
| 2309 |
|
$repository = $this->getRepository(); |
| 2310 |
|
$roleService = $repository->getRoleService(); |
| 2311 |
|
|
| 2312 |
|
/* BEGIN: Use Case */ |
| 2313 |
|
$userGroup = $this->createUserGroupVersion1(); |
| 2314 |
|
|
| 2315 |
|
// Load the existing "Administrator" role |
| 2316 |
|
$role = $roleService->loadRoleByIdentifier('Administrator'); |
| 2317 |
|
|
| 2318 |
|
// Assign the "Administrator" role to the newly created user group |
| 2319 |
|
$roleService->assignRoleToUserGroup($role, $userGroup); |
| 2320 |
|
|
| 2321 |
|
// The assignments array will contain the new role<->group assignment |
| 2322 |
|
$roleAssignments = $roleService->getRoleAssignments($role); |
| 2323 |
|
/* END: Use Case */ |
| 2324 |
|
|
| 2325 |
|
// Administrator + Example Group |
| 2326 |
|
$this->assertEquals(2, count($roleAssignments)); |
| 2327 |
|
} |
| 2328 |
|
|
| 2329 |
|
/** |
| 2330 |
|
* Test for the assignRoleToUserGroup() method. |