| @@ 1006-1059 (lines=54) @@ | ||
| 1003 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testLoadRoleByIdentifier |
|
| 1004 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testNewPolicyCreateStruct |
|
| 1005 | */ |
|
| 1006 | public function testAddPolicy() |
|
| 1007 | { |
|
| 1008 | $repository = $this->getRepository(); |
|
| 1009 | ||
| 1010 | /* BEGIN: Use Case */ |
|
| 1011 | $roleService = $repository->getRoleService(); |
|
| 1012 | ||
| 1013 | $roleCreate = $roleService->newRoleCreateStruct('newRole'); |
|
| 1014 | ||
| 1015 | // @todo uncomment when support for multilingual names and descriptions is added EZP-24776 |
|
| 1016 | // $roleCreate->mainLanguageCode = 'eng-US'; |
|
| 1017 | ||
| 1018 | $roleDraft = $roleService->createRole($roleCreate); |
|
| 1019 | $roleService->publishRoleDraft($roleDraft); |
|
| 1020 | $role = $roleService->loadRole($roleDraft->id); |
|
| 1021 | ||
| 1022 | $role = $roleService->addPolicy( |
|
| 1023 | $role, |
|
| 1024 | $roleService->newPolicyCreateStruct('content', 'delete') |
|
| 1025 | ); |
|
| 1026 | $role = $roleService->addPolicy( |
|
| 1027 | $role, |
|
| 1028 | $roleService->newPolicyCreateStruct('content', 'create') |
|
| 1029 | ); |
|
| 1030 | /* END: Use Case */ |
|
| 1031 | ||
| 1032 | $actual = []; |
|
| 1033 | foreach ($role->getPolicies() as $policy) { |
|
| 1034 | $actual[] = [ |
|
| 1035 | 'module' => $policy->module, |
|
| 1036 | 'function' => $policy->function, |
|
| 1037 | ]; |
|
| 1038 | } |
|
| 1039 | usort( |
|
| 1040 | $actual, |
|
| 1041 | function ($p1, $p2) { |
|
| 1042 | return strcasecmp($p1['function'], $p2['function']); |
|
| 1043 | } |
|
| 1044 | ); |
|
| 1045 | ||
| 1046 | $this->assertEquals( |
|
| 1047 | [ |
|
| 1048 | [ |
|
| 1049 | 'module' => 'content', |
|
| 1050 | 'function' => 'create', |
|
| 1051 | ], |
|
| 1052 | [ |
|
| 1053 | 'module' => 'content', |
|
| 1054 | 'function' => 'delete', |
|
| 1055 | ], |
|
| 1056 | ], |
|
| 1057 | $actual |
|
| 1058 | ); |
|
| 1059 | } |
|
| 1060 | ||
| 1061 | /** |
|
| 1062 | * Test for the addPolicyByRoleDraft() method. |
|
| @@ 2966-3019 (lines=54) @@ | ||
| 2963 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testCreateRoleDraft |
|
| 2964 | * @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAddPolicyByRoleDraft |
|
| 2965 | */ |
|
| 2966 | public function testPublishRoleDraftAddPolicies() |
|
| 2967 | { |
|
| 2968 | $repository = $this->getRepository(); |
|
| 2969 | ||
| 2970 | /* BEGIN: Use Case */ |
|
| 2971 | $roleService = $repository->getRoleService(); |
|
| 2972 | $roleCreate = $roleService->newRoleCreateStruct('newRole'); |
|
| 2973 | ||
| 2974 | // @todo uncomment when support for multilingual names and descriptions is added EZP-24776 |
|
| 2975 | // $roleCreate->mainLanguageCode = 'eng-US'; |
|
| 2976 | ||
| 2977 | $roleDraft = $roleService->createRole($roleCreate); |
|
| 2978 | ||
| 2979 | $roleDraft = $roleService->addPolicyByRoleDraft( |
|
| 2980 | $roleDraft, |
|
| 2981 | $roleService->newPolicyCreateStruct('content', 'delete') |
|
| 2982 | ); |
|
| 2983 | $roleDraft = $roleService->addPolicyByRoleDraft( |
|
| 2984 | $roleDraft, |
|
| 2985 | $roleService->newPolicyCreateStruct('content', 'create') |
|
| 2986 | ); |
|
| 2987 | ||
| 2988 | $roleService->publishRoleDraft($roleDraft); |
|
| 2989 | $role = $roleService->loadRoleByIdentifier($roleCreate->identifier); |
|
| 2990 | /* END: Use Case */ |
|
| 2991 | ||
| 2992 | $actual = []; |
|
| 2993 | foreach ($role->getPolicies() as $policy) { |
|
| 2994 | $actual[] = [ |
|
| 2995 | 'module' => $policy->module, |
|
| 2996 | 'function' => $policy->function, |
|
| 2997 | ]; |
|
| 2998 | } |
|
| 2999 | usort( |
|
| 3000 | $actual, |
|
| 3001 | function ($p1, $p2) { |
|
| 3002 | return strcasecmp($p1['function'], $p2['function']); |
|
| 3003 | } |
|
| 3004 | ); |
|
| 3005 | ||
| 3006 | $this->assertEquals( |
|
| 3007 | [ |
|
| 3008 | [ |
|
| 3009 | 'module' => 'content', |
|
| 3010 | 'function' => 'create', |
|
| 3011 | ], |
|
| 3012 | [ |
|
| 3013 | 'module' => 'content', |
|
| 3014 | 'function' => 'delete', |
|
| 3015 | ], |
|
| 3016 | ], |
|
| 3017 | $actual |
|
| 3018 | ); |
|
| 3019 | } |
|
| 3020 | ||
| 3021 | /** |
|
| 3022 | * Create a user group fixture in a variable named <b>$userGroup</b>,. |
|