| @@ 169-193 (lines=25) @@ | ||
| 166 | * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testNewLocationCreateStruct |
|
| 167 | * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
|
| 168 | */ |
|
| 169 | public function testCreateLocationThrowsInvalidArgumentExceptionContentAlreadyBelowParent() |
|
| 170 | { |
|
| 171 | $repository = $this->getRepository(); |
|
| 172 | ||
| 173 | $contentId = $this->generateId('object', 11); |
|
| 174 | $parentLocationId = $this->generateId('location', 5); |
|
| 175 | /* BEGIN: Use Case */ |
|
| 176 | // $contentId is the ID of an existing content object |
|
| 177 | // $parentLocationId is the ID of an existing location which already |
|
| 178 | // has the content assigned to one of its descendant locations |
|
| 179 | $contentService = $repository->getContentService(); |
|
| 180 | $locationService = $repository->getLocationService(); |
|
| 181 | ||
| 182 | // ContentInfo for "How to use eZ Publish" |
|
| 183 | $contentInfo = $contentService->loadContentInfo($contentId); |
|
| 184 | ||
| 185 | $locationCreate = $locationService->newLocationCreateStruct($parentLocationId); |
|
| 186 | ||
| 187 | // Throws exception, since content is already located at "/1/2/107/110/" |
|
| 188 | $locationService->createLocation( |
|
| 189 | $contentInfo, |
|
| 190 | $locationCreate |
|
| 191 | ); |
|
| 192 | /* END: Use Case */ |
|
| 193 | } |
|
| 194 | ||
| 195 | /** |
|
| 196 | * Test for the createLocation() method. |
|
| @@ 202-226 (lines=25) @@ | ||
| 199 | * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testNewLocationCreateStruct |
|
| 200 | * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
|
| 201 | */ |
|
| 202 | public function testCreateLocationThrowsInvalidArgumentExceptionParentIsSubLocationOfContent() |
|
| 203 | { |
|
| 204 | $repository = $this->getRepository(); |
|
| 205 | ||
| 206 | $contentId = $this->generateId('object', 4); |
|
| 207 | $parentLocationId = $this->generateId('location', 12); |
|
| 208 | /* BEGIN: Use Case */ |
|
| 209 | // $contentId is the ID of an existing content object |
|
| 210 | // $parentLocationId is the ID of an existing location which is below a |
|
| 211 | // location that is assigned to the content |
|
| 212 | $contentService = $repository->getContentService(); |
|
| 213 | $locationService = $repository->getLocationService(); |
|
| 214 | ||
| 215 | // ContentInfo for "How to use eZ Publish" |
|
| 216 | $contentInfo = $contentService->loadContentInfo($contentId); |
|
| 217 | ||
| 218 | $locationCreate = $locationService->newLocationCreateStruct($parentLocationId); |
|
| 219 | ||
| 220 | // Throws exception, since content is already located at "/1/2/" |
|
| 221 | $locationService->createLocation( |
|
| 222 | $contentInfo, |
|
| 223 | $locationCreate |
|
| 224 | ); |
|
| 225 | /* END: Use Case */ |
|
| 226 | } |
|
| 227 | ||
| 228 | /** |
|
| 229 | * Test for the createLocation() method. |
|
| @@ 395-420 (lines=26) @@ | ||
| 392 | * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
|
| 393 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentByVersionInfo |
|
| 394 | */ |
|
| 395 | public function testLoadContentByVersionInfoThrowsUnauthorizedException() |
|
| 396 | { |
|
| 397 | $repository = $this->getRepository(); |
|
| 398 | ||
| 399 | $anonymousUserId = $this->generateId('user', 10); |
|
| 400 | /* BEGIN: Use Case */ |
|
| 401 | // $anonymousUserId is the ID of the "Anonymous User" in an eZ Publish |
|
| 402 | // demo installation |
|
| 403 | ||
| 404 | $contentService = $repository->getContentService(); |
|
| 405 | ||
| 406 | // Load the ContentInfo for "Anonymous User" |
|
| 407 | $contentInfo = $contentService->loadContentInfo($anonymousUserId); |
|
| 408 | ||
| 409 | // Load the current VersionInfo |
|
| 410 | $versionInfo = $contentService->loadVersionInfo($contentInfo); |
|
| 411 | ||
| 412 | $pseudoEditor = $this->createAnonymousWithEditorRole(); |
|
| 413 | ||
| 414 | // Set restricted editor user |
|
| 415 | $repository->setCurrentUser($pseudoEditor); |
|
| 416 | ||
| 417 | // This call will fail with a "UnauthorizedException" |
|
| 418 | $contentService->loadContentByVersionInfo($versionInfo); |
|
| 419 | /* END: Use Case */ |
|
| 420 | } |
|
| 421 | ||
| 422 | /** |
|
| 423 | * Test for the loadContentByVersionInfo() method. |
|
| @@ 429-454 (lines=26) @@ | ||
| 426 | * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
|
| 427 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentByVersionInfoWithSecondParameter |
|
| 428 | */ |
|
| 429 | public function testLoadContentByVersionInfoThrowsUnauthorizedExceptionWithSecondParameter() |
|
| 430 | { |
|
| 431 | $repository = $this->getRepository(); |
|
| 432 | ||
| 433 | $anonymousUserId = $this->generateId('user', 10); |
|
| 434 | /* BEGIN: Use Case */ |
|
| 435 | // $anonymousUserId is the ID of the "Anonymous User" in an eZ Publish |
|
| 436 | // demo installation |
|
| 437 | ||
| 438 | $contentService = $repository->getContentService(); |
|
| 439 | ||
| 440 | // Load the ContentInfo for "Anonymous User" |
|
| 441 | $contentInfo = $contentService->loadContentInfo($anonymousUserId); |
|
| 442 | ||
| 443 | // Load the current VersionInfo |
|
| 444 | $versionInfo = $contentService->loadVersionInfo($contentInfo); |
|
| 445 | ||
| 446 | $pseudoEditor = $this->createAnonymousWithEditorRole(); |
|
| 447 | ||
| 448 | // Set restricted editor user |
|
| 449 | $repository->setCurrentUser($pseudoEditor); |
|
| 450 | ||
| 451 | // This call will fail with a "UnauthorizedException" |
|
| 452 | $contentService->loadContentByVersionInfo($versionInfo, ['eng-US']); |
|
| 453 | /* END: Use Case */ |
|
| 454 | } |
|
| 455 | ||
| 456 | /** |
|
| 457 | * Test for the loadContent() method. |
|
| @@ 763-786 (lines=24) @@ | ||
| 760 | * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
|
| 761 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testDeleteContent |
|
| 762 | */ |
|
| 763 | public function testDeleteContentThrowsUnauthorizedException() |
|
| 764 | { |
|
| 765 | $repository = $this->getRepository(); |
|
| 766 | $contentService = $repository->getContentService(); |
|
| 767 | ||
| 768 | $anonymousUserId = $this->generateId('user', 10); |
|
| 769 | /* BEGIN: Use Case */ |
|
| 770 | // $anonymousUserId is the ID of the "Anonymous User" in an eZ Publish |
|
| 771 | // demo installation |
|
| 772 | $contentVersion2 = $this->createContentVersion2(); |
|
| 773 | ||
| 774 | // Get ContentInfo instance |
|
| 775 | $contentInfo = $contentVersion2->contentInfo; |
|
| 776 | ||
| 777 | // Load the user service |
|
| 778 | $userService = $repository->getUserService(); |
|
| 779 | ||
| 780 | // Set anonymous user |
|
| 781 | $repository->setCurrentUser($userService->loadUser($anonymousUserId)); |
|
| 782 | ||
| 783 | // This call will fail with a "UnauthorizedException" |
|
| 784 | $contentService->deleteContent($contentInfo); |
|
| 785 | /* END: Use Case */ |
|
| 786 | } |
|
| 787 | ||
| 788 | /** |
|
| 789 | * Test for the createContentDraft() method. |
|
| @@ 795-819 (lines=25) @@ | ||
| 792 | * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
|
| 793 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentDraft |
|
| 794 | */ |
|
| 795 | public function testCreateContentDraftThrowsUnauthorizedException() |
|
| 796 | { |
|
| 797 | $repository = $this->getRepository(); |
|
| 798 | ||
| 799 | $contentService = $repository->getContentService(); |
|
| 800 | ||
| 801 | $anonymousUserId = $this->generateId('user', 10); |
|
| 802 | /* BEGIN: Use Case */ |
|
| 803 | // $anonymousUserId is the ID of the "Anonymous User" in an eZ Publish |
|
| 804 | // demo installation |
|
| 805 | $content = $this->createContentVersion1(); |
|
| 806 | ||
| 807 | // Get ContentInfo instance |
|
| 808 | $contentInfo = $content->contentInfo; |
|
| 809 | ||
| 810 | // Load the user service |
|
| 811 | $userService = $repository->getUserService(); |
|
| 812 | ||
| 813 | // Set anonymous user |
|
| 814 | $repository->setCurrentUser($userService->loadUser($anonymousUserId)); |
|
| 815 | ||
| 816 | // This call will fail with a "UnauthorizedException" |
|
| 817 | $contentService->createContentDraft($contentInfo); |
|
| 818 | /* END: Use Case */ |
|
| 819 | } |
|
| 820 | ||
| 821 | /** |
|
| 822 | * Test for the createContentDraft() method. |
|
| @@ 891-917 (lines=27) @@ | ||
| 888 | * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
|
| 889 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentDrafts |
|
| 890 | */ |
|
| 891 | public function testLoadContentDraftsThrowsUnauthorizedExceptionWithFirstParameter() |
|
| 892 | { |
|
| 893 | $repository = $this->getRepository(); |
|
| 894 | ||
| 895 | $administratorUserId = $this->generateId('user', 14); |
|
| 896 | $anonymousUserId = $this->generateId('user', 10); |
|
| 897 | /* BEGIN: Use Case */ |
|
| 898 | // $anonymousUserId is the ID of the "Anonymous User" in an eZ Publish |
|
| 899 | // demo installation |
|
| 900 | // $administratorUserId is the ID of the "Administrator" user in a eZ |
|
| 901 | // Publish demo installation. |
|
| 902 | ||
| 903 | $contentService = $repository->getContentService(); |
|
| 904 | ||
| 905 | // Load the user service |
|
| 906 | $userService = $repository->getUserService(); |
|
| 907 | ||
| 908 | // Load the "Administrator" user |
|
| 909 | $administratorUser = $userService->loadUser($administratorUserId); |
|
| 910 | ||
| 911 | // Set anonymous user |
|
| 912 | $repository->setCurrentUser($userService->loadUser($anonymousUserId)); |
|
| 913 | ||
| 914 | // This call will fail with a "UnauthorizedException" |
|
| 915 | $contentService->loadContentDrafts($administratorUser); |
|
| 916 | /* END: Use Case */ |
|
| 917 | } |
|
| 918 | ||
| 919 | /** |
|
| 920 | * Test for the updateContent() method. |
|
| @@ 1026-1050 (lines=25) @@ | ||
| 1023 | * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
|
| 1024 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadVersions |
|
| 1025 | */ |
|
| 1026 | public function testLoadVersionsThrowsUnauthorizedException() |
|
| 1027 | { |
|
| 1028 | $repository = $this->getRepository(); |
|
| 1029 | ||
| 1030 | $contentService = $repository->getContentService(); |
|
| 1031 | ||
| 1032 | $anonymousUserId = $this->generateId('user', 10); |
|
| 1033 | /* BEGIN: Use Case */ |
|
| 1034 | // $anonymousUserId is the ID of the "Anonymous User" in an eZ Publish |
|
| 1035 | // demo installation |
|
| 1036 | $contentVersion2 = $this->createContentVersion2(); |
|
| 1037 | ||
| 1038 | // Get ContentInfo instance of version 2 |
|
| 1039 | $contentInfo = $contentVersion2->contentInfo; |
|
| 1040 | ||
| 1041 | // Load the user service |
|
| 1042 | $userService = $repository->getUserService(); |
|
| 1043 | ||
| 1044 | // Set anonymous user |
|
| 1045 | $repository->setCurrentUser($userService->loadUser($anonymousUserId)); |
|
| 1046 | ||
| 1047 | // This call will fail with a "UnauthorizedException" |
|
| 1048 | $contentService->loadVersions($contentInfo); |
|
| 1049 | /* END: Use Case */ |
|
| 1050 | } |
|
| 1051 | ||
| 1052 | /** |
|
| 1053 | * Test for the copyContent() method. |
|
| @@ 762-786 (lines=25) @@ | ||
| 759 | * @see \eZ\Publish\API\Repository\ContentService::loadContentByVersionInfo() |
|
| 760 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadVersionInfo |
|
| 761 | */ |
|
| 762 | public function testLoadContentByVersionInfo() |
|
| 763 | { |
|
| 764 | $repository = $this->getRepository(); |
|
| 765 | ||
| 766 | $mediaFolderId = $this->generateId('object', 41); |
|
| 767 | /* BEGIN: Use Case */ |
|
| 768 | // $mediaFolderId contains the ID of the "Media" folder |
|
| 769 | ||
| 770 | $contentService = $repository->getContentService(); |
|
| 771 | ||
| 772 | // Load the ContentInfo for "Media" folder |
|
| 773 | $contentInfo = $contentService->loadContentInfo($mediaFolderId); |
|
| 774 | ||
| 775 | // Load the current VersionInfo |
|
| 776 | $versionInfo = $contentService->loadVersionInfo($contentInfo); |
|
| 777 | ||
| 778 | // Now load the current content version for the info instance |
|
| 779 | $content = $contentService->loadContentByVersionInfo($versionInfo); |
|
| 780 | /* END: Use Case */ |
|
| 781 | ||
| 782 | $this->assertInstanceOf( |
|
| 783 | '\\eZ\\Publish\\API\\Repository\\Values\\Content\\Content', |
|
| 784 | $content |
|
| 785 | ); |
|
| 786 | } |
|
| 787 | ||
| 788 | /** |
|
| 789 | * Test for the loadContent() method. |
|
| @@ 631-655 (lines=25) @@ | ||
| 628 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetContentService |
|
| 629 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testHasAccessLimited |
|
| 630 | */ |
|
| 631 | public function testCanUserWithLimitationYes() |
|
| 632 | { |
|
| 633 | $repository = $this->getRepository(); |
|
| 634 | ||
| 635 | $imagesFolderId = $this->generateId('object', 49); |
|
| 636 | ||
| 637 | /* BEGIN: Use Case */ |
|
| 638 | // $imagesFolderId contains the ID of the "Images" folder |
|
| 639 | ||
| 640 | $user = $this->createUserVersion1(); |
|
| 641 | ||
| 642 | // Set created user as current user |
|
| 643 | $repository->setCurrentUser($user); |
|
| 644 | ||
| 645 | $contentService = $repository->getContentService(); |
|
| 646 | ||
| 647 | // Performing an action having necessary permissions will succeed |
|
| 648 | $imagesFolder = $contentService->loadContent($imagesFolderId); |
|
| 649 | ||
| 650 | // This call will return true |
|
| 651 | $canUser = $repository->canUser('content', 'read', $imagesFolder); |
|
| 652 | /* END: Use Case */ |
|
| 653 | ||
| 654 | $this->assertTrue($canUser); |
|
| 655 | } |
|
| 656 | ||
| 657 | /** |
|
| 658 | * Test for the canUser() method. |
|