|
@@ 2188-2229 (lines=42) @@
|
| 2185 |
|
* @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAssignRoleToUser |
| 2186 |
|
* @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testCreateRoleWithAddPolicy |
| 2187 |
|
*/ |
| 2188 |
|
public function testGetRoleAssignmentsForUserDirect() |
| 2189 |
|
{ |
| 2190 |
|
$repository = $this->getRepository(); |
| 2191 |
|
$roleService = $repository->getRoleService(); |
| 2192 |
|
|
| 2193 |
|
/* BEGIN: Use Case */ |
| 2194 |
|
$user = $this->createUserVersion1(); |
| 2195 |
|
|
| 2196 |
|
// Instantiate a role create and add some policies |
| 2197 |
|
$roleCreate = $roleService->newRoleCreateStruct('Example Role'); |
| 2198 |
|
|
| 2199 |
|
// @todo uncomment when support for multilingual names and descriptions is added EZP-24776 |
| 2200 |
|
// $roleCreate->mainLanguageCode = 'eng-US'; |
| 2201 |
|
|
| 2202 |
|
$roleCreate->addPolicy( |
| 2203 |
|
$roleService->newPolicyCreateStruct('user', 'login') |
| 2204 |
|
); |
| 2205 |
|
$roleCreate->addPolicy( |
| 2206 |
|
$roleService->newPolicyCreateStruct('content', 'read') |
| 2207 |
|
); |
| 2208 |
|
$roleCreate->addPolicy( |
| 2209 |
|
$roleService->newPolicyCreateStruct('content', 'edit') |
| 2210 |
|
); |
| 2211 |
|
|
| 2212 |
|
// Create the new role instance |
| 2213 |
|
$roleDraft = $roleService->createRole($roleCreate); |
| 2214 |
|
$roleService->publishRoleDraft($roleDraft); |
| 2215 |
|
$role = $roleService->loadRole($roleDraft->id); |
| 2216 |
|
|
| 2217 |
|
// Assign role to new user |
| 2218 |
|
$roleService->assignRoleToUser($role, $user); |
| 2219 |
|
|
| 2220 |
|
// Load the currently assigned role |
| 2221 |
|
$roleAssignments = $roleService->getRoleAssignmentsForUser($user); |
| 2222 |
|
/* END: Use Case */ |
| 2223 |
|
|
| 2224 |
|
$this->assertEquals(1, count($roleAssignments)); |
| 2225 |
|
$this->assertInstanceOf( |
| 2226 |
|
'\\eZ\\Publish\\API\\Repository\\Values\\User\\UserRoleAssignment', |
| 2227 |
|
reset($roleAssignments) |
| 2228 |
|
); |
| 2229 |
|
} |
| 2230 |
|
|
| 2231 |
|
/** |
| 2232 |
|
* Test for the getRoleAssignmentsForUser() method. |
|
@@ 2684-2725 (lines=42) @@
|
| 2681 |
|
* @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAssignRoleToUserGroup |
| 2682 |
|
* @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testCreateRoleWithAddPolicy |
| 2683 |
|
*/ |
| 2684 |
|
public function testGetRoleAssignmentsForUserGroup() |
| 2685 |
|
{ |
| 2686 |
|
$repository = $this->getRepository(); |
| 2687 |
|
$roleService = $repository->getRoleService(); |
| 2688 |
|
|
| 2689 |
|
/* BEGIN: Use Case */ |
| 2690 |
|
$userGroup = $this->createUserGroupVersion1(); |
| 2691 |
|
|
| 2692 |
|
// Instantiate a role create and add some policies |
| 2693 |
|
$roleCreate = $roleService->newRoleCreateStruct('Example Role'); |
| 2694 |
|
|
| 2695 |
|
// @todo uncomment when support for multilingual names and descriptions is added EZP-24776 |
| 2696 |
|
// $roleCreate->mainLanguageCode = 'eng-US'; |
| 2697 |
|
|
| 2698 |
|
$roleCreate->addPolicy( |
| 2699 |
|
$roleService->newPolicyCreateStruct('user', 'login') |
| 2700 |
|
); |
| 2701 |
|
$roleCreate->addPolicy( |
| 2702 |
|
$roleService->newPolicyCreateStruct('content', 'read') |
| 2703 |
|
); |
| 2704 |
|
$roleCreate->addPolicy( |
| 2705 |
|
$roleService->newPolicyCreateStruct('content', 'edit') |
| 2706 |
|
); |
| 2707 |
|
|
| 2708 |
|
// Create the new role instance |
| 2709 |
|
$roleDraft = $roleService->createRole($roleCreate); |
| 2710 |
|
$roleService->publishRoleDraft($roleDraft); |
| 2711 |
|
$role = $roleService->loadRole($roleDraft->id); |
| 2712 |
|
|
| 2713 |
|
// Assign role to new user group |
| 2714 |
|
$roleService->assignRoleToUserGroup($role, $userGroup); |
| 2715 |
|
|
| 2716 |
|
// Load the currently assigned role |
| 2717 |
|
$roleAssignments = $roleService->getRoleAssignmentsForUserGroup($userGroup); |
| 2718 |
|
/* END: Use Case */ |
| 2719 |
|
|
| 2720 |
|
$this->assertEquals(1, count($roleAssignments)); |
| 2721 |
|
$this->assertInstanceOf( |
| 2722 |
|
'\\eZ\\Publish\\API\\Repository\\Values\\User\\UserGroupRoleAssignment', |
| 2723 |
|
reset($roleAssignments) |
| 2724 |
|
); |
| 2725 |
|
} |
| 2726 |
|
|
| 2727 |
|
/** |
| 2728 |
|
* Test for the loadPoliciesByUserId() method. |