| @@ 2945-2966 (lines=22) @@ | ||
| 2942 | * @see \eZ\Publish\API\Repository\ContentService::createContentDraft() |
|
| 2943 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testAddRelationSetsExpectedRelations |
|
| 2944 | */ |
|
| 2945 | public function testCreateContentDraftWithRelations() |
|
| 2946 | { |
|
| 2947 | $repository = $this->getRepository(); |
|
| 2948 | ||
| 2949 | $contentService = $repository->getContentService(); |
|
| 2950 | ||
| 2951 | // RemoteId of the "Media" content of an eZ Publish demo installation |
|
| 2952 | $mediaRemoteId = 'a6e35cbcb7cd6ae4b691f3eee30cd262'; |
|
| 2953 | $draft = $this->createContentDraftVersion1(); |
|
| 2954 | $media = $contentService->loadContentInfoByRemoteId($mediaRemoteId); |
|
| 2955 | ||
| 2956 | // Create relation between new content object and "Media" page |
|
| 2957 | $contentService->addRelation( |
|
| 2958 | $draft->getVersionInfo(), |
|
| 2959 | $media |
|
| 2960 | ); |
|
| 2961 | ||
| 2962 | $content = $contentService->publishVersion($draft->versionInfo); |
|
| 2963 | $newDraft = $contentService->createContentDraft($content->contentInfo); |
|
| 2964 | ||
| 2965 | return $contentService->loadRelations($newDraft->getVersionInfo()); |
|
| 2966 | } |
|
| 2967 | ||
| 2968 | /** |
|
| 2969 | * Test for the createContentDraft() method. |
|
| @@ 3527-3560 (lines=34) @@ | ||
| 3524 | * @expectedException \eZ\Publish\API\Repository\Exceptions\BadStateException |
|
| 3525 | * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testDeleteRelation |
|
| 3526 | */ |
|
| 3527 | public function testDeleteRelationThrowsBadStateException() |
|
| 3528 | { |
|
| 3529 | $repository = $this->getRepository(); |
|
| 3530 | ||
| 3531 | $contentService = $repository->getContentService(); |
|
| 3532 | ||
| 3533 | /* BEGIN: Use Case */ |
|
| 3534 | // RemoteId of the "Media" page of an eZ Publish demo installation |
|
| 3535 | $mediaRemoteId = 'a6e35cbcb7cd6ae4b691f3eee30cd262'; |
|
| 3536 | ||
| 3537 | $content = $this->createContentVersion1(); |
|
| 3538 | ||
| 3539 | // Load the destination object |
|
| 3540 | $media = $contentService->loadContentInfoByRemoteId($mediaRemoteId); |
|
| 3541 | ||
| 3542 | // Create a new draft |
|
| 3543 | $draftVersion2 = $contentService->createContentDraft($content->contentInfo); |
|
| 3544 | ||
| 3545 | // Add a relation |
|
| 3546 | $contentService->addRelation($draftVersion2->getVersionInfo(), $media); |
|
| 3547 | ||
| 3548 | // Publish new version |
|
| 3549 | $contentVersion2 = $contentService->publishVersion( |
|
| 3550 | $draftVersion2->getVersionInfo() |
|
| 3551 | ); |
|
| 3552 | ||
| 3553 | // This call will fail with a "BadStateException", because content is |
|
| 3554 | // published and not a draft. |
|
| 3555 | $contentService->deleteRelation( |
|
| 3556 | $contentVersion2->getVersionInfo(), |
|
| 3557 | $media |
|
| 3558 | ); |
|
| 3559 | /* END: Use Case */ |
|
| 3560 | } |
|
| 3561 | ||
| 3562 | /** |
|
| 3563 | * Test for the deleteRelation() method. |
|
| @@ 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. |
|