|
@@ 2157-2198 (lines=42) @@
|
| 2154 |
|
* @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAssignRoleToUser |
| 2155 |
|
* @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testCreateRoleWithAddPolicy |
| 2156 |
|
*/ |
| 2157 |
|
public function testGetRoleAssignmentsForUserDirect() |
| 2158 |
|
{ |
| 2159 |
|
$repository = $this->getRepository(); |
| 2160 |
|
$roleService = $repository->getRoleService(); |
| 2161 |
|
|
| 2162 |
|
/* BEGIN: Use Case */ |
| 2163 |
|
$user = $this->createUserVersion1(); |
| 2164 |
|
|
| 2165 |
|
// Instantiate a role create and add some policies |
| 2166 |
|
$roleCreate = $roleService->newRoleCreateStruct('Example Role'); |
| 2167 |
|
|
| 2168 |
|
// @todo uncomment when support for multilingual names and descriptions is added EZP-24776 |
| 2169 |
|
// $roleCreate->mainLanguageCode = 'eng-US'; |
| 2170 |
|
|
| 2171 |
|
$roleCreate->addPolicy( |
| 2172 |
|
$roleService->newPolicyCreateStruct('user', 'login') |
| 2173 |
|
); |
| 2174 |
|
$roleCreate->addPolicy( |
| 2175 |
|
$roleService->newPolicyCreateStruct('content', 'read') |
| 2176 |
|
); |
| 2177 |
|
$roleCreate->addPolicy( |
| 2178 |
|
$roleService->newPolicyCreateStruct('content', 'edit') |
| 2179 |
|
); |
| 2180 |
|
|
| 2181 |
|
// Create the new role instance |
| 2182 |
|
$roleDraft = $roleService->createRole($roleCreate); |
| 2183 |
|
$roleService->publishRoleDraft($roleDraft); |
| 2184 |
|
$role = $roleService->loadRole($roleDraft->id); |
| 2185 |
|
|
| 2186 |
|
// Assign role to new user |
| 2187 |
|
$roleService->assignRoleToUser($role, $user); |
| 2188 |
|
|
| 2189 |
|
// Load the currently assigned role |
| 2190 |
|
$roleAssignments = $roleService->getRoleAssignmentsForUser($user); |
| 2191 |
|
/* END: Use Case */ |
| 2192 |
|
|
| 2193 |
|
$this->assertEquals(1, count($roleAssignments)); |
| 2194 |
|
$this->assertInstanceOf( |
| 2195 |
|
'\\eZ\\Publish\\API\\Repository\\Values\\User\\UserRoleAssignment', |
| 2196 |
|
reset($roleAssignments) |
| 2197 |
|
); |
| 2198 |
|
} |
| 2199 |
|
|
| 2200 |
|
/** |
| 2201 |
|
* Test for the getRoleAssignmentsForUser() method. |
|
@@ 2653-2694 (lines=42) @@
|
| 2650 |
|
* @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAssignRoleToUserGroup |
| 2651 |
|
* @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testCreateRoleWithAddPolicy |
| 2652 |
|
*/ |
| 2653 |
|
public function testGetRoleAssignmentsForUserGroup() |
| 2654 |
|
{ |
| 2655 |
|
$repository = $this->getRepository(); |
| 2656 |
|
$roleService = $repository->getRoleService(); |
| 2657 |
|
|
| 2658 |
|
/* BEGIN: Use Case */ |
| 2659 |
|
$userGroup = $this->createUserGroupVersion1(); |
| 2660 |
|
|
| 2661 |
|
// Instantiate a role create and add some policies |
| 2662 |
|
$roleCreate = $roleService->newRoleCreateStruct('Example Role'); |
| 2663 |
|
|
| 2664 |
|
// @todo uncomment when support for multilingual names and descriptions is added EZP-24776 |
| 2665 |
|
// $roleCreate->mainLanguageCode = 'eng-US'; |
| 2666 |
|
|
| 2667 |
|
$roleCreate->addPolicy( |
| 2668 |
|
$roleService->newPolicyCreateStruct('user', 'login') |
| 2669 |
|
); |
| 2670 |
|
$roleCreate->addPolicy( |
| 2671 |
|
$roleService->newPolicyCreateStruct('content', 'read') |
| 2672 |
|
); |
| 2673 |
|
$roleCreate->addPolicy( |
| 2674 |
|
$roleService->newPolicyCreateStruct('content', 'edit') |
| 2675 |
|
); |
| 2676 |
|
|
| 2677 |
|
// Create the new role instance |
| 2678 |
|
$roleDraft = $roleService->createRole($roleCreate); |
| 2679 |
|
$roleService->publishRoleDraft($roleDraft); |
| 2680 |
|
$role = $roleService->loadRole($roleDraft->id); |
| 2681 |
|
|
| 2682 |
|
// Assign role to new user group |
| 2683 |
|
$roleService->assignRoleToUserGroup($role, $userGroup); |
| 2684 |
|
|
| 2685 |
|
// Load the currently assigned role |
| 2686 |
|
$roleAssignments = $roleService->getRoleAssignmentsForUserGroup($userGroup); |
| 2687 |
|
/* END: Use Case */ |
| 2688 |
|
|
| 2689 |
|
$this->assertEquals(1, count($roleAssignments)); |
| 2690 |
|
$this->assertInstanceOf( |
| 2691 |
|
'\\eZ\\Publish\\API\\Repository\\Values\\User\\UserGroupRoleAssignment', |
| 2692 |
|
reset($roleAssignments) |
| 2693 |
|
); |
| 2694 |
|
} |
| 2695 |
|
|
| 2696 |
|
/** |
| 2697 |
|
* Test for the loadPoliciesByUserId() method. |