| @@ 585-636 (lines=52) @@ | ||
| 582 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetContentTypeService |
|
| 583 | * @depends eZ\Publish\API\Repository\Tests\PermissionServiceTest::testHasAccessLimited |
|
| 584 | */ |
|
| 585 | public function testCanUserWithMultipleTargetsYes() |
|
| 586 | { |
|
| 587 | $repository = $this->getRepository(); |
|
| 588 | ||
| 589 | $imagesLocationId = $this->generateId('location', 51); |
|
| 590 | $filesLocationId = $this->generateId('location', 52); |
|
| 591 | ||
| 592 | /* BEGIN: Use Case */ |
|
| 593 | // $imagesLocationId contains the ID of the "Images" location |
|
| 594 | // $filesLocationId contains the ID of the "Files" location |
|
| 595 | ||
| 596 | $user = $this->createUserVersion1(); |
|
| 597 | ||
| 598 | $permissionService = $repository->getPermissionService(); |
|
| 599 | ||
| 600 | // Set created user as current user reference |
|
| 601 | $permissionService->setCurrentUserReference($user); |
|
| 602 | ||
| 603 | $contentTypeService = $repository->getContentTypeService(); |
|
| 604 | ||
| 605 | $contentType = $contentTypeService->loadContentTypeByIdentifier('folder'); |
|
| 606 | ||
| 607 | $contentService = $repository->getContentService(); |
|
| 608 | ||
| 609 | $contentCreateStruct = $contentService->newContentCreateStruct($contentType, 'eng-US'); |
|
| 610 | $contentCreateStruct->setField('name', 'My multipurpose folder'); |
|
| 611 | $contentCreateStruct->remoteId = 'abcdef0123456789abcdef0123456789'; |
|
| 612 | $contentCreateStruct->alwaysAvailable = true; |
|
| 613 | ||
| 614 | $locationService = $repository->getLocationService(); |
|
| 615 | $locationCreateStruct1 = $locationService->newLocationCreateStruct($imagesLocationId); |
|
| 616 | $locationCreateStruct2 = $locationService->newLocationCreateStruct($filesLocationId); |
|
| 617 | $locationCreateStructs = array($locationCreateStruct1, $locationCreateStruct2); |
|
| 618 | ||
| 619 | // This call will return true |
|
| 620 | $canUser = $permissionService->canUser( |
|
| 621 | 'content', |
|
| 622 | 'create', |
|
| 623 | $contentCreateStruct, |
|
| 624 | $locationCreateStructs |
|
| 625 | ); |
|
| 626 | ||
| 627 | // Performing an action having necessary permissions will succeed |
|
| 628 | $contentDraft = $contentService->createContent($contentCreateStruct, $locationCreateStructs); |
|
| 629 | /* END: Use Case */ |
|
| 630 | ||
| 631 | $this->assertTrue($canUser); |
|
| 632 | $this->assertEquals( |
|
| 633 | 'My multipurpose folder', |
|
| 634 | $contentDraft->getFieldValue('name')->text |
|
| 635 | ); |
|
| 636 | } |
|
| 637 | ||
| 638 | /** |
|
| 639 | * Test for the canUser() method. |
|
| @@ 852-901 (lines=50) @@ | ||
| 849 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetContentTypeService |
|
| 850 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testHasAccessLimited |
|
| 851 | */ |
|
| 852 | public function testCanUserWithMultipleTargetsYes() |
|
| 853 | { |
|
| 854 | $repository = $this->getRepository(); |
|
| 855 | ||
| 856 | $imagesLocationId = $this->generateId('location', 51); |
|
| 857 | $filesLocationId = $this->generateId('location', 52); |
|
| 858 | ||
| 859 | /* BEGIN: Use Case */ |
|
| 860 | // $imagesLocationId contains the ID of the "Images" location |
|
| 861 | // $filesLocationId contains the ID of the "Files" location |
|
| 862 | ||
| 863 | $user = $this->createUserVersion1(); |
|
| 864 | ||
| 865 | // Set created user as current user |
|
| 866 | $repository->setCurrentUser($user); |
|
| 867 | ||
| 868 | $contentTypeService = $repository->getContentTypeService(); |
|
| 869 | ||
| 870 | $contentType = $contentTypeService->loadContentTypeByIdentifier('folder'); |
|
| 871 | ||
| 872 | $contentService = $repository->getContentService(); |
|
| 873 | ||
| 874 | $contentCreateStruct = $contentService->newContentCreateStruct($contentType, 'eng-US'); |
|
| 875 | $contentCreateStruct->setField('name', 'My multipurpose folder'); |
|
| 876 | $contentCreateStruct->remoteId = 'abcdef0123456789abcdef0123456789'; |
|
| 877 | $contentCreateStruct->alwaysAvailable = true; |
|
| 878 | ||
| 879 | $locationService = $repository->getLocationService(); |
|
| 880 | $locationCreateStruct1 = $locationService->newLocationCreateStruct($imagesLocationId); |
|
| 881 | $locationCreateStruct2 = $locationService->newLocationCreateStruct($filesLocationId); |
|
| 882 | $locationCreateStructs = array($locationCreateStruct1, $locationCreateStruct2); |
|
| 883 | ||
| 884 | // This call will return true |
|
| 885 | $canUser = $repository->canUser( |
|
| 886 | 'content', |
|
| 887 | 'create', |
|
| 888 | $contentCreateStruct, |
|
| 889 | $locationCreateStructs |
|
| 890 | ); |
|
| 891 | ||
| 892 | // Performing an action having necessary permissions will succeed |
|
| 893 | $contentDraft = $contentService->createContent($contentCreateStruct, $locationCreateStructs); |
|
| 894 | /* END: Use Case */ |
|
| 895 | ||
| 896 | $this->assertTrue($canUser); |
|
| 897 | $this->assertEquals( |
|
| 898 | 'My multipurpose folder', |
|
| 899 | $contentDraft->getFieldValue('name')->text |
|
| 900 | ); |
|
| 901 | } |
|
| 902 | ||
| 903 | /** |
|
| 904 | * Test for the canUser() method. |
|