| @@ 631-655 (lines=25) @@ | ||
| 628 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetContentService |
|
| 629 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testHasAccessLimited |
|
| 630 | */ |
|
| 631 | public function testCanUserWithLimitationYes() |
|
| 632 | { |
|
| 633 | $repository = $this->getRepository(); |
|
| 634 | ||
| 635 | $imagesFolderId = $this->generateId('object', 49); |
|
| 636 | ||
| 637 | /* BEGIN: Use Case */ |
|
| 638 | // $imagesFolderId contains the ID of the "Images" folder |
|
| 639 | ||
| 640 | $user = $this->createUserVersion1(); |
|
| 641 | ||
| 642 | // Set created user as current user |
|
| 643 | $repository->setCurrentUser($user); |
|
| 644 | ||
| 645 | $contentService = $repository->getContentService(); |
|
| 646 | ||
| 647 | // Performing an action having necessary permissions will succeed |
|
| 648 | $imagesFolder = $contentService->loadContent($imagesFolderId); |
|
| 649 | ||
| 650 | // This call will return true |
|
| 651 | $canUser = $repository->canUser('content', 'read', $imagesFolder); |
|
| 652 | /* END: Use Case */ |
|
| 653 | ||
| 654 | $this->assertTrue($canUser); |
|
| 655 | } |
|
| 656 | ||
| 657 | /** |
|
| 658 | * Test for the canUser() method. |
|
| @@ 708-732 (lines=25) @@ | ||
| 705 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testHasAccessLimited |
|
| 706 | * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
|
| 707 | */ |
|
| 708 | public function testCanUserThrowsInvalidArgumentException() |
|
| 709 | { |
|
| 710 | $repository = $this->getRepository(); |
|
| 711 | ||
| 712 | $userGroupContentTypeId = $this->generateId('type', 3); |
|
| 713 | ||
| 714 | /* BEGIN: Use Case */ |
|
| 715 | // $userGroupContentTypeId contains the ID of the "UserGroup" ContentType |
|
| 716 | ||
| 717 | $user = $this->createUserVersion1(); |
|
| 718 | ||
| 719 | // Set created user as current user |
|
| 720 | $repository->setCurrentUser($user); |
|
| 721 | ||
| 722 | $contentTypeService = $repository->getContentTypeService(); |
|
| 723 | ||
| 724 | // Load the "UserGroup" ContentType |
|
| 725 | $userGroupContentType = $contentTypeService->loadContentType($userGroupContentTypeId); |
|
| 726 | ||
| 727 | // This call will throw "InvalidArgumentException" because $userGroupContentType |
|
| 728 | // is an instance of \eZ\Publish\API\Repository\Values\ContentType\ContentType, |
|
| 729 | // which can not be checked for user access |
|
| 730 | $canUser = $repository->canUser('content', 'create', $userGroupContentType); |
|
| 731 | /* END: Use Case */ |
|
| 732 | } |
|
| 733 | ||
| 734 | /** |
|
| 735 | * Test for the canUser() method. |
|
| @@ 978-1006 (lines=29) @@ | ||
| 975 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testHasAccessLimited |
|
| 976 | * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
|
| 977 | */ |
|
| 978 | public function testCanUserWithTargetThrowsInvalidArgumentException() |
|
| 979 | { |
|
| 980 | $repository = $this->getRepository(); |
|
| 981 | ||
| 982 | $homeId = $this->generateId('object', 57); |
|
| 983 | ||
| 984 | /* BEGIN: Use Case */ |
|
| 985 | // $homeId contains the ID of the "Home" frontpage |
|
| 986 | ||
| 987 | $user = $this->createUserVersion1(); |
|
| 988 | ||
| 989 | // Set created user as current user |
|
| 990 | $repository->setCurrentUser($user); |
|
| 991 | ||
| 992 | $contentService = $repository->getContentService(); |
|
| 993 | ||
| 994 | // Load the ContentInfo for "Home" frontpage |
|
| 995 | $contentInfo = $contentService->loadContentInfo($homeId); |
|
| 996 | ||
| 997 | // This call will throw "InvalidArgumentException" because $targets argument must be an |
|
| 998 | // instance of \eZ\Publish\API\Repository\Values\ValueObject class or an array of the same |
|
| 999 | $canUser = $repository->canUser( |
|
| 1000 | 'content', |
|
| 1001 | 'remove', |
|
| 1002 | $contentInfo, |
|
| 1003 | new \stdClass() |
|
| 1004 | ); |
|
| 1005 | /* END: Use Case */ |
|
| 1006 | } |
|
| 1007 | ||
| 1008 | /** |
|
| 1009 | * Test for the canUser() method. |
|
| @@ 133-158 (lines=26) @@ | ||
| 130 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetUserService |
|
| 131 | * @depends eZ\Publish\API\Repository\Tests\PermissionResolverTest::testHasAccessWithAnonymousUserNo |
|
| 132 | */ |
|
| 133 | public function testHasAccessForCurrentUserNo() |
|
| 134 | { |
|
| 135 | $repository = $this->getRepository(); |
|
| 136 | ||
| 137 | $anonymousUserId = $this->generateId('user', 10); |
|
| 138 | ||
| 139 | /* BEGIN: Use Case */ |
|
| 140 | // $anonymousUserId is the ID of the "Anonymous" user in a eZ |
|
| 141 | // Publish demo installation. |
|
| 142 | ||
| 143 | $userService = $repository->getUserService(); |
|
| 144 | $permissionResolver = $repository->getPermissionResolver(); |
|
| 145 | ||
| 146 | // Load anonymous user |
|
| 147 | $anonymousUser = $userService->loadUser($anonymousUserId); |
|
| 148 | ||
| 149 | // Set anonymous user as current user reference |
|
| 150 | $permissionResolver->setCurrentUserReference($anonymousUser); |
|
| 151 | ||
| 152 | // This call will return false because anonymous user does not have access |
|
| 153 | // to content removal |
|
| 154 | $hasAccess = $permissionResolver->hasAccess('content', 'remove'); |
|
| 155 | /* END: Use Case */ |
|
| 156 | ||
| 157 | $this->assertFalse($hasAccess); |
|
| 158 | } |
|
| 159 | ||
| 160 | /** |
|
| 161 | * Test for the hasAccess() method. |
|
| @@ 196-219 (lines=24) @@ | ||
| 193 | * @depends eZ\Publish\API\Repository\Tests\PermissionResolverTest::testSetCurrentUserReference |
|
| 194 | * @depends eZ\Publish\API\Repository\Tests\PermissionResolverTest::testHasAccessWithAdministratorUser |
|
| 195 | */ |
|
| 196 | public function testHasAccessForCurrentUserYes() |
|
| 197 | { |
|
| 198 | $repository = $this->getRepository(); |
|
| 199 | ||
| 200 | $administratorUserId = $this->generateId('user', 14); |
|
| 201 | ||
| 202 | /* BEGIN: Use Case */ |
|
| 203 | // $administratorUserId contains the ID of the administrator user |
|
| 204 | ||
| 205 | $userService = $repository->getUserService(); |
|
| 206 | $permissionResolver = $repository->getPermissionResolver(); |
|
| 207 | ||
| 208 | // Load administrator user |
|
| 209 | $administratorUser = $userService->loadUser($administratorUserId); |
|
| 210 | ||
| 211 | // Set administrator user as current user reference |
|
| 212 | $permissionResolver->setCurrentUserReference($administratorUser); |
|
| 213 | ||
| 214 | // This call will return true |
|
| 215 | $hasAccess = $permissionResolver->hasAccess('content', 'read'); |
|
| 216 | /* END: Use Case */ |
|
| 217 | ||
| 218 | $this->assertTrue($hasAccess); |
|
| 219 | } |
|
| 220 | ||
| 221 | /** |
|
| 222 | * Test for the hasAccess() method. |
|
| @@ 349-375 (lines=27) @@ | ||
| 346 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetContentService |
|
| 347 | * @depends eZ\Publish\API\Repository\Tests\PermissionResolverTest::testHasAccessLimited |
|
| 348 | */ |
|
| 349 | public function testCanUserWithLimitationYes() |
|
| 350 | { |
|
| 351 | $repository = $this->getRepository(); |
|
| 352 | ||
| 353 | $imagesFolderId = $this->generateId('object', 49); |
|
| 354 | ||
| 355 | /* BEGIN: Use Case */ |
|
| 356 | // $imagesFolderId contains the ID of the "Images" folder |
|
| 357 | ||
| 358 | $user = $this->createUserVersion1(); |
|
| 359 | ||
| 360 | $permissionResolver = $repository->getPermissionResolver(); |
|
| 361 | ||
| 362 | // Set created user as current user reference |
|
| 363 | $permissionResolver->setCurrentUserReference($user); |
|
| 364 | ||
| 365 | $contentService = $repository->getContentService(); |
|
| 366 | ||
| 367 | // Performing an action having necessary permissions will succeed |
|
| 368 | $imagesFolder = $contentService->loadContent($imagesFolderId); |
|
| 369 | ||
| 370 | // This call will return true |
|
| 371 | $canUser = $permissionResolver->canUser('content', 'read', $imagesFolder); |
|
| 372 | /* END: Use Case */ |
|
| 373 | ||
| 374 | $this->assertTrue($canUser); |
|
| 375 | } |
|
| 376 | ||
| 377 | /** |
|
| 378 | * Test for the canUser() method. |
|
| @@ 430-456 (lines=27) @@ | ||
| 427 | * @depends eZ\Publish\API\Repository\Tests\PermissionResolverTest::testHasAccessLimited |
|
| 428 | * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
|
| 429 | */ |
|
| 430 | public function testCanUserThrowsInvalidArgumentException() |
|
| 431 | { |
|
| 432 | $repository = $this->getRepository(); |
|
| 433 | ||
| 434 | $userGroupContentTypeId = $this->generateId('type', 3); |
|
| 435 | ||
| 436 | /* BEGIN: Use Case */ |
|
| 437 | // $userGroupContentTypeId contains the ID of the "UserGroup" ContentType |
|
| 438 | ||
| 439 | $user = $this->createUserVersion1(); |
|
| 440 | ||
| 441 | $permissionResolver = $repository->getPermissionResolver(); |
|
| 442 | ||
| 443 | // Set created user as current user reference |
|
| 444 | $permissionResolver->setCurrentUserReference($user); |
|
| 445 | ||
| 446 | $contentTypeService = $repository->getContentTypeService(); |
|
| 447 | ||
| 448 | // Load the "UserGroup" ContentType |
|
| 449 | $userGroupContentType = $contentTypeService->loadContentType($userGroupContentTypeId); |
|
| 450 | ||
| 451 | // This call will throw "InvalidArgumentException" because $userGroupContentType |
|
| 452 | // is an instance of \eZ\Publish\API\Repository\Values\ContentType\ContentType, |
|
| 453 | // which can not be checked for user access |
|
| 454 | $canUser = $permissionResolver->canUser('content', 'create', $userGroupContentType); |
|
| 455 | /* END: Use Case */ |
|
| 456 | } |
|
| 457 | ||
| 458 | /** |
|
| 459 | * Test for the canUser() method. |
|