|
@@ 2251-2292 (lines=42) @@
|
| 2248 |
|
* @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAssignRoleToUser |
| 2249 |
|
* @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testCreateRoleWithAddPolicy |
| 2250 |
|
*/ |
| 2251 |
|
public function testGetRoleAssignmentsForUserDirect() |
| 2252 |
|
{ |
| 2253 |
|
$repository = $this->getRepository(); |
| 2254 |
|
$roleService = $repository->getRoleService(); |
| 2255 |
|
|
| 2256 |
|
/* BEGIN: Use Case */ |
| 2257 |
|
$user = $this->createUserVersion1(); |
| 2258 |
|
|
| 2259 |
|
// Instantiate a role create and add some policies |
| 2260 |
|
$roleCreate = $roleService->newRoleCreateStruct('Example Role'); |
| 2261 |
|
|
| 2262 |
|
// @todo uncomment when support for multilingual names and descriptions is added EZP-24776 |
| 2263 |
|
// $roleCreate->mainLanguageCode = 'eng-US'; |
| 2264 |
|
|
| 2265 |
|
$roleCreate->addPolicy( |
| 2266 |
|
$roleService->newPolicyCreateStruct('user', 'login') |
| 2267 |
|
); |
| 2268 |
|
$roleCreate->addPolicy( |
| 2269 |
|
$roleService->newPolicyCreateStruct('content', 'read') |
| 2270 |
|
); |
| 2271 |
|
$roleCreate->addPolicy( |
| 2272 |
|
$roleService->newPolicyCreateStruct('content', 'edit') |
| 2273 |
|
); |
| 2274 |
|
|
| 2275 |
|
// Create the new role instance |
| 2276 |
|
$roleDraft = $roleService->createRole($roleCreate); |
| 2277 |
|
$roleService->publishRoleDraft($roleDraft); |
| 2278 |
|
$role = $roleService->loadRole($roleDraft->id); |
| 2279 |
|
|
| 2280 |
|
// Assign role to new user |
| 2281 |
|
$roleService->assignRoleToUser($role, $user); |
| 2282 |
|
|
| 2283 |
|
// Load the currently assigned role |
| 2284 |
|
$roleAssignments = $roleService->getRoleAssignmentsForUser($user); |
| 2285 |
|
/* END: Use Case */ |
| 2286 |
|
|
| 2287 |
|
$this->assertEquals(1, count($roleAssignments)); |
| 2288 |
|
$this->assertInstanceOf( |
| 2289 |
|
'\\eZ\\Publish\\API\\Repository\\Values\\User\\UserRoleAssignment', |
| 2290 |
|
reset($roleAssignments) |
| 2291 |
|
); |
| 2292 |
|
} |
| 2293 |
|
|
| 2294 |
|
/** |
| 2295 |
|
* Test for the getRoleAssignmentsForUser() method. |
|
@@ 2747-2788 (lines=42) @@
|
| 2744 |
|
* @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAssignRoleToUserGroup |
| 2745 |
|
* @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testCreateRoleWithAddPolicy |
| 2746 |
|
*/ |
| 2747 |
|
public function testGetRoleAssignmentsForUserGroup() |
| 2748 |
|
{ |
| 2749 |
|
$repository = $this->getRepository(); |
| 2750 |
|
$roleService = $repository->getRoleService(); |
| 2751 |
|
|
| 2752 |
|
/* BEGIN: Use Case */ |
| 2753 |
|
$userGroup = $this->createUserGroupVersion1(); |
| 2754 |
|
|
| 2755 |
|
// Instantiate a role create and add some policies |
| 2756 |
|
$roleCreate = $roleService->newRoleCreateStruct('Example Role'); |
| 2757 |
|
|
| 2758 |
|
// @todo uncomment when support for multilingual names and descriptions is added EZP-24776 |
| 2759 |
|
// $roleCreate->mainLanguageCode = 'eng-US'; |
| 2760 |
|
|
| 2761 |
|
$roleCreate->addPolicy( |
| 2762 |
|
$roleService->newPolicyCreateStruct('user', 'login') |
| 2763 |
|
); |
| 2764 |
|
$roleCreate->addPolicy( |
| 2765 |
|
$roleService->newPolicyCreateStruct('content', 'read') |
| 2766 |
|
); |
| 2767 |
|
$roleCreate->addPolicy( |
| 2768 |
|
$roleService->newPolicyCreateStruct('content', 'edit') |
| 2769 |
|
); |
| 2770 |
|
|
| 2771 |
|
// Create the new role instance |
| 2772 |
|
$roleDraft = $roleService->createRole($roleCreate); |
| 2773 |
|
$roleService->publishRoleDraft($roleDraft); |
| 2774 |
|
$role = $roleService->loadRole($roleDraft->id); |
| 2775 |
|
|
| 2776 |
|
// Assign role to new user group |
| 2777 |
|
$roleService->assignRoleToUserGroup($role, $userGroup); |
| 2778 |
|
|
| 2779 |
|
// Load the currently assigned role |
| 2780 |
|
$roleAssignments = $roleService->getRoleAssignmentsForUserGroup($userGroup); |
| 2781 |
|
/* END: Use Case */ |
| 2782 |
|
|
| 2783 |
|
$this->assertEquals(1, count($roleAssignments)); |
| 2784 |
|
$this->assertInstanceOf( |
| 2785 |
|
'\\eZ\\Publish\\API\\Repository\\Values\\User\\UserGroupRoleAssignment', |
| 2786 |
|
reset($roleAssignments) |
| 2787 |
|
); |
| 2788 |
|
} |
| 2789 |
|
|
| 2790 |
|
/** |
| 2791 |
|
* Test for the loadPoliciesByUserId() method. |