Code Duplication    Length = 22-34 lines in 3 locations

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

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