| @@ 648-696 (lines=49) @@ | ||
| 645 | * @depends eZ\Publish\API\Repository\Tests\PermissionServiceTest::testHasAccessLimited |
|
| 646 | * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
|
| 647 | */ |
|
| 648 | public function testCanUserWithMultipleTargetsNo() |
|
| 649 | { |
|
| 650 | $repository = $this->getRepository(); |
|
| 651 | ||
| 652 | $homeLocationId = $this->generateId('location', 2); |
|
| 653 | $administratorUsersLocationId = $this->generateId('location', 13); |
|
| 654 | ||
| 655 | /* BEGIN: Use Case */ |
|
| 656 | // $homeLocationId contains the ID of the "Home" location |
|
| 657 | // $administratorUsersLocationId contains the ID of the "Administrator users" location |
|
| 658 | ||
| 659 | $user = $this->createUserVersion1(); |
|
| 660 | ||
| 661 | $permissionService = $repository->getPermissionService(); |
|
| 662 | ||
| 663 | // Set created user as current user reference |
|
| 664 | $permissionService->setCurrentUserReference($user); |
|
| 665 | ||
| 666 | $contentTypeService = $repository->getContentTypeService(); |
|
| 667 | ||
| 668 | $contentType = $contentTypeService->loadContentTypeByIdentifier('forums'); |
|
| 669 | ||
| 670 | $contentService = $repository->getContentService(); |
|
| 671 | ||
| 672 | $contentCreateStruct = $contentService->newContentCreateStruct($contentType, 'eng-US'); |
|
| 673 | $contentCreateStruct->setField('name', 'My awesome forums'); |
|
| 674 | $contentCreateStruct->remoteId = 'abcdef0123456789abcdef0123456789'; |
|
| 675 | $contentCreateStruct->alwaysAvailable = true; |
|
| 676 | ||
| 677 | $locationService = $repository->getLocationService(); |
|
| 678 | $locationCreateStruct1 = $locationService->newLocationCreateStruct($homeLocationId); |
|
| 679 | $locationCreateStruct2 = $locationService->newLocationCreateStruct($administratorUsersLocationId); |
|
| 680 | $locationCreateStructs = array($locationCreateStruct1, $locationCreateStruct2); |
|
| 681 | ||
| 682 | // This call will return false because user with Editor role does not have permission to |
|
| 683 | // create content in the "Administrator users" location subtree |
|
| 684 | $canUser = $permissionService->canUser( |
|
| 685 | 'content', |
|
| 686 | 'create', |
|
| 687 | $contentCreateStruct, |
|
| 688 | $locationCreateStructs |
|
| 689 | ); |
|
| 690 | ||
| 691 | // Performing an action without necessary permissions will fail with "UnauthorizedException" |
|
| 692 | if (!$canUser) { |
|
| 693 | $contentDraft = $contentService->createContent($contentCreateStruct, $locationCreateStructs); |
|
| 694 | } |
|
| 695 | /* END: Use Case */ |
|
| 696 | } |
|
| 697 | ||
| 698 | /** |
|
| 699 | * Test for the canUser() method. |
|
| @@ 913-959 (lines=47) @@ | ||
| 910 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testHasAccessLimited |
|
| 911 | * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
|
| 912 | */ |
|
| 913 | public function testCanUserWithMultipleTargetsNo() |
|
| 914 | { |
|
| 915 | $repository = $this->getRepository(); |
|
| 916 | ||
| 917 | $homeLocationId = $this->generateId('location', 2); |
|
| 918 | $administratorUsersLocationId = $this->generateId('location', 13); |
|
| 919 | ||
| 920 | /* BEGIN: Use Case */ |
|
| 921 | // $homeLocationId contains the ID of the "Home" location |
|
| 922 | // $administratorUsersLocationId contains the ID of the "Administrator users" location |
|
| 923 | ||
| 924 | $user = $this->createUserVersion1(); |
|
| 925 | ||
| 926 | // Set created user as current user |
|
| 927 | $repository->setCurrentUser($user); |
|
| 928 | ||
| 929 | $contentTypeService = $repository->getContentTypeService(); |
|
| 930 | ||
| 931 | $contentType = $contentTypeService->loadContentTypeByIdentifier('forums'); |
|
| 932 | ||
| 933 | $contentService = $repository->getContentService(); |
|
| 934 | ||
| 935 | $contentCreateStruct = $contentService->newContentCreateStruct($contentType, 'eng-US'); |
|
| 936 | $contentCreateStruct->setField('name', 'My awesome forums'); |
|
| 937 | $contentCreateStruct->remoteId = 'abcdef0123456789abcdef0123456789'; |
|
| 938 | $contentCreateStruct->alwaysAvailable = true; |
|
| 939 | ||
| 940 | $locationService = $repository->getLocationService(); |
|
| 941 | $locationCreateStruct1 = $locationService->newLocationCreateStruct($homeLocationId); |
|
| 942 | $locationCreateStruct2 = $locationService->newLocationCreateStruct($administratorUsersLocationId); |
|
| 943 | $locationCreateStructs = array($locationCreateStruct1, $locationCreateStruct2); |
|
| 944 | ||
| 945 | // This call will return false because user with Editor role does not have permission to |
|
| 946 | // create content in the "Administrator users" location subtree |
|
| 947 | $canUser = $repository->canUser( |
|
| 948 | 'content', |
|
| 949 | 'create', |
|
| 950 | $contentCreateStruct, |
|
| 951 | $locationCreateStructs |
|
| 952 | ); |
|
| 953 | ||
| 954 | // Performing an action without necessary permissions will fail with "UnauthorizedException" |
|
| 955 | if (!$canUser) { |
|
| 956 | $contentDraft = $contentService->createContent($contentCreateStruct, $locationCreateStructs); |
|
| 957 | } |
|
| 958 | /* END: Use Case */ |
|
| 959 | } |
|
| 960 | ||
| 961 | /** |
|
| 962 | * Test for the canUser() method. |
|