|
@@ 2012-2042 (lines=31) @@
|
| 2009 |
|
* @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAssignRoleToUser |
| 2010 |
|
* @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testLoadRoleByIdentifier |
| 2011 |
|
*/ |
| 2012 |
|
public function testAssignRoleToUserThrowsInvalidArgumentException() |
| 2013 |
|
{ |
| 2014 |
|
$repository = $this->getRepository(); |
| 2015 |
|
|
| 2016 |
|
/* BEGIN: Use Case */ |
| 2017 |
|
$roleService = $repository->getRoleService(); |
| 2018 |
|
|
| 2019 |
|
// Load the existing "Anonymous" role |
| 2020 |
|
$role = $roleService->loadRoleByIdentifier('Anonymous'); |
| 2021 |
|
|
| 2022 |
|
// Get current user |
| 2023 |
|
$currentUser = $repository->getCurrentUser(); |
| 2024 |
|
|
| 2025 |
|
// Assign the "Anonymous" role to the current user |
| 2026 |
|
try { |
| 2027 |
|
$roleService->assignRoleToUser( |
| 2028 |
|
$role, |
| 2029 |
|
$currentUser |
| 2030 |
|
); |
| 2031 |
|
} catch (Exception $e) { |
| 2032 |
|
$this->fail('Got exception at first valid attempt to assign role'); |
| 2033 |
|
} |
| 2034 |
|
|
| 2035 |
|
// Re-Assign the "Anonymous" role to the current user |
| 2036 |
|
// This call will fail with an InvalidArgumentException, because limitation is already assigned |
| 2037 |
|
$roleService->assignRoleToUser( |
| 2038 |
|
$role, |
| 2039 |
|
$currentUser |
| 2040 |
|
); |
| 2041 |
|
/* END: Use Case */ |
| 2042 |
|
} |
| 2043 |
|
|
| 2044 |
|
/** |
| 2045 |
|
* Test for the assignRoleToUser() method. |
|
@@ 2254-2274 (lines=21) @@
|
| 2251 |
|
* @see \eZ\Publish\API\Repository\RoleService::assignRoleToUserGroup() |
| 2252 |
|
* @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testGetRoleAssignments |
| 2253 |
|
*/ |
| 2254 |
|
public function testAssignRoleToUserGroup() |
| 2255 |
|
{ |
| 2256 |
|
$repository = $this->getRepository(); |
| 2257 |
|
$roleService = $repository->getRoleService(); |
| 2258 |
|
|
| 2259 |
|
/* BEGIN: Use Case */ |
| 2260 |
|
$userGroup = $this->createUserGroupVersion1(); |
| 2261 |
|
|
| 2262 |
|
// Load the existing "Administrator" role |
| 2263 |
|
$role = $roleService->loadRoleByIdentifier('Administrator'); |
| 2264 |
|
|
| 2265 |
|
// Assign the "Administrator" role to the newly created user group |
| 2266 |
|
$roleService->assignRoleToUserGroup($role, $userGroup); |
| 2267 |
|
|
| 2268 |
|
// The assignments array will contain the new role<->group assignment |
| 2269 |
|
$roleAssignments = $roleService->getRoleAssignments($role); |
| 2270 |
|
/* END: Use Case */ |
| 2271 |
|
|
| 2272 |
|
// Administrator + Example Group |
| 2273 |
|
$this->assertEquals(2, count($roleAssignments)); |
| 2274 |
|
} |
| 2275 |
|
|
| 2276 |
|
/** |
| 2277 |
|
* Test for the assignRoleToUserGroup() method. |