|
@@ 2255-2296 (lines=42) @@
|
| 2252 |
|
* @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAssignRoleToUser |
| 2253 |
|
* @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testCreateRoleWithAddPolicy |
| 2254 |
|
*/ |
| 2255 |
|
public function testGetRoleAssignmentsForUserDirect() |
| 2256 |
|
{ |
| 2257 |
|
$repository = $this->getRepository(); |
| 2258 |
|
$roleService = $repository->getRoleService(); |
| 2259 |
|
|
| 2260 |
|
/* BEGIN: Use Case */ |
| 2261 |
|
$user = $this->createUserVersion1(); |
| 2262 |
|
|
| 2263 |
|
// Instantiate a role create and add some policies |
| 2264 |
|
$roleCreate = $roleService->newRoleCreateStruct('Example Role'); |
| 2265 |
|
|
| 2266 |
|
// @todo uncomment when support for multilingual names and descriptions is added EZP-24776 |
| 2267 |
|
// $roleCreate->mainLanguageCode = 'eng-US'; |
| 2268 |
|
|
| 2269 |
|
$roleCreate->addPolicy( |
| 2270 |
|
$roleService->newPolicyCreateStruct('user', 'login') |
| 2271 |
|
); |
| 2272 |
|
$roleCreate->addPolicy( |
| 2273 |
|
$roleService->newPolicyCreateStruct('content', 'read') |
| 2274 |
|
); |
| 2275 |
|
$roleCreate->addPolicy( |
| 2276 |
|
$roleService->newPolicyCreateStruct('content', 'edit') |
| 2277 |
|
); |
| 2278 |
|
|
| 2279 |
|
// Create the new role instance |
| 2280 |
|
$roleDraft = $roleService->createRole($roleCreate); |
| 2281 |
|
$roleService->publishRoleDraft($roleDraft); |
| 2282 |
|
$role = $roleService->loadRole($roleDraft->id); |
| 2283 |
|
|
| 2284 |
|
// Assign role to new user |
| 2285 |
|
$roleService->assignRoleToUser($role, $user); |
| 2286 |
|
|
| 2287 |
|
// Load the currently assigned role |
| 2288 |
|
$roleAssignments = $roleService->getRoleAssignmentsForUser($user); |
| 2289 |
|
/* END: Use Case */ |
| 2290 |
|
|
| 2291 |
|
$this->assertEquals(1, count($roleAssignments)); |
| 2292 |
|
$this->assertInstanceOf( |
| 2293 |
|
'\\eZ\\Publish\\API\\Repository\\Values\\User\\UserRoleAssignment', |
| 2294 |
|
reset($roleAssignments) |
| 2295 |
|
); |
| 2296 |
|
} |
| 2297 |
|
|
| 2298 |
|
/** |
| 2299 |
|
* Test for the getRoleAssignmentsForUser() method. |
|
@@ 2781-2822 (lines=42) @@
|
| 2778 |
|
* @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAssignRoleToUserGroup |
| 2779 |
|
* @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testCreateRoleWithAddPolicy |
| 2780 |
|
*/ |
| 2781 |
|
public function testGetRoleAssignmentsForUserGroup() |
| 2782 |
|
{ |
| 2783 |
|
$repository = $this->getRepository(); |
| 2784 |
|
$roleService = $repository->getRoleService(); |
| 2785 |
|
|
| 2786 |
|
/* BEGIN: Use Case */ |
| 2787 |
|
$userGroup = $this->createUserGroupVersion1(); |
| 2788 |
|
|
| 2789 |
|
// Instantiate a role create and add some policies |
| 2790 |
|
$roleCreate = $roleService->newRoleCreateStruct('Example Role'); |
| 2791 |
|
|
| 2792 |
|
// @todo uncomment when support for multilingual names and descriptions is added EZP-24776 |
| 2793 |
|
// $roleCreate->mainLanguageCode = 'eng-US'; |
| 2794 |
|
|
| 2795 |
|
$roleCreate->addPolicy( |
| 2796 |
|
$roleService->newPolicyCreateStruct('user', 'login') |
| 2797 |
|
); |
| 2798 |
|
$roleCreate->addPolicy( |
| 2799 |
|
$roleService->newPolicyCreateStruct('content', 'read') |
| 2800 |
|
); |
| 2801 |
|
$roleCreate->addPolicy( |
| 2802 |
|
$roleService->newPolicyCreateStruct('content', 'edit') |
| 2803 |
|
); |
| 2804 |
|
|
| 2805 |
|
// Create the new role instance |
| 2806 |
|
$roleDraft = $roleService->createRole($roleCreate); |
| 2807 |
|
$roleService->publishRoleDraft($roleDraft); |
| 2808 |
|
$role = $roleService->loadRole($roleDraft->id); |
| 2809 |
|
|
| 2810 |
|
// Assign role to new user group |
| 2811 |
|
$roleService->assignRoleToUserGroup($role, $userGroup); |
| 2812 |
|
|
| 2813 |
|
// Load the currently assigned role |
| 2814 |
|
$roleAssignments = $roleService->getRoleAssignmentsForUserGroup($userGroup); |
| 2815 |
|
/* END: Use Case */ |
| 2816 |
|
|
| 2817 |
|
$this->assertEquals(1, count($roleAssignments)); |
| 2818 |
|
$this->assertInstanceOf( |
| 2819 |
|
'\\eZ\\Publish\\API\\Repository\\Values\\User\\UserGroupRoleAssignment', |
| 2820 |
|
reset($roleAssignments) |
| 2821 |
|
); |
| 2822 |
|
} |
| 2823 |
|
|
| 2824 |
|
/** |
| 2825 |
|
* Test for the loadPoliciesByUserId() method. |