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

@@ 2953-2974 (lines=22) @@
2950
     * @see \eZ\Publish\API\Repository\ContentService::createContentDraft()
2951
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testAddRelationSetsExpectedRelations
2952
     */
2953
    public function testCreateContentDraftWithRelations()
2954
    {
2955
        $repository = $this->getRepository();
2956
2957
        $contentService = $repository->getContentService();
2958
2959
        // RemoteId of the "Media" content of an eZ Publish demo installation
2960
        $mediaRemoteId = 'a6e35cbcb7cd6ae4b691f3eee30cd262';
2961
        $draft = $this->createContentDraftVersion1();
2962
        $media = $contentService->loadContentInfoByRemoteId($mediaRemoteId);
2963
2964
        // Create relation between new content object and "Media" page
2965
        $contentService->addRelation(
2966
            $draft->getVersionInfo(),
2967
            $media
2968
        );
2969
2970
        $content = $contentService->publishVersion($draft->versionInfo);
2971
        $newDraft = $contentService->createContentDraft($content->contentInfo);
2972
2973
        return $contentService->loadRelations($newDraft->getVersionInfo());
2974
    }
2975
2976
    /**
2977
     * Test for the createContentDraft() method.
@@ 3535-3568 (lines=34) @@
3532
     * @expectedException \eZ\Publish\API\Repository\Exceptions\BadStateException
3533
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testDeleteRelation
3534
     */
3535
    public function testDeleteRelationThrowsBadStateException()
3536
    {
3537
        $repository = $this->getRepository();
3538
3539
        $contentService = $repository->getContentService();
3540
3541
        /* BEGIN: Use Case */
3542
        // RemoteId of the "Media" page of an eZ Publish demo installation
3543
        $mediaRemoteId = 'a6e35cbcb7cd6ae4b691f3eee30cd262';
3544
3545
        $content = $this->createContentVersion1();
3546
3547
        // Load the destination object
3548
        $media = $contentService->loadContentInfoByRemoteId($mediaRemoteId);
3549
3550
        // Create a new draft
3551
        $draftVersion2 = $contentService->createContentDraft($content->contentInfo);
3552
3553
        // Add a relation
3554
        $contentService->addRelation($draftVersion2->getVersionInfo(), $media);
3555
3556
        // Publish new version
3557
        $contentVersion2 = $contentService->publishVersion(
3558
            $draftVersion2->getVersionInfo()
3559
        );
3560
3561
        // This call will fail with a "BadStateException", because content is
3562
        // published and not a draft.
3563
        $contentService->deleteRelation(
3564
            $contentVersion2->getVersionInfo(),
3565
            $media
3566
        );
3567
        /* END: Use Case */
3568
    }
3569
3570
    /**
3571
     * Test for the deleteRelation() method.