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

@@ 3277-3298 (lines=22) @@
3274
     * @see \eZ\Publish\API\Repository\ContentService::createContentDraft()
3275
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testAddRelationSetsExpectedRelations
3276
     */
3277
    public function testCreateContentDraftWithRelations()
3278
    {
3279
        $repository = $this->getRepository();
3280
3281
        $contentService = $repository->getContentService();
3282
3283
        // RemoteId of the "Media" content of an eZ Publish demo installation
3284
        $mediaRemoteId = 'a6e35cbcb7cd6ae4b691f3eee30cd262';
3285
        $draft = $this->createContentDraftVersion1();
3286
        $media = $contentService->loadContentInfoByRemoteId($mediaRemoteId);
3287
3288
        // Create relation between new content object and "Media" page
3289
        $contentService->addRelation(
3290
            $draft->getVersionInfo(),
3291
            $media
3292
        );
3293
3294
        $content = $contentService->publishVersion($draft->versionInfo);
3295
        $newDraft = $contentService->createContentDraft($content->contentInfo);
3296
3297
        return $contentService->loadRelations($newDraft->getVersionInfo());
3298
    }
3299
3300
    /**
3301
     * Test for the createContentDraft() method.
@@ 3859-3892 (lines=34) @@
3856
     * @expectedException \eZ\Publish\API\Repository\Exceptions\BadStateException
3857
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testDeleteRelation
3858
     */
3859
    public function testDeleteRelationThrowsBadStateException()
3860
    {
3861
        $repository = $this->getRepository();
3862
3863
        $contentService = $repository->getContentService();
3864
3865
        /* BEGIN: Use Case */
3866
        // RemoteId of the "Media" page of an eZ Publish demo installation
3867
        $mediaRemoteId = 'a6e35cbcb7cd6ae4b691f3eee30cd262';
3868
3869
        $content = $this->createContentVersion1();
3870
3871
        // Load the destination object
3872
        $media = $contentService->loadContentInfoByRemoteId($mediaRemoteId);
3873
3874
        // Create a new draft
3875
        $draftVersion2 = $contentService->createContentDraft($content->contentInfo);
3876
3877
        // Add a relation
3878
        $contentService->addRelation($draftVersion2->getVersionInfo(), $media);
3879
3880
        // Publish new version
3881
        $contentVersion2 = $contentService->publishVersion(
3882
            $draftVersion2->getVersionInfo()
3883
        );
3884
3885
        // This call will fail with a "BadStateException", because content is
3886
        // published and not a draft.
3887
        $contentService->deleteRelation(
3888
            $contentVersion2->getVersionInfo(),
3889
            $media
3890
        );
3891
        /* END: Use Case */
3892
    }
3893
3894
    /**
3895
     * Test for the deleteRelation() method.