| @@ 304-337 (lines=34) @@ | ||
| 301 | * @depends eZ\Publish\API\Repository\Tests\PermissionResolverTest::testHasAccessForCurrentUserYes |
|
| 302 | * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException |
|
| 303 | */ |
|
| 304 | public function testCanUserForAdministratorUser() |
|
| 305 | { |
|
| 306 | $repository = $this->getRepository(); |
|
| 307 | ||
| 308 | $administratorUserId = $this->generateId('user', 14); |
|
| 309 | $homeId = $this->generateId('object', 57); |
|
| 310 | ||
| 311 | /* BEGIN: Use Case */ |
|
| 312 | // $administratorUserId contains the ID of the administrator user |
|
| 313 | // $homeId contains the ID of the "Home" frontpage |
|
| 314 | ||
| 315 | $contentService = $repository->getContentService(); |
|
| 316 | $userService = $repository->getUserService(); |
|
| 317 | $permissionResolver = $repository->getPermissionResolver(); |
|
| 318 | ||
| 319 | // Load administrator user |
|
| 320 | $administratorUser = $userService->loadUser($administratorUserId); |
|
| 321 | ||
| 322 | // Set administrator user as current user reference |
|
| 323 | $permissionResolver->setCurrentUserReference($administratorUser); |
|
| 324 | ||
| 325 | // Load the ContentInfo for "Home" frontpage |
|
| 326 | $contentInfo = $contentService->loadContentInfo($homeId); |
|
| 327 | ||
| 328 | // This call will return true |
|
| 329 | $canUser = $permissionResolver->canUser('content', 'remove', $contentInfo); |
|
| 330 | ||
| 331 | // Performing an action having necessary permissions will succeed |
|
| 332 | $contentService->deleteContent($contentInfo); |
|
| 333 | /* END: Use Case */ |
|
| 334 | ||
| 335 | $this->assertTrue($canUser); |
|
| 336 | $contentService->loadContent($homeId); |
|
| 337 | } |
|
| 338 | ||
| 339 | /** |
|
| 340 | * Test for the canUser() method. |
|
| @@ 315-351 (lines=37) @@ | ||
| 312 | * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
|
| 313 | * @depends eZ\Publish\API\Repository\Tests\ObjectStateServiceTest::testSetContentState |
|
| 314 | */ |
|
| 315 | public function testSetContentStateThrowsUnauthorizedException() |
|
| 316 | { |
|
| 317 | $repository = $this->getRepository(); |
|
| 318 | ||
| 319 | $anonymousUserId = $this->generateId('user', 10); |
|
| 320 | $ezLockObjectStateGroupId = $this->generateId('objectstategroup', 2); |
|
| 321 | $lockedObjectStateId = $this->generateId('objectstate', 2); |
|
| 322 | /* BEGIN: Use Case */ |
|
| 323 | // $anonymousUserId is the ID of the "Anonymous" user in a eZ |
|
| 324 | // Publish demo installation. |
|
| 325 | // Set anonymous user |
|
| 326 | $userService = $repository->getUserService(); |
|
| 327 | $repository->setCurrentUser($userService->loadUser($anonymousUserId)); |
|
| 328 | ||
| 329 | // $anonymousUserId is the content ID of "Anonymous User" |
|
| 330 | // $ezLockObjectStateGroupId contains the ID of the "ez_lock" object |
|
| 331 | // state group |
|
| 332 | // $lockedObjectStateId is the ID of the state "locked" |
|
| 333 | $contentService = $repository->getContentService(); |
|
| 334 | $objectStateService = $repository->getObjectStateService(); |
|
| 335 | ||
| 336 | $contentInfo = $contentService->loadContentInfo($anonymousUserId); |
|
| 337 | ||
| 338 | $ezLockObjectStateGroup = $objectStateService->loadObjectStateGroup( |
|
| 339 | $ezLockObjectStateGroupId |
|
| 340 | ); |
|
| 341 | $lockedObjectState = $objectStateService->loadObjectState($lockedObjectStateId); |
|
| 342 | ||
| 343 | // Throws unauthorized exception, since the anonymous user must not |
|
| 344 | // set object state |
|
| 345 | $objectStateService->setContentState( |
|
| 346 | $contentInfo, |
|
| 347 | $ezLockObjectStateGroup, |
|
| 348 | $lockedObjectState |
|
| 349 | ); |
|
| 350 | /* END: Use Case */ |
|
| 351 | } |
|
| 352 | } |
|
| 353 | ||
| @@ 1529-1565 (lines=37) @@ | ||
| 1526 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo |
|
| 1527 | * @depends testLoadObjectState |
|
| 1528 | */ |
|
| 1529 | public function testSetContentState() |
|
| 1530 | { |
|
| 1531 | $repository = $this->getRepository(); |
|
| 1532 | ||
| 1533 | $anonymousUserId = $this->generateId('user', 10); |
|
| 1534 | $ezLockObjectStateGroupId = $this->generateId('objectstategroup', 2); |
|
| 1535 | $lockedObjectStateId = $this->generateId('objectstate', 2); |
|
| 1536 | /* BEGIN: Use Case */ |
|
| 1537 | // $anonymousUserId is the content ID of "Anonymous User" |
|
| 1538 | // $ezLockObjectStateGroupId contains the ID of the "ez_lock" object |
|
| 1539 | // state group |
|
| 1540 | // $lockedObjectStateId is the ID of the state "locked" |
|
| 1541 | $contentService = $repository->getContentService(); |
|
| 1542 | $objectStateService = $repository->getObjectStateService(); |
|
| 1543 | ||
| 1544 | $contentInfo = $contentService->loadContentInfo($anonymousUserId); |
|
| 1545 | ||
| 1546 | $ezLockObjectStateGroup = $objectStateService->loadObjectStateGroup( |
|
| 1547 | $ezLockObjectStateGroupId |
|
| 1548 | ); |
|
| 1549 | $lockedObjectState = $objectStateService->loadObjectState($lockedObjectStateId); |
|
| 1550 | ||
| 1551 | // Sets the state of $contentInfo from "not_locked" to "locked" |
|
| 1552 | $objectStateService->setContentState( |
|
| 1553 | $contentInfo, |
|
| 1554 | $ezLockObjectStateGroup, |
|
| 1555 | $lockedObjectState |
|
| 1556 | ); |
|
| 1557 | /* END: Use Case */ |
|
| 1558 | ||
| 1559 | $ezLockObjectState = $objectStateService->getContentState( |
|
| 1560 | $contentInfo, |
|
| 1561 | $ezLockObjectStateGroup |
|
| 1562 | ); |
|
| 1563 | ||
| 1564 | $this->assertEquals('locked', $ezLockObjectState->identifier); |
|
| 1565 | } |
|
| 1566 | ||
| 1567 | /** |
|
| 1568 | * Test for the setContentState() method. |
|