| @@ 937-983 (lines=47) @@ | ||
| 934 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testHasAccessLimited |
|
| 935 | * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
|
| 936 | */ |
|
| 937 | public function testCanUserWithMultipleTargetsNo() |
|
| 938 | { |
|
| 939 | $repository = $this->getRepository(); |
|
| 940 | ||
| 941 | $homeLocationId = $this->generateId('location', 2); |
|
| 942 | $administratorUsersLocationId = $this->generateId('location', 13); |
|
| 943 | ||
| 944 | /* BEGIN: Use Case */ |
|
| 945 | // $homeLocationId contains the ID of the "Home" location |
|
| 946 | // $administratorUsersLocationId contains the ID of the "Administrator users" location |
|
| 947 | ||
| 948 | $user = $this->createUserVersion1(); |
|
| 949 | ||
| 950 | // Set created user as current user |
|
| 951 | $repository->setCurrentUser($user); |
|
| 952 | ||
| 953 | $contentTypeService = $repository->getContentTypeService(); |
|
| 954 | ||
| 955 | $contentType = $contentTypeService->loadContentTypeByIdentifier('forums'); |
|
| 956 | ||
| 957 | $contentService = $repository->getContentService(); |
|
| 958 | ||
| 959 | $contentCreateStruct = $contentService->newContentCreateStruct($contentType, 'eng-US'); |
|
| 960 | $contentCreateStruct->setField('name', 'My awesome forums'); |
|
| 961 | $contentCreateStruct->remoteId = 'abcdef0123456789abcdef0123456789'; |
|
| 962 | $contentCreateStruct->alwaysAvailable = true; |
|
| 963 | ||
| 964 | $locationService = $repository->getLocationService(); |
|
| 965 | $locationCreateStruct1 = $locationService->newLocationCreateStruct($homeLocationId); |
|
| 966 | $locationCreateStruct2 = $locationService->newLocationCreateStruct($administratorUsersLocationId); |
|
| 967 | $locationCreateStructs = array($locationCreateStruct1, $locationCreateStruct2); |
|
| 968 | ||
| 969 | // This call will return false because user with Editor role does not have permission to |
|
| 970 | // create content in the "Administrator users" location subtree |
|
| 971 | $canUser = $repository->canUser( |
|
| 972 | 'content', |
|
| 973 | 'create', |
|
| 974 | $contentCreateStruct, |
|
| 975 | $locationCreateStructs |
|
| 976 | ); |
|
| 977 | ||
| 978 | // Performing an action without necessary permissions will fail with "UnauthorizedException" |
|
| 979 | if (!$canUser) { |
|
| 980 | $contentDraft = $contentService->createContent($contentCreateStruct, $locationCreateStructs); |
|
| 981 | } |
|
| 982 | /* END: Use Case */ |
|
| 983 | } |
|
| 984 | ||
| 985 | /** |
|
| 986 | * Test for the canUser() method. |
|
| @@ 654-702 (lines=49) @@ | ||
| 651 | * @depends eZ\Publish\API\Repository\Tests\PermissionResolverTest::testHasAccessLimited |
|
| 652 | * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
|
| 653 | */ |
|
| 654 | public function testCanUserWithMultipleTargetsNo() |
|
| 655 | { |
|
| 656 | $repository = $this->getRepository(); |
|
| 657 | ||
| 658 | $homeLocationId = $this->generateId('location', 2); |
|
| 659 | $administratorUsersLocationId = $this->generateId('location', 13); |
|
| 660 | ||
| 661 | /* BEGIN: Use Case */ |
|
| 662 | // $homeLocationId contains the ID of the "Home" location |
|
| 663 | // $administratorUsersLocationId contains the ID of the "Administrator users" location |
|
| 664 | ||
| 665 | $user = $this->createUserVersion1(); |
|
| 666 | ||
| 667 | $permissionResolver = $repository->getPermissionResolver(); |
|
| 668 | ||
| 669 | // Set created user as current user reference |
|
| 670 | $permissionResolver->setCurrentUserReference($user); |
|
| 671 | ||
| 672 | $contentTypeService = $repository->getContentTypeService(); |
|
| 673 | ||
| 674 | $contentType = $contentTypeService->loadContentTypeByIdentifier('forums'); |
|
| 675 | ||
| 676 | $contentService = $repository->getContentService(); |
|
| 677 | ||
| 678 | $contentCreateStruct = $contentService->newContentCreateStruct($contentType, 'eng-US'); |
|
| 679 | $contentCreateStruct->setField('name', 'My awesome forums'); |
|
| 680 | $contentCreateStruct->remoteId = 'abcdef0123456789abcdef0123456789'; |
|
| 681 | $contentCreateStruct->alwaysAvailable = true; |
|
| 682 | ||
| 683 | $locationService = $repository->getLocationService(); |
|
| 684 | $locationCreateStruct1 = $locationService->newLocationCreateStruct($homeLocationId); |
|
| 685 | $locationCreateStruct2 = $locationService->newLocationCreateStruct($administratorUsersLocationId); |
|
| 686 | $locationCreateStructs = array($locationCreateStruct1, $locationCreateStruct2); |
|
| 687 | ||
| 688 | // This call will return false because user with Editor role does not have permission to |
|
| 689 | // create content in the "Administrator users" location subtree |
|
| 690 | $canUser = $permissionResolver->canUser( |
|
| 691 | 'content', |
|
| 692 | 'create', |
|
| 693 | $contentCreateStruct, |
|
| 694 | $locationCreateStructs |
|
| 695 | ); |
|
| 696 | ||
| 697 | // Performing an action without necessary permissions will fail with "UnauthorizedException" |
|
| 698 | if (!$canUser) { |
|
| 699 | $contentDraft = $contentService->createContent($contentCreateStruct, $locationCreateStructs); |
|
| 700 | } |
|
| 701 | /* END: Use Case */ |
|
| 702 | } |
|
| 703 | ||
| 704 | /** |
|
| 705 | * Test for the canUser() method. |
|