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

@@ 2880-2901 (lines=22) @@
2877
     * @see \eZ\Publish\API\Repository\ContentService::createContentDraft()
2878
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testAddRelationSetsExpectedRelations
2879
     */
2880
    public function testCreateContentDraftWithRelations()
2881
    {
2882
        $repository = $this->getRepository();
2883
2884
        $contentService = $repository->getContentService();
2885
2886
        // RemoteId of the "Media" content of an eZ Publish demo installation
2887
        $mediaRemoteId = 'a6e35cbcb7cd6ae4b691f3eee30cd262';
2888
        $draft = $this->createContentDraftVersion1();
2889
        $media = $contentService->loadContentInfoByRemoteId($mediaRemoteId);
2890
2891
        // Create relation between new content object and "Media" page
2892
        $contentService->addRelation(
2893
            $draft->getVersionInfo(),
2894
            $media
2895
        );
2896
2897
        $content = $contentService->publishVersion($draft->versionInfo);
2898
        $newDraft = $contentService->createContentDraft($content->contentInfo);
2899
2900
        return $contentService->loadRelations($newDraft->getVersionInfo());
2901
    }
2902
2903
    /**
2904
     * Test for the createContentDraft() method.
@@ 3462-3495 (lines=34) @@
3459
     * @expectedException \eZ\Publish\API\Repository\Exceptions\BadStateException
3460
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testDeleteRelation
3461
     */
3462
    public function testDeleteRelationThrowsBadStateException()
3463
    {
3464
        $repository = $this->getRepository();
3465
3466
        $contentService = $repository->getContentService();
3467
3468
        /* BEGIN: Use Case */
3469
        // RemoteId of the "Media" page of an eZ Publish demo installation
3470
        $mediaRemoteId = 'a6e35cbcb7cd6ae4b691f3eee30cd262';
3471
3472
        $content = $this->createContentVersion1();
3473
3474
        // Load the destination object
3475
        $media = $contentService->loadContentInfoByRemoteId($mediaRemoteId);
3476
3477
        // Create a new draft
3478
        $draftVersion2 = $contentService->createContentDraft($content->contentInfo);
3479
3480
        // Add a relation
3481
        $contentService->addRelation($draftVersion2->getVersionInfo(), $media);
3482
3483
        // Publish new version
3484
        $contentVersion2 = $contentService->publishVersion(
3485
            $draftVersion2->getVersionInfo()
3486
        );
3487
3488
        // This call will fail with a "BadStateException", because content is
3489
        // published and not a draft.
3490
        $contentService->deleteRelation(
3491
            $contentVersion2->getVersionInfo(),
3492
            $media
3493
        );
3494
        /* END: Use Case */
3495
    }
3496
3497
    /**
3498
     * Test for the deleteRelation() method.