|
@@ 414-447 (lines=34) @@
|
| 411 |
|
* |
| 412 |
|
* @see \eZ\Publish\API\Repository\RoleService::createRole() |
| 413 |
|
*/ |
| 414 |
|
public function testCreateRoleThrowsLimitationValidationException() |
| 415 |
|
{ |
| 416 |
|
$this->expectException(\eZ\Publish\API\Repository\Exceptions\LimitationValidationException::class); |
| 417 |
|
|
| 418 |
|
$repository = $this->getRepository(); |
| 419 |
|
|
| 420 |
|
/* BEGIN: Use Case */ |
| 421 |
|
$roleService = $repository->getRoleService(); |
| 422 |
|
|
| 423 |
|
// Create new role create struct |
| 424 |
|
$roleCreate = $roleService->newRoleCreateStruct('Lumberjack'); |
| 425 |
|
|
| 426 |
|
// @todo uncomment when support for multilingual names and descriptions is added EZP-24776 |
| 427 |
|
// $roleCreate->mainLanguageCode = 'eng-US'; |
| 428 |
|
|
| 429 |
|
// Create new subtree limitation |
| 430 |
|
$limitation = new SubtreeLimitation( |
| 431 |
|
[ |
| 432 |
|
'limitationValues' => ['/mountain/forest/tree/42/'], |
| 433 |
|
] |
| 434 |
|
); |
| 435 |
|
|
| 436 |
|
// Create policy create struct and add limitation to it |
| 437 |
|
$policyCreate = $roleService->newPolicyCreateStruct('content', 'remove'); |
| 438 |
|
$policyCreate->addLimitation($limitation); |
| 439 |
|
|
| 440 |
|
// Add policy create struct to role create struct |
| 441 |
|
$roleCreate->addPolicy($policyCreate); |
| 442 |
|
|
| 443 |
|
// This call will fail with an LimitationValidationException, because subtree |
| 444 |
|
// "/mountain/forest/tree/42/" does not exist |
| 445 |
|
$roleService->createRole($roleCreate); |
| 446 |
|
/* END: Use Case */ |
| 447 |
|
} |
| 448 |
|
|
| 449 |
|
/** |
| 450 |
|
* Test for the createRole() method. |
|
@@ 1254-1285 (lines=32) @@
|
| 1251 |
|
* @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testNewPolicyCreateStruct |
| 1252 |
|
* @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testCreateRoleDraft |
| 1253 |
|
*/ |
| 1254 |
|
public function testAddPolicyByRoleDraftThrowsLimitationValidationException() |
| 1255 |
|
{ |
| 1256 |
|
$this->expectException(\eZ\Publish\API\Repository\Exceptions\LimitationValidationException::class); |
| 1257 |
|
|
| 1258 |
|
$repository = $this->getRepository(); |
| 1259 |
|
|
| 1260 |
|
/* BEGIN: Use Case */ |
| 1261 |
|
$roleService = $repository->getRoleService(); |
| 1262 |
|
|
| 1263 |
|
$roleCreate = $roleService->newRoleCreateStruct('Lumberjack'); |
| 1264 |
|
|
| 1265 |
|
// @todo uncomment when support for multilingual names and descriptions is added EZP-24776 |
| 1266 |
|
// $roleCreate->mainLanguageCode = 'eng-US'; |
| 1267 |
|
|
| 1268 |
|
$roleDraft = $roleService->createRole($roleCreate); |
| 1269 |
|
|
| 1270 |
|
// Create new subtree limitation |
| 1271 |
|
$limitation = new SubtreeLimitation( |
| 1272 |
|
[ |
| 1273 |
|
'limitationValues' => ['/mountain/forest/tree/42/'], |
| 1274 |
|
] |
| 1275 |
|
); |
| 1276 |
|
|
| 1277 |
|
// Create policy create struct and add limitation to it |
| 1278 |
|
$policyCreateStruct = $roleService->newPolicyCreateStruct('content', 'remove'); |
| 1279 |
|
$policyCreateStruct->addLimitation($limitation); |
| 1280 |
|
|
| 1281 |
|
// This call will fail with an LimitationValidationException, because subtree |
| 1282 |
|
// "/mountain/forest/tree/42/" does not exist |
| 1283 |
|
$roleService->addPolicyByRoleDraft($roleDraft, $policyCreateStruct); |
| 1284 |
|
/* END: Use Case */ |
| 1285 |
|
} |
| 1286 |
|
|
| 1287 |
|
/** |
| 1288 |
|
* Test for the createRole() method. |
|
@@ 2453-2484 (lines=32) @@
|
| 2450 |
|
* @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testLoadRoleByIdentifier |
| 2451 |
|
* @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAssignRoleToUserGroup |
| 2452 |
|
*/ |
| 2453 |
|
public function testAssignRoleToUserGroupWithRoleLimitationThrowsLimitationValidationException() |
| 2454 |
|
{ |
| 2455 |
|
$this->expectException(\eZ\Publish\API\Repository\Exceptions\LimitationValidationException::class); |
| 2456 |
|
|
| 2457 |
|
$repository = $this->getRepository(); |
| 2458 |
|
|
| 2459 |
|
$mainGroupId = $this->generateId('group', 4); |
| 2460 |
|
/* BEGIN: Use Case */ |
| 2461 |
|
// $mainGroupId is the ID of the main "Users" group |
| 2462 |
|
|
| 2463 |
|
$userService = $repository->getUserService(); |
| 2464 |
|
$roleService = $repository->getRoleService(); |
| 2465 |
|
|
| 2466 |
|
$userGroup = $userService->loadUserGroup($mainGroupId); |
| 2467 |
|
|
| 2468 |
|
// Load the existing "Anonymous" role |
| 2469 |
|
$role = $roleService->loadRoleByIdentifier('Anonymous'); |
| 2470 |
|
|
| 2471 |
|
// Assign the "Anonymous" role to the newly created user group |
| 2472 |
|
// This call will fail with an LimitationValidationException, because subtree "/lorem/ipsum/42/" |
| 2473 |
|
// does not exists |
| 2474 |
|
$roleService->assignRoleToUserGroup( |
| 2475 |
|
$role, |
| 2476 |
|
$userGroup, |
| 2477 |
|
new SubtreeLimitation( |
| 2478 |
|
[ |
| 2479 |
|
'limitationValues' => ['/lorem/ipsum/42/'], |
| 2480 |
|
] |
| 2481 |
|
) |
| 2482 |
|
); |
| 2483 |
|
/* END: Use Case */ |
| 2484 |
|
} |
| 2485 |
|
|
| 2486 |
|
/** |
| 2487 |
|
* Test for the assignRoleToUserGroup() method. |