|
@@ 395-428 (lines=34) @@
|
| 392 |
|
* |
| 393 |
|
* @see \eZ\Publish\API\Repository\RoleService::createRole() |
| 394 |
|
*/ |
| 395 |
|
public function testCreateRoleThrowsLimitationValidationException() |
| 396 |
|
{ |
| 397 |
|
$this->expectException(\eZ\Publish\API\Repository\Exceptions\LimitationValidationException::class); |
| 398 |
|
|
| 399 |
|
$repository = $this->getRepository(); |
| 400 |
|
|
| 401 |
|
/* BEGIN: Use Case */ |
| 402 |
|
$roleService = $repository->getRoleService(); |
| 403 |
|
|
| 404 |
|
// Create new role create struct |
| 405 |
|
$roleCreate = $roleService->newRoleCreateStruct('Lumberjack'); |
| 406 |
|
|
| 407 |
|
// @todo uncomment when support for multilingual names and descriptions is added EZP-24776 |
| 408 |
|
// $roleCreate->mainLanguageCode = 'eng-US'; |
| 409 |
|
|
| 410 |
|
// Create new subtree limitation |
| 411 |
|
$limitation = new SubtreeLimitation( |
| 412 |
|
[ |
| 413 |
|
'limitationValues' => ['/mountain/forest/tree/42/'], |
| 414 |
|
] |
| 415 |
|
); |
| 416 |
|
|
| 417 |
|
// Create policy create struct and add limitation to it |
| 418 |
|
$policyCreate = $roleService->newPolicyCreateStruct('content', 'remove'); |
| 419 |
|
$policyCreate->addLimitation($limitation); |
| 420 |
|
|
| 421 |
|
// Add policy create struct to role create struct |
| 422 |
|
$roleCreate->addPolicy($policyCreate); |
| 423 |
|
|
| 424 |
|
// This call will fail with an LimitationValidationException, because subtree |
| 425 |
|
// "/mountain/forest/tree/42/" does not exist |
| 426 |
|
$roleService->createRole($roleCreate); |
| 427 |
|
/* END: Use Case */ |
| 428 |
|
} |
| 429 |
|
|
| 430 |
|
/** |
| 431 |
|
* Test for the createRole() method. |
|
@@ 1066-1097 (lines=32) @@
|
| 1063 |
|
* @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testNewPolicyCreateStruct |
| 1064 |
|
* @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testCreateRoleDraft |
| 1065 |
|
*/ |
| 1066 |
|
public function testAddPolicyByRoleDraftThrowsLimitationValidationException() |
| 1067 |
|
{ |
| 1068 |
|
$this->expectException(\eZ\Publish\API\Repository\Exceptions\LimitationValidationException::class); |
| 1069 |
|
|
| 1070 |
|
$repository = $this->getRepository(); |
| 1071 |
|
|
| 1072 |
|
/* BEGIN: Use Case */ |
| 1073 |
|
$roleService = $repository->getRoleService(); |
| 1074 |
|
|
| 1075 |
|
$roleCreate = $roleService->newRoleCreateStruct('Lumberjack'); |
| 1076 |
|
|
| 1077 |
|
// @todo uncomment when support for multilingual names and descriptions is added EZP-24776 |
| 1078 |
|
// $roleCreate->mainLanguageCode = 'eng-US'; |
| 1079 |
|
|
| 1080 |
|
$roleDraft = $roleService->createRole($roleCreate); |
| 1081 |
|
|
| 1082 |
|
// Create new subtree limitation |
| 1083 |
|
$limitation = new SubtreeLimitation( |
| 1084 |
|
[ |
| 1085 |
|
'limitationValues' => ['/mountain/forest/tree/42/'], |
| 1086 |
|
] |
| 1087 |
|
); |
| 1088 |
|
|
| 1089 |
|
// Create policy create struct and add limitation to it |
| 1090 |
|
$policyCreateStruct = $roleService->newPolicyCreateStruct('content', 'remove'); |
| 1091 |
|
$policyCreateStruct->addLimitation($limitation); |
| 1092 |
|
|
| 1093 |
|
// This call will fail with an LimitationValidationException, because subtree |
| 1094 |
|
// "/mountain/forest/tree/42/" does not exist |
| 1095 |
|
$roleService->addPolicyByRoleDraft($roleDraft, $policyCreateStruct); |
| 1096 |
|
/* END: Use Case */ |
| 1097 |
|
} |
| 1098 |
|
|
| 1099 |
|
/** |
| 1100 |
|
* Test for the createRole() method. |
|
@@ 2265-2296 (lines=32) @@
|
| 2262 |
|
* @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testLoadRoleByIdentifier |
| 2263 |
|
* @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAssignRoleToUserGroup |
| 2264 |
|
*/ |
| 2265 |
|
public function testAssignRoleToUserGroupWithRoleLimitationThrowsLimitationValidationException() |
| 2266 |
|
{ |
| 2267 |
|
$this->expectException(\eZ\Publish\API\Repository\Exceptions\LimitationValidationException::class); |
| 2268 |
|
|
| 2269 |
|
$repository = $this->getRepository(); |
| 2270 |
|
|
| 2271 |
|
$mainGroupId = $this->generateId('group', 4); |
| 2272 |
|
/* BEGIN: Use Case */ |
| 2273 |
|
// $mainGroupId is the ID of the main "Users" group |
| 2274 |
|
|
| 2275 |
|
$userService = $repository->getUserService(); |
| 2276 |
|
$roleService = $repository->getRoleService(); |
| 2277 |
|
|
| 2278 |
|
$userGroup = $userService->loadUserGroup($mainGroupId); |
| 2279 |
|
|
| 2280 |
|
// Load the existing "Anonymous" role |
| 2281 |
|
$role = $roleService->loadRoleByIdentifier('Anonymous'); |
| 2282 |
|
|
| 2283 |
|
// Assign the "Anonymous" role to the newly created user group |
| 2284 |
|
// This call will fail with an LimitationValidationException, because subtree "/lorem/ipsum/42/" |
| 2285 |
|
// does not exists |
| 2286 |
|
$roleService->assignRoleToUserGroup( |
| 2287 |
|
$role, |
| 2288 |
|
$userGroup, |
| 2289 |
|
new SubtreeLimitation( |
| 2290 |
|
[ |
| 2291 |
|
'limitationValues' => ['/lorem/ipsum/42/'], |
| 2292 |
|
] |
| 2293 |
|
) |
| 2294 |
|
); |
| 2295 |
|
/* END: Use Case */ |
| 2296 |
|
} |
| 2297 |
|
|
| 2298 |
|
/** |
| 2299 |
|
* Test for the assignRoleToUserGroup() method. |