Code Duplication    Length = 22-34 lines in 3 locations

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

@@ 827-852 (lines=26) @@
824
     * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
825
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentDraftWithSecondParameter
826
     */
827
    public function testCreateContentDraftThrowsUnauthorizedExceptionWithSecondParameter()
828
    {
829
        $repository = $this->getRepository();
830
831
        $contentService = $repository->getContentService();
832
833
        $anonymousUserId = $this->generateId('user', 10);
834
        /* BEGIN: Use Case */
835
        // $anonymousUserId is the ID of the "Anonymous User" in an eZ Publish
836
        // demo installation
837
        $content = $this->createContentVersion1();
838
839
        // Get ContentInfo and VersionInfo instances
840
        $contentInfo = $content->contentInfo;
841
        $versionInfo = $content->getVersionInfo();
842
843
        // Load the user service
844
        $userService = $repository->getUserService();
845
846
        // Set anonymous user
847
        $repository->setCurrentUser($userService->loadUser($anonymousUserId));
848
849
        // This call will fail with a "UnauthorizedException"
850
        $contentService->createContentDraft($contentInfo, $versionInfo);
851
        /* END: Use Case */
852
    }
853
854
    /**
855
     * Test for the loadContentDrafts() method.

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.