|
@@ 250-280 (lines=31) @@
|
| 247 |
|
* @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testUpdatePolicy |
| 248 |
|
* @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testCreateUser |
| 249 |
|
*/ |
| 250 |
|
public function testUpdatePolicyThrowsUnauthorizedException() |
| 251 |
|
{ |
| 252 |
|
$repository = $this->getRepository(); |
| 253 |
|
$roleService = $repository->getRoleService(); |
| 254 |
|
|
| 255 |
|
/* BEGIN: Use Case */ |
| 256 |
|
$user = $this->createUserVersion1(); |
| 257 |
|
|
| 258 |
|
$role = $this->createRole(); |
| 259 |
|
|
| 260 |
|
// Get first role policy |
| 261 |
|
$policies = $role->getPolicies(); |
| 262 |
|
$policy = reset($policies); |
| 263 |
|
|
| 264 |
|
// Set "Editor" user as current user. |
| 265 |
|
$repository->setCurrentUser($user); |
| 266 |
|
|
| 267 |
|
// Get a policy update struct and add a limitation |
| 268 |
|
$policyUpdate = $roleService->newPolicyUpdateStruct(); |
| 269 |
|
$policyUpdate->addLimitation( |
| 270 |
|
new SubtreeLimitation( |
| 271 |
|
[ |
| 272 |
|
'limitationValues' => ['/1/'], |
| 273 |
|
] |
| 274 |
|
) |
| 275 |
|
); |
| 276 |
|
|
| 277 |
|
// This call will fail with an "UnauthorizedException" |
| 278 |
|
$roleService->updatePolicy($policy, $policyUpdate); |
| 279 |
|
/* END: Use Case */ |
| 280 |
|
} |
| 281 |
|
|
| 282 |
|
/** |
| 283 |
|
* Test for the removePolicy() method. |
|
@@ 392-421 (lines=30) @@
|
| 389 |
|
* @depends eZ\Publish\API\Repository\Tests\RoleServiceTest::testAssignRoleToUserGroup |
| 390 |
|
* @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testCreateUser |
| 391 |
|
*/ |
| 392 |
|
public function testAssignRoleToUserGroupThrowsUnauthorizedExceptionWithRoleLimitationParameter() |
| 393 |
|
{ |
| 394 |
|
$repository = $this->getRepository(); |
| 395 |
|
$userService = $repository->getUserService(); |
| 396 |
|
$roleService = $repository->getRoleService(); |
| 397 |
|
|
| 398 |
|
$editorsGroupId = $this->generateId('group', 13); |
| 399 |
|
|
| 400 |
|
/* BEGIN: Use Case */ |
| 401 |
|
$user = $this->createUserVersion1(); |
| 402 |
|
|
| 403 |
|
$role = $this->createRole(); |
| 404 |
|
|
| 405 |
|
// Load the "Editors" user group |
| 406 |
|
$userGroup = $userService->loadUserGroup($editorsGroupId); |
| 407 |
|
|
| 408 |
|
// Set "Editor" user as current user. |
| 409 |
|
$repository->setCurrentUser($user); |
| 410 |
|
|
| 411 |
|
// Create a subtree role limitation |
| 412 |
|
$limitation = new SubtreeLimitation( |
| 413 |
|
[ |
| 414 |
|
'limitationValues' => ['/1/2/'], |
| 415 |
|
] |
| 416 |
|
); |
| 417 |
|
|
| 418 |
|
// This call will fail with an "UnauthorizedException" |
| 419 |
|
$roleService->assignRoleToUserGroup($role, $userGroup, $limitation); |
| 420 |
|
/* END: Use Case */ |
| 421 |
|
} |
| 422 |
|
|
| 423 |
|
/** |
| 424 |
|
* Test for the unassignRoleFromUserGroup() method. |