Code Duplication    Length = 22-34 lines in 3 locations

eZ/Publish/API/Repository/Tests/ContentServiceTest.php 2 locations

@@ 3353-3374 (lines=22) @@
3350
     * @see \eZ\Publish\API\Repository\ContentService::createContentDraft()
3351
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testAddRelationSetsExpectedRelations
3352
     */
3353
    public function testCreateContentDraftWithRelations()
3354
    {
3355
        $repository = $this->getRepository();
3356
3357
        $contentService = $repository->getContentService();
3358
3359
        // RemoteId of the "Media" content of an eZ Publish demo installation
3360
        $mediaRemoteId = 'a6e35cbcb7cd6ae4b691f3eee30cd262';
3361
        $draft = $this->createContentDraftVersion1();
3362
        $media = $contentService->loadContentInfoByRemoteId($mediaRemoteId);
3363
3364
        // Create relation between new content object and "Media" page
3365
        $contentService->addRelation(
3366
            $draft->getVersionInfo(),
3367
            $media
3368
        );
3369
3370
        $content = $contentService->publishVersion($draft->versionInfo);
3371
        $newDraft = $contentService->createContentDraft($content->contentInfo);
3372
3373
        return $contentService->loadRelations($newDraft->getVersionInfo());
3374
    }
3375
3376
    /**
3377
     * Test for the createContentDraft() method.
@@ 3935-3968 (lines=34) @@
3932
     * @expectedException \eZ\Publish\API\Repository\Exceptions\BadStateException
3933
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testDeleteRelation
3934
     */
3935
    public function testDeleteRelationThrowsBadStateException()
3936
    {
3937
        $repository = $this->getRepository();
3938
3939
        $contentService = $repository->getContentService();
3940
3941
        /* BEGIN: Use Case */
3942
        // RemoteId of the "Media" page of an eZ Publish demo installation
3943
        $mediaRemoteId = 'a6e35cbcb7cd6ae4b691f3eee30cd262';
3944
3945
        $content = $this->createContentVersion1();
3946
3947
        // Load the destination object
3948
        $media = $contentService->loadContentInfoByRemoteId($mediaRemoteId);
3949
3950
        // Create a new draft
3951
        $draftVersion2 = $contentService->createContentDraft($content->contentInfo);
3952
3953
        // Add a relation
3954
        $contentService->addRelation($draftVersion2->getVersionInfo(), $media);
3955
3956
        // Publish new version
3957
        $contentVersion2 = $contentService->publishVersion(
3958
            $draftVersion2->getVersionInfo()
3959
        );
3960
3961
        // This call will fail with a "BadStateException", because content is
3962
        // published and not a draft.
3963
        $contentService->deleteRelation(
3964
            $contentVersion2->getVersionInfo(),
3965
            $media
3966
        );
3967
        /* END: Use Case */
3968
    }
3969
3970
    /**
3971
     * Test for the deleteRelation() method.

eZ/Publish/API/Repository/Tests/ContentServiceAuthorizationTest.php 1 location

@@ 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.