| @@ 828-853 (lines=26) @@ | ||
| 825 | * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
|
| 826 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentDraftWithSecondParameter |
|
| 827 | */ |
|
| 828 | public function testCreateContentDraftThrowsUnauthorizedExceptionWithSecondParameter() |
|
| 829 | { |
|
| 830 | $repository = $this->getRepository(); |
|
| 831 | ||
| 832 | $contentService = $repository->getContentService(); |
|
| 833 | ||
| 834 | $anonymousUserId = $this->generateId('user', 10); |
|
| 835 | /* BEGIN: Use Case */ |
|
| 836 | // $anonymousUserId is the ID of the "Anonymous User" in an eZ Publish |
|
| 837 | // demo installation |
|
| 838 | $content = $this->createContentVersion1(); |
|
| 839 | ||
| 840 | // Get ContentInfo and VersionInfo instances |
|
| 841 | $contentInfo = $content->contentInfo; |
|
| 842 | $versionInfo = $content->getVersionInfo(); |
|
| 843 | ||
| 844 | // Load the user service |
|
| 845 | $userService = $repository->getUserService(); |
|
| 846 | ||
| 847 | // Set anonymous user |
|
| 848 | $repository->setCurrentUser($userService->loadUser($anonymousUserId)); |
|
| 849 | ||
| 850 | // This call will fail with a "UnauthorizedException" |
|
| 851 | $contentService->createContentDraft($contentInfo, $versionInfo); |
|
| 852 | /* END: Use Case */ |
|
| 853 | } |
|
| 854 | ||
| 855 | /** |
|
| 856 | * Test for the loadContentDrafts() method. |
|
| @@ 3362-3383 (lines=22) @@ | ||
| 3359 | * @see \eZ\Publish\API\Repository\ContentService::createContentDraft() |
|
| 3360 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testAddRelationSetsExpectedRelations |
|
| 3361 | */ |
|
| 3362 | public function testCreateContentDraftWithRelations() |
|
| 3363 | { |
|
| 3364 | $repository = $this->getRepository(); |
|
| 3365 | ||
| 3366 | $contentService = $repository->getContentService(); |
|
| 3367 | ||
| 3368 | // RemoteId of the "Media" content of an eZ Publish demo installation |
|
| 3369 | $mediaRemoteId = 'a6e35cbcb7cd6ae4b691f3eee30cd262'; |
|
| 3370 | $draft = $this->createContentDraftVersion1(); |
|
| 3371 | $media = $contentService->loadContentInfoByRemoteId($mediaRemoteId); |
|
| 3372 | ||
| 3373 | // Create relation between new content object and "Media" page |
|
| 3374 | $contentService->addRelation( |
|
| 3375 | $draft->getVersionInfo(), |
|
| 3376 | $media |
|
| 3377 | ); |
|
| 3378 | ||
| 3379 | $content = $contentService->publishVersion($draft->versionInfo); |
|
| 3380 | $newDraft = $contentService->createContentDraft($content->contentInfo); |
|
| 3381 | ||
| 3382 | return $contentService->loadRelations($newDraft->getVersionInfo()); |
|
| 3383 | } |
|
| 3384 | ||
| 3385 | /** |
|
| 3386 | * Test for the createContentDraft() method. |
|
| @@ 3944-3977 (lines=34) @@ | ||
| 3941 | * @expectedException \eZ\Publish\API\Repository\Exceptions\BadStateException |
|
| 3942 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testDeleteRelation |
|
| 3943 | */ |
|
| 3944 | public function testDeleteRelationThrowsBadStateException() |
|
| 3945 | { |
|
| 3946 | $repository = $this->getRepository(); |
|
| 3947 | ||
| 3948 | $contentService = $repository->getContentService(); |
|
| 3949 | ||
| 3950 | /* BEGIN: Use Case */ |
|
| 3951 | // RemoteId of the "Media" page of an eZ Publish demo installation |
|
| 3952 | $mediaRemoteId = 'a6e35cbcb7cd6ae4b691f3eee30cd262'; |
|
| 3953 | ||
| 3954 | $content = $this->createContentVersion1(); |
|
| 3955 | ||
| 3956 | // Load the destination object |
|
| 3957 | $media = $contentService->loadContentInfoByRemoteId($mediaRemoteId); |
|
| 3958 | ||
| 3959 | // Create a new draft |
|
| 3960 | $draftVersion2 = $contentService->createContentDraft($content->contentInfo); |
|
| 3961 | ||
| 3962 | // Add a relation |
|
| 3963 | $contentService->addRelation($draftVersion2->getVersionInfo(), $media); |
|
| 3964 | ||
| 3965 | // Publish new version |
|
| 3966 | $contentVersion2 = $contentService->publishVersion( |
|
| 3967 | $draftVersion2->getVersionInfo() |
|
| 3968 | ); |
|
| 3969 | ||
| 3970 | // This call will fail with a "BadStateException", because content is |
|
| 3971 | // published and not a draft. |
|
| 3972 | $contentService->deleteRelation( |
|
| 3973 | $contentVersion2->getVersionInfo(), |
|
| 3974 | $media |
|
| 3975 | ); |
|
| 3976 | /* END: Use Case */ |
|
| 3977 | } |
|
| 3978 | ||
| 3979 | /** |
|
| 3980 | * Test for the deleteRelation() method. |
|