Code Duplication    Length = 22-34 lines in 3 locations

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.

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

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