| @@ 829-854 (lines=26) @@ | ||
| 826 | * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
|
| 827 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentDraftWithSecondParameter |
|
| 828 | */ |
|
| 829 | public function testCreateContentDraftThrowsUnauthorizedExceptionWithSecondParameter() |
|
| 830 | { |
|
| 831 | $repository = $this->getRepository(); |
|
| 832 | ||
| 833 | $contentService = $repository->getContentService(); |
|
| 834 | ||
| 835 | $anonymousUserId = $this->generateId('user', 10); |
|
| 836 | /* BEGIN: Use Case */ |
|
| 837 | // $anonymousUserId is the ID of the "Anonymous User" in an eZ Publish |
|
| 838 | // demo installation |
|
| 839 | $content = $this->createContentVersion1(); |
|
| 840 | ||
| 841 | // Get ContentInfo and VersionInfo instances |
|
| 842 | $contentInfo = $content->contentInfo; |
|
| 843 | $versionInfo = $content->getVersionInfo(); |
|
| 844 | ||
| 845 | // Load the user service |
|
| 846 | $userService = $repository->getUserService(); |
|
| 847 | ||
| 848 | // Set anonymous user |
|
| 849 | $repository->setCurrentUser($userService->loadUser($anonymousUserId)); |
|
| 850 | ||
| 851 | // This call will fail with a "UnauthorizedException" |
|
| 852 | $contentService->createContentDraft($contentInfo, $versionInfo); |
|
| 853 | /* END: Use Case */ |
|
| 854 | } |
|
| 855 | ||
| 856 | /** |
|
| 857 | * Test for the loadContentDrafts() method. |
|
| @@ 2961-2982 (lines=22) @@ | ||
| 2958 | * @see \eZ\Publish\API\Repository\ContentService::createContentDraft() |
|
| 2959 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testAddRelationSetsExpectedRelations |
|
| 2960 | */ |
|
| 2961 | public function testCreateContentDraftWithRelations() |
|
| 2962 | { |
|
| 2963 | $repository = $this->getRepository(); |
|
| 2964 | ||
| 2965 | $contentService = $repository->getContentService(); |
|
| 2966 | ||
| 2967 | // RemoteId of the "Media" content of an eZ Publish demo installation |
|
| 2968 | $mediaRemoteId = 'a6e35cbcb7cd6ae4b691f3eee30cd262'; |
|
| 2969 | $draft = $this->createContentDraftVersion1(); |
|
| 2970 | $media = $contentService->loadContentInfoByRemoteId($mediaRemoteId); |
|
| 2971 | ||
| 2972 | // Create relation between new content object and "Media" page |
|
| 2973 | $contentService->addRelation( |
|
| 2974 | $draft->getVersionInfo(), |
|
| 2975 | $media |
|
| 2976 | ); |
|
| 2977 | ||
| 2978 | $content = $contentService->publishVersion($draft->versionInfo); |
|
| 2979 | $newDraft = $contentService->createContentDraft($content->contentInfo); |
|
| 2980 | ||
| 2981 | return $contentService->loadRelations($newDraft->getVersionInfo()); |
|
| 2982 | } |
|
| 2983 | ||
| 2984 | /** |
|
| 2985 | * Test for the createContentDraft() method. |
|
| @@ 3543-3576 (lines=34) @@ | ||
| 3540 | * @expectedException \eZ\Publish\API\Repository\Exceptions\BadStateException |
|
| 3541 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testDeleteRelation |
|
| 3542 | */ |
|
| 3543 | public function testDeleteRelationThrowsBadStateException() |
|
| 3544 | { |
|
| 3545 | $repository = $this->getRepository(); |
|
| 3546 | ||
| 3547 | $contentService = $repository->getContentService(); |
|
| 3548 | ||
| 3549 | /* BEGIN: Use Case */ |
|
| 3550 | // RemoteId of the "Media" page of an eZ Publish demo installation |
|
| 3551 | $mediaRemoteId = 'a6e35cbcb7cd6ae4b691f3eee30cd262'; |
|
| 3552 | ||
| 3553 | $content = $this->createContentVersion1(); |
|
| 3554 | ||
| 3555 | // Load the destination object |
|
| 3556 | $media = $contentService->loadContentInfoByRemoteId($mediaRemoteId); |
|
| 3557 | ||
| 3558 | // Create a new draft |
|
| 3559 | $draftVersion2 = $contentService->createContentDraft($content->contentInfo); |
|
| 3560 | ||
| 3561 | // Add a relation |
|
| 3562 | $contentService->addRelation($draftVersion2->getVersionInfo(), $media); |
|
| 3563 | ||
| 3564 | // Publish new version |
|
| 3565 | $contentVersion2 = $contentService->publishVersion( |
|
| 3566 | $draftVersion2->getVersionInfo() |
|
| 3567 | ); |
|
| 3568 | ||
| 3569 | // This call will fail with a "BadStateException", because content is |
|
| 3570 | // published and not a draft. |
|
| 3571 | $contentService->deleteRelation( |
|
| 3572 | $contentVersion2->getVersionInfo(), |
|
| 3573 | $media |
|
| 3574 | ); |
|
| 3575 | /* END: Use Case */ |
|
| 3576 | } |
|
| 3577 | ||
| 3578 | /** |
|
| 3579 | * Test for the deleteRelation() method. |
|