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