| @@ 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. |
|
| @@ 3471-3492 (lines=22) @@ | ||
| 3468 | * @see \eZ\Publish\API\Repository\ContentService::createContentDraft() |
|
| 3469 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testAddRelationSetsExpectedRelations |
|
| 3470 | */ |
|
| 3471 | public function testCreateContentDraftWithRelations() |
|
| 3472 | { |
|
| 3473 | $repository = $this->getRepository(); |
|
| 3474 | ||
| 3475 | $contentService = $repository->getContentService(); |
|
| 3476 | ||
| 3477 | // RemoteId of the "Media" content of an eZ Publish demo installation |
|
| 3478 | $mediaRemoteId = 'a6e35cbcb7cd6ae4b691f3eee30cd262'; |
|
| 3479 | $draft = $this->createContentDraftVersion1(); |
|
| 3480 | $media = $contentService->loadContentInfoByRemoteId($mediaRemoteId); |
|
| 3481 | ||
| 3482 | // Create relation between new content object and "Media" page |
|
| 3483 | $contentService->addRelation( |
|
| 3484 | $draft->getVersionInfo(), |
|
| 3485 | $media |
|
| 3486 | ); |
|
| 3487 | ||
| 3488 | $content = $contentService->publishVersion($draft->versionInfo); |
|
| 3489 | $newDraft = $contentService->createContentDraft($content->contentInfo); |
|
| 3490 | ||
| 3491 | return $contentService->loadRelations($newDraft->getVersionInfo()); |
|
| 3492 | } |
|
| 3493 | ||
| 3494 | /** |
|
| 3495 | * Test for the createContentDraft() method. |
|
| @@ 4053-4086 (lines=34) @@ | ||
| 4050 | * @expectedException \eZ\Publish\API\Repository\Exceptions\BadStateException |
|
| 4051 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testDeleteRelation |
|
| 4052 | */ |
|
| 4053 | public function testDeleteRelationThrowsBadStateException() |
|
| 4054 | { |
|
| 4055 | $repository = $this->getRepository(); |
|
| 4056 | ||
| 4057 | $contentService = $repository->getContentService(); |
|
| 4058 | ||
| 4059 | /* BEGIN: Use Case */ |
|
| 4060 | // RemoteId of the "Media" page of an eZ Publish demo installation |
|
| 4061 | $mediaRemoteId = 'a6e35cbcb7cd6ae4b691f3eee30cd262'; |
|
| 4062 | ||
| 4063 | $content = $this->createContentVersion1(); |
|
| 4064 | ||
| 4065 | // Load the destination object |
|
| 4066 | $media = $contentService->loadContentInfoByRemoteId($mediaRemoteId); |
|
| 4067 | ||
| 4068 | // Create a new draft |
|
| 4069 | $draftVersion2 = $contentService->createContentDraft($content->contentInfo); |
|
| 4070 | ||
| 4071 | // Add a relation |
|
| 4072 | $contentService->addRelation($draftVersion2->getVersionInfo(), $media); |
|
| 4073 | ||
| 4074 | // Publish new version |
|
| 4075 | $contentVersion2 = $contentService->publishVersion( |
|
| 4076 | $draftVersion2->getVersionInfo() |
|
| 4077 | ); |
|
| 4078 | ||
| 4079 | // This call will fail with a "BadStateException", because content is |
|
| 4080 | // published and not a draft. |
|
| 4081 | $contentService->deleteRelation( |
|
| 4082 | $contentVersion2->getVersionInfo(), |
|
| 4083 | $media |
|
| 4084 | ); |
|
| 4085 | /* END: Use Case */ |
|
| 4086 | } |
|
| 4087 | ||
| 4088 | /** |
|
| 4089 | * Test for the deleteRelation() method. |
|