| @@ 101-120 (lines=20) @@ | ||
| 98 | * @see \eZ\Publish\API\Repository\ContentService::loadContentInfo() |
|
| 99 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo |
|
| 100 | */ |
|
| 101 | public function testLoadContentInfoThrowsUnauthorizedException() |
|
| 102 | { |
|
| 103 | $this->expectException(\eZ\Publish\API\Repository\Exceptions\UnauthorizedException::class); |
|
| 104 | ||
| 105 | $repository = $this->getRepository(); |
|
| 106 | ||
| 107 | $contentId = $this->generateId('object', 10); |
|
| 108 | /* BEGIN: Use Case */ |
|
| 109 | $contentService = $repository->getContentService(); |
|
| 110 | ||
| 111 | $pseudoEditor = $this->createAnonymousWithEditorRole(); |
|
| 112 | ||
| 113 | // Set restricted editor user |
|
| 114 | $repository->setCurrentUser($pseudoEditor); |
|
| 115 | ||
| 116 | // This call will fail with a "UnauthorizedException" |
|
| 117 | // $contentId contains a content object ID not accessible for anonymous |
|
| 118 | $contentService->loadContentInfo($contentId); |
|
| 119 | /* END: Use Case */ |
|
| 120 | } |
|
| 121 | ||
| 122 | /** |
|
| 123 | * Test for the sudo() method. |
|
| @@ 151-161 (lines=11) @@ | ||
| 148 | * @see \eZ\Publish\API\Repository\ContentService::loadContentInfoList() |
|
| 149 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfoList |
|
| 150 | */ |
|
| 151 | public function testLoadContentInfoListSkipsUnauthorizedItems() |
|
| 152 | { |
|
| 153 | $repository = $this->getRepository(); |
|
| 154 | $contentId = $this->generateId('object', 10); |
|
| 155 | $contentService = $repository->getContentService(); |
|
| 156 | $repository->setCurrentUser($this->createAnonymousWithEditorRole()); |
|
| 157 | ||
| 158 | $list = $contentService->loadContentInfoList([$contentId]); |
|
| 159 | ||
| 160 | $this->assertCount(0, $list); |
|
| 161 | } |
|
| 162 | ||
| 163 | /** |
|
| 164 | * Test for the loadContentInfoByRemoteId() method. |
|
| @@ 197-221 (lines=25) @@ | ||
| 194 | * @see \eZ\Publish\API\Repository\ContentService::loadVersionInfo() |
|
| 195 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadVersionInfo |
|
| 196 | */ |
|
| 197 | public function testLoadVersionInfoThrowsUnauthorizedException() |
|
| 198 | { |
|
| 199 | $this->expectException(\eZ\Publish\API\Repository\Exceptions\UnauthorizedException::class); |
|
| 200 | ||
| 201 | $repository = $this->getRepository(); |
|
| 202 | ||
| 203 | $anonymousUserId = $this->generateId('user', 10); |
|
| 204 | /* BEGIN: Use Case */ |
|
| 205 | // $anonymousUserId is the ID of the "Anonymous User" in an eZ Publish |
|
| 206 | // demo installation |
|
| 207 | ||
| 208 | $contentService = $repository->getContentService(); |
|
| 209 | ||
| 210 | // Load the ContentInfo for "Anonymous User" |
|
| 211 | $contentInfo = $contentService->loadContentInfo($anonymousUserId); |
|
| 212 | ||
| 213 | $pseudoEditor = $this->createAnonymousWithEditorRole(); |
|
| 214 | ||
| 215 | // Set restricted editor user |
|
| 216 | $repository->setCurrentUser($pseudoEditor); |
|
| 217 | ||
| 218 | // This call will fail with a "UnauthorizedException" |
|
| 219 | $contentService->loadVersionInfo($contentInfo); |
|
| 220 | /* END: Use Case */ |
|
| 221 | } |
|
| 222 | ||
| 223 | /** |
|
| 224 | * Test for the loadVersionInfo() method. |
|
| @@ 353-377 (lines=25) @@ | ||
| 350 | * @see \eZ\Publish\API\Repository\ContentService::loadContentByContentInfo() |
|
| 351 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentByContentInfo |
|
| 352 | */ |
|
| 353 | public function testLoadContentByContentInfoThrowsUnauthorizedException() |
|
| 354 | { |
|
| 355 | $this->expectException(\eZ\Publish\API\Repository\Exceptions\UnauthorizedException::class); |
|
| 356 | ||
| 357 | $repository = $this->getRepository(); |
|
| 358 | ||
| 359 | $anonymousUserId = $this->generateId('user', 10); |
|
| 360 | /* BEGIN: Use Case */ |
|
| 361 | // $anonymousUserId is the ID of the "Anonymous User" in an eZ Publish |
|
| 362 | // demo installation |
|
| 363 | ||
| 364 | $contentService = $repository->getContentService(); |
|
| 365 | ||
| 366 | // Load the ContentInfo for "Anonymous User" |
|
| 367 | $contentInfo = $contentService->loadContentInfo($anonymousUserId); |
|
| 368 | ||
| 369 | $pseudoEditor = $this->createAnonymousWithEditorRole(); |
|
| 370 | ||
| 371 | // Set restricted editor user |
|
| 372 | $repository->setCurrentUser($pseudoEditor); |
|
| 373 | ||
| 374 | // This call will fail with a "UnauthorizedException" |
|
| 375 | $contentService->loadContentByContentInfo($contentInfo); |
|
| 376 | /* END: Use Case */ |
|
| 377 | } |
|
| 378 | ||
| 379 | /** |
|
| 380 | * Test for the loadContentByContentInfo() method. |
|
| @@ 577-598 (lines=22) @@ | ||
| 574 | * @see \eZ\Publish\API\Repository\ContentService::loadContent($contentId, $languages, $versionNo) |
|
| 575 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentWithThirdParameter |
|
| 576 | */ |
|
| 577 | public function testLoadContentThrowsUnauthorizedExceptionWithThirdParameter() |
|
| 578 | { |
|
| 579 | $this->expectException(\eZ\Publish\API\Repository\Exceptions\UnauthorizedException::class); |
|
| 580 | ||
| 581 | $repository = $this->getRepository(); |
|
| 582 | ||
| 583 | $anonymousUserId = $this->generateId('user', 10); |
|
| 584 | /* BEGIN: Use Case */ |
|
| 585 | // $anonymousUserId is the ID of the "Anonymous User" in an eZ Publish |
|
| 586 | // demo installation |
|
| 587 | ||
| 588 | $contentService = $repository->getContentService(); |
|
| 589 | ||
| 590 | $pseudoEditor = $this->createAnonymousWithEditorRole(); |
|
| 591 | ||
| 592 | // Set restricted editor user |
|
| 593 | $repository->setCurrentUser($pseudoEditor); |
|
| 594 | ||
| 595 | // This call will fail with a "UnauthorizedException" |
|
| 596 | $contentService->loadContent($anonymousUserId, array('eng-US'), 2); |
|
| 597 | /* END: Use Case */ |
|
| 598 | } |
|
| 599 | ||
| 600 | /** |
|
| 601 | * Test for the loadContent() method on a draft. |
|
| @@ 525-543 (lines=19) @@ | ||
| 522 | * @see \eZ\Publish\API\Repository\ContentService::loadContentInfo() |
|
| 523 | * @group user |
|
| 524 | */ |
|
| 525 | public function testLoadContentInfo() |
|
| 526 | { |
|
| 527 | $repository = $this->getRepository(); |
|
| 528 | ||
| 529 | $mediaFolderId = $this->generateId('object', 41); |
|
| 530 | /* BEGIN: Use Case */ |
|
| 531 | $contentService = $repository->getContentService(); |
|
| 532 | ||
| 533 | // Load the ContentInfo for "Media" folder |
|
| 534 | $contentInfo = $contentService->loadContentInfo($mediaFolderId); |
|
| 535 | /* END: Use Case */ |
|
| 536 | ||
| 537 | $this->assertInstanceOf( |
|
| 538 | '\\eZ\\Publish\\API\\Repository\\Values\\Content\\ContentInfo', |
|
| 539 | $contentInfo |
|
| 540 | ); |
|
| 541 | ||
| 542 | return $contentInfo; |
|
| 543 | } |
|
| 544 | ||
| 545 | /** |
|
| 546 | * Test for the returned value of the loadContentInfo() method. |
|
| @@ 609-618 (lines=10) @@ | ||
| 606 | * @see \eZ\Publish\API\Repository\ContentService::loadContentInfoList() |
|
| 607 | * @depends testLoadContentInfoList |
|
| 608 | */ |
|
| 609 | public function testLoadContentInfoListSkipsNotFoundItems() |
|
| 610 | { |
|
| 611 | $repository = $this->getRepository(); |
|
| 612 | ||
| 613 | $nonExistentContentId = $this->generateId('object', self::DB_INT_MAX); |
|
| 614 | $contentService = $repository->getContentService(); |
|
| 615 | $list = $contentService->loadContentInfoList([$nonExistentContentId]); |
|
| 616 | ||
| 617 | $this->assertCount(0, $list); |
|
| 618 | } |
|
| 619 | ||
| 620 | /** |
|
| 621 | * Test for the loadContentInfoByRemoteId() method. |
|
| @@ 698-719 (lines=22) @@ | ||
| 695 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo |
|
| 696 | * @group user |
|
| 697 | */ |
|
| 698 | public function testLoadVersionInfo() |
|
| 699 | { |
|
| 700 | $repository = $this->getRepository(); |
|
| 701 | ||
| 702 | $mediaFolderId = $this->generateId('object', 41); |
|
| 703 | /* BEGIN: Use Case */ |
|
| 704 | // $mediaFolderId contains the ID of the "Media" folder |
|
| 705 | ||
| 706 | $contentService = $repository->getContentService(); |
|
| 707 | ||
| 708 | // Load the ContentInfo for "Media" folder |
|
| 709 | $contentInfo = $contentService->loadContentInfo($mediaFolderId); |
|
| 710 | ||
| 711 | // Now load the current version info of the "Media" folder |
|
| 712 | $versionInfo = $contentService->loadVersionInfo($contentInfo); |
|
| 713 | /* END: Use Case */ |
|
| 714 | ||
| 715 | $this->assertInstanceOf( |
|
| 716 | '\\eZ\\Publish\\API\\Repository\\Values\\Content\\VersionInfo', |
|
| 717 | $versionInfo |
|
| 718 | ); |
|
| 719 | } |
|
| 720 | ||
| 721 | /** |
|
| 722 | * Test for the loadVersionInfoById() method. |
|
| @@ 726-746 (lines=21) @@ | ||
| 723 | * |
|
| 724 | * @see \eZ\Publish\API\Repository\ContentService::loadVersionInfoById() |
|
| 725 | */ |
|
| 726 | public function testLoadVersionInfoById() |
|
| 727 | { |
|
| 728 | $repository = $this->getRepository(); |
|
| 729 | ||
| 730 | $mediaFolderId = $this->generateId('object', 41); |
|
| 731 | /* BEGIN: Use Case */ |
|
| 732 | // $mediaFolderId contains the ID of the "Media" folder |
|
| 733 | ||
| 734 | $contentService = $repository->getContentService(); |
|
| 735 | ||
| 736 | // Load the VersionInfo for "Media" folder |
|
| 737 | $versionInfo = $contentService->loadVersionInfoById($mediaFolderId); |
|
| 738 | /* END: Use Case */ |
|
| 739 | ||
| 740 | $this->assertInstanceOf( |
|
| 741 | '\\eZ\\Publish\\API\\Repository\\Values\\Content\\VersionInfo', |
|
| 742 | $versionInfo |
|
| 743 | ); |
|
| 744 | ||
| 745 | return $versionInfo; |
|
| 746 | } |
|
| 747 | ||
| 748 | /** |
|
| 749 | * Test for the returned value of the loadVersionInfoById() method. |
|
| @@ 809-830 (lines=22) @@ | ||
| 806 | * @see \eZ\Publish\API\Repository\ContentService::loadContentByContentInfo() |
|
| 807 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo |
|
| 808 | */ |
|
| 809 | public function testLoadContentByContentInfo() |
|
| 810 | { |
|
| 811 | $repository = $this->getRepository(); |
|
| 812 | ||
| 813 | $mediaFolderId = $this->generateId('object', 41); |
|
| 814 | /* BEGIN: Use Case */ |
|
| 815 | // $mediaFolderId contains the ID of the "Media" folder |
|
| 816 | ||
| 817 | $contentService = $repository->getContentService(); |
|
| 818 | ||
| 819 | // Load the ContentInfo for "Media" folder |
|
| 820 | $contentInfo = $contentService->loadContentInfo($mediaFolderId); |
|
| 821 | ||
| 822 | // Now load the current content version for the info instance |
|
| 823 | $content = $contentService->loadContentByContentInfo($contentInfo); |
|
| 824 | /* END: Use Case */ |
|
| 825 | ||
| 826 | $this->assertInstanceOf( |
|
| 827 | '\\eZ\\Publish\\API\\Repository\\Values\\Content\\Content', |
|
| 828 | $content |
|
| 829 | ); |
|
| 830 | } |
|
| 831 | ||
| 832 | /** |
|
| 833 | * Test for the loadContentByVersionInfo() method. |
|
| @@ 871-889 (lines=19) @@ | ||
| 868 | * @group user |
|
| 869 | * @group field-type |
|
| 870 | */ |
|
| 871 | public function testLoadContent() |
|
| 872 | { |
|
| 873 | $repository = $this->getRepository(); |
|
| 874 | ||
| 875 | $mediaFolderId = $this->generateId('object', 41); |
|
| 876 | /* BEGIN: Use Case */ |
|
| 877 | // $mediaFolderId contains the ID of the "Media" folder |
|
| 878 | ||
| 879 | $contentService = $repository->getContentService(); |
|
| 880 | ||
| 881 | // Load the Content for "Media" folder, any language and current version |
|
| 882 | $content = $contentService->loadContent($mediaFolderId); |
|
| 883 | /* END: Use Case */ |
|
| 884 | ||
| 885 | $this->assertInstanceOf( |
|
| 886 | '\\eZ\\Publish\\API\\Repository\\Values\\Content\\Content', |
|
| 887 | $content |
|
| 888 | ); |
|
| 889 | } |
|
| 890 | ||
| 891 | /** |
|
| 892 | * Test for the loadContent() method. |
|