| @@ 827-852 (lines=26) @@ | ||
| 824 | * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
|
| 825 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentDraftWithSecondParameter |
|
| 826 | */ |
|
| 827 | public function testCreateContentDraftThrowsUnauthorizedExceptionWithSecondParameter() |
|
| 828 | { |
|
| 829 | $repository = $this->getRepository(); |
|
| 830 | ||
| 831 | $contentService = $repository->getContentService(); |
|
| 832 | ||
| 833 | $anonymousUserId = $this->generateId('user', 10); |
|
| 834 | /* BEGIN: Use Case */ |
|
| 835 | // $anonymousUserId is the ID of the "Anonymous User" in an eZ Publish |
|
| 836 | // demo installation |
|
| 837 | $content = $this->createContentVersion1(); |
|
| 838 | ||
| 839 | // Get ContentInfo and VersionInfo instances |
|
| 840 | $contentInfo = $content->contentInfo; |
|
| 841 | $versionInfo = $content->getVersionInfo(); |
|
| 842 | ||
| 843 | // Load the user service |
|
| 844 | $userService = $repository->getUserService(); |
|
| 845 | ||
| 846 | // Set anonymous user |
|
| 847 | $repository->setCurrentUser($userService->loadUser($anonymousUserId)); |
|
| 848 | ||
| 849 | // This call will fail with a "UnauthorizedException" |
|
| 850 | $contentService->createContentDraft($contentInfo, $versionInfo); |
|
| 851 | /* END: Use Case */ |
|
| 852 | } |
|
| 853 | ||
| 854 | /** |
|
| 855 | * Test for the loadContentDrafts() method. |
|
| @@ 3318-3339 (lines=22) @@ | ||
| 3315 | * @see \eZ\Publish\API\Repository\ContentService::createContentDraft() |
|
| 3316 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testAddRelationSetsExpectedRelations |
|
| 3317 | */ |
|
| 3318 | public function testCreateContentDraftWithRelations() |
|
| 3319 | { |
|
| 3320 | $repository = $this->getRepository(); |
|
| 3321 | ||
| 3322 | $contentService = $repository->getContentService(); |
|
| 3323 | ||
| 3324 | // RemoteId of the "Media" content of an eZ Publish demo installation |
|
| 3325 | $mediaRemoteId = 'a6e35cbcb7cd6ae4b691f3eee30cd262'; |
|
| 3326 | $draft = $this->createContentDraftVersion1(); |
|
| 3327 | $media = $contentService->loadContentInfoByRemoteId($mediaRemoteId); |
|
| 3328 | ||
| 3329 | // Create relation between new content object and "Media" page |
|
| 3330 | $contentService->addRelation( |
|
| 3331 | $draft->getVersionInfo(), |
|
| 3332 | $media |
|
| 3333 | ); |
|
| 3334 | ||
| 3335 | $content = $contentService->publishVersion($draft->versionInfo); |
|
| 3336 | $newDraft = $contentService->createContentDraft($content->contentInfo); |
|
| 3337 | ||
| 3338 | return $contentService->loadRelations($newDraft->getVersionInfo()); |
|
| 3339 | } |
|
| 3340 | ||
| 3341 | /** |
|
| 3342 | * Test for the createContentDraft() method. |
|
| @@ 3900-3933 (lines=34) @@ | ||
| 3897 | * @expectedException \eZ\Publish\API\Repository\Exceptions\BadStateException |
|
| 3898 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testDeleteRelation |
|
| 3899 | */ |
|
| 3900 | public function testDeleteRelationThrowsBadStateException() |
|
| 3901 | { |
|
| 3902 | $repository = $this->getRepository(); |
|
| 3903 | ||
| 3904 | $contentService = $repository->getContentService(); |
|
| 3905 | ||
| 3906 | /* BEGIN: Use Case */ |
|
| 3907 | // RemoteId of the "Media" page of an eZ Publish demo installation |
|
| 3908 | $mediaRemoteId = 'a6e35cbcb7cd6ae4b691f3eee30cd262'; |
|
| 3909 | ||
| 3910 | $content = $this->createContentVersion1(); |
|
| 3911 | ||
| 3912 | // Load the destination object |
|
| 3913 | $media = $contentService->loadContentInfoByRemoteId($mediaRemoteId); |
|
| 3914 | ||
| 3915 | // Create a new draft |
|
| 3916 | $draftVersion2 = $contentService->createContentDraft($content->contentInfo); |
|
| 3917 | ||
| 3918 | // Add a relation |
|
| 3919 | $contentService->addRelation($draftVersion2->getVersionInfo(), $media); |
|
| 3920 | ||
| 3921 | // Publish new version |
|
| 3922 | $contentVersion2 = $contentService->publishVersion( |
|
| 3923 | $draftVersion2->getVersionInfo() |
|
| 3924 | ); |
|
| 3925 | ||
| 3926 | // This call will fail with a "BadStateException", because content is |
|
| 3927 | // published and not a draft. |
|
| 3928 | $contentService->deleteRelation( |
|
| 3929 | $contentVersion2->getVersionInfo(), |
|
| 3930 | $media |
|
| 3931 | ); |
|
| 3932 | /* END: Use Case */ |
|
| 3933 | } |
|
| 3934 | ||
| 3935 | /** |
|
| 3936 | * Test for the deleteRelation() method. |
|