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

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