| @@ 876-925 (lines=50) @@ | ||
| 873 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetContentTypeService |
|
| 874 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testHasAccessLimited |
|
| 875 | */ |
|
| 876 | public function testCanUserWithMultipleTargetsYes() |
|
| 877 | { |
|
| 878 | $repository = $this->getRepository(); |
|
| 879 | ||
| 880 | $imagesLocationId = $this->generateId('location', 51); |
|
| 881 | $filesLocationId = $this->generateId('location', 52); |
|
| 882 | ||
| 883 | /* BEGIN: Use Case */ |
|
| 884 | // $imagesLocationId contains the ID of the "Images" location |
|
| 885 | // $filesLocationId contains the ID of the "Files" location |
|
| 886 | ||
| 887 | $user = $this->createUserVersion1(); |
|
| 888 | ||
| 889 | // Set created user as current user |
|
| 890 | $repository->setCurrentUser($user); |
|
| 891 | ||
| 892 | $contentTypeService = $repository->getContentTypeService(); |
|
| 893 | ||
| 894 | $contentType = $contentTypeService->loadContentTypeByIdentifier('folder'); |
|
| 895 | ||
| 896 | $contentService = $repository->getContentService(); |
|
| 897 | ||
| 898 | $contentCreateStruct = $contentService->newContentCreateStruct($contentType, 'eng-US'); |
|
| 899 | $contentCreateStruct->setField('name', 'My multipurpose folder'); |
|
| 900 | $contentCreateStruct->remoteId = 'abcdef0123456789abcdef0123456789'; |
|
| 901 | $contentCreateStruct->alwaysAvailable = true; |
|
| 902 | ||
| 903 | $locationService = $repository->getLocationService(); |
|
| 904 | $locationCreateStruct1 = $locationService->newLocationCreateStruct($imagesLocationId); |
|
| 905 | $locationCreateStruct2 = $locationService->newLocationCreateStruct($filesLocationId); |
|
| 906 | $locationCreateStructs = [$locationCreateStruct1, $locationCreateStruct2]; |
|
| 907 | ||
| 908 | // This call will return true |
|
| 909 | $canUser = $repository->canUser( |
|
| 910 | 'content', |
|
| 911 | 'create', |
|
| 912 | $contentCreateStruct, |
|
| 913 | $locationCreateStructs |
|
| 914 | ); |
|
| 915 | ||
| 916 | // Performing an action having necessary permissions will succeed |
|
| 917 | $contentDraft = $contentService->createContent($contentCreateStruct, $locationCreateStructs); |
|
| 918 | /* END: Use Case */ |
|
| 919 | ||
| 920 | $this->assertTrue($canUser); |
|
| 921 | $this->assertEquals( |
|
| 922 | 'My multipurpose folder', |
|
| 923 | $contentDraft->getFieldValue('name')->text |
|
| 924 | ); |
|
| 925 | } |
|
| 926 | ||
| 927 | /** |
|
| 928 | * Test for the canUser() method. |
|
| @@ 591-642 (lines=52) @@ | ||
| 588 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetContentTypeService |
|
| 589 | * @depends eZ\Publish\API\Repository\Tests\PermissionResolverTest::testHasAccessLimited |
|
| 590 | */ |
|
| 591 | public function testCanUserWithMultipleTargetsYes() |
|
| 592 | { |
|
| 593 | $repository = $this->getRepository(); |
|
| 594 | ||
| 595 | $imagesLocationId = $this->generateId('location', 51); |
|
| 596 | $filesLocationId = $this->generateId('location', 52); |
|
| 597 | ||
| 598 | /* BEGIN: Use Case */ |
|
| 599 | // $imagesLocationId contains the ID of the "Images" location |
|
| 600 | // $filesLocationId contains the ID of the "Files" location |
|
| 601 | ||
| 602 | $user = $this->createUserVersion1(); |
|
| 603 | ||
| 604 | $permissionResolver = $repository->getPermissionResolver(); |
|
| 605 | ||
| 606 | // Set created user as current user reference |
|
| 607 | $permissionResolver->setCurrentUserReference($user); |
|
| 608 | ||
| 609 | $contentTypeService = $repository->getContentTypeService(); |
|
| 610 | ||
| 611 | $contentType = $contentTypeService->loadContentTypeByIdentifier('folder'); |
|
| 612 | ||
| 613 | $contentService = $repository->getContentService(); |
|
| 614 | ||
| 615 | $contentCreateStruct = $contentService->newContentCreateStruct($contentType, 'eng-US'); |
|
| 616 | $contentCreateStruct->setField('name', 'My multipurpose folder'); |
|
| 617 | $contentCreateStruct->remoteId = 'abcdef0123456789abcdef0123456789'; |
|
| 618 | $contentCreateStruct->alwaysAvailable = true; |
|
| 619 | ||
| 620 | $locationService = $repository->getLocationService(); |
|
| 621 | $locationCreateStruct1 = $locationService->newLocationCreateStruct($imagesLocationId); |
|
| 622 | $locationCreateStruct2 = $locationService->newLocationCreateStruct($filesLocationId); |
|
| 623 | $locationCreateStructs = [$locationCreateStruct1, $locationCreateStruct2]; |
|
| 624 | ||
| 625 | // This call will return true |
|
| 626 | $canUser = $permissionResolver->canUser( |
|
| 627 | 'content', |
|
| 628 | 'create', |
|
| 629 | $contentCreateStruct, |
|
| 630 | $locationCreateStructs |
|
| 631 | ); |
|
| 632 | ||
| 633 | // Performing an action having necessary permissions will succeed |
|
| 634 | $contentDraft = $contentService->createContent($contentCreateStruct, $locationCreateStructs); |
|
| 635 | /* END: Use Case */ |
|
| 636 | ||
| 637 | $this->assertTrue($canUser); |
|
| 638 | $this->assertEquals( |
|
| 639 | 'My multipurpose folder', |
|
| 640 | $contentDraft->getFieldValue('name')->text |
|
| 641 | ); |
|
| 642 | } |
|
| 643 | ||
| 644 | /** |
|
| 645 | * Test for the canUser() method. |
|