Code Duplication    Length = 22-34 lines in 3 locations

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

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

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

@@ 3000-3021 (lines=22) @@
2997
     * @see \eZ\Publish\API\Repository\ContentService::createContentDraft()
2998
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testAddRelationSetsExpectedRelations
2999
     */
3000
    public function testCreateContentDraftWithRelations()
3001
    {
3002
        $repository = $this->getRepository();
3003
3004
        $contentService = $repository->getContentService();
3005
3006
        // RemoteId of the "Media" content of an eZ Publish demo installation
3007
        $mediaRemoteId = 'a6e35cbcb7cd6ae4b691f3eee30cd262';
3008
        $draft = $this->createContentDraftVersion1();
3009
        $media = $contentService->loadContentInfoByRemoteId($mediaRemoteId);
3010
3011
        // Create relation between new content object and "Media" page
3012
        $contentService->addRelation(
3013
            $draft->getVersionInfo(),
3014
            $media
3015
        );
3016
3017
        $content = $contentService->publishVersion($draft->versionInfo);
3018
        $newDraft = $contentService->createContentDraft($content->contentInfo);
3019
3020
        return $contentService->loadRelations($newDraft->getVersionInfo());
3021
    }
3022
3023
    /**
3024
     * Test for the createContentDraft() method.
@@ 3582-3615 (lines=34) @@
3579
     * @expectedException \eZ\Publish\API\Repository\Exceptions\BadStateException
3580
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testDeleteRelation
3581
     */
3582
    public function testDeleteRelationThrowsBadStateException()
3583
    {
3584
        $repository = $this->getRepository();
3585
3586
        $contentService = $repository->getContentService();
3587
3588
        /* BEGIN: Use Case */
3589
        // RemoteId of the "Media" page of an eZ Publish demo installation
3590
        $mediaRemoteId = 'a6e35cbcb7cd6ae4b691f3eee30cd262';
3591
3592
        $content = $this->createContentVersion1();
3593
3594
        // Load the destination object
3595
        $media = $contentService->loadContentInfoByRemoteId($mediaRemoteId);
3596
3597
        // Create a new draft
3598
        $draftVersion2 = $contentService->createContentDraft($content->contentInfo);
3599
3600
        // Add a relation
3601
        $contentService->addRelation($draftVersion2->getVersionInfo(), $media);
3602
3603
        // Publish new version
3604
        $contentVersion2 = $contentService->publishVersion(
3605
            $draftVersion2->getVersionInfo()
3606
        );
3607
3608
        // This call will fail with a "BadStateException", because content is
3609
        // published and not a draft.
3610
        $contentService->deleteRelation(
3611
            $contentVersion2->getVersionInfo(),
3612
            $media
3613
        );
3614
        /* END: Use Case */
3615
    }
3616
3617
    /**
3618
     * Test for the deleteRelation() method.