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

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