Code Duplication    Length = 22-34 lines in 3 locations

eZ/Publish/API/Repository/Tests/ContentServiceAuthorizationTest.php 1 location

@@ 829-854 (lines=26) @@
826
     * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
827
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentDraftWithSecondParameter
828
     */
829
    public function testCreateContentDraftThrowsUnauthorizedExceptionWithSecondParameter()
830
    {
831
        $repository = $this->getRepository();
832
833
        $contentService = $repository->getContentService();
834
835
        $anonymousUserId = $this->generateId('user', 10);
836
        /* BEGIN: Use Case */
837
        // $anonymousUserId is the ID of the "Anonymous User" in an eZ Publish
838
        // demo installation
839
        $content = $this->createContentVersion1();
840
841
        // Get ContentInfo and VersionInfo instances
842
        $contentInfo = $content->contentInfo;
843
        $versionInfo = $content->getVersionInfo();
844
845
        // Load the user service
846
        $userService = $repository->getUserService();
847
848
        // Set anonymous user
849
        $repository->setCurrentUser($userService->loadUser($anonymousUserId));
850
851
        // This call will fail with a "UnauthorizedException"
852
        $contentService->createContentDraft($contentInfo, $versionInfo);
853
        /* END: Use Case */
854
    }
855
856
    /**
857
     * Test for the loadContentDrafts() method.

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

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