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

@@ 3317-3338 (lines=22) @@
3314
     * @see \eZ\Publish\API\Repository\ContentService::createContentDraft()
3315
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testAddRelationSetsExpectedRelations
3316
     */
3317
    public function testCreateContentDraftWithRelations()
3318
    {
3319
        $repository = $this->getRepository();
3320
3321
        $contentService = $repository->getContentService();
3322
3323
        // RemoteId of the "Media" content of an eZ Publish demo installation
3324
        $mediaRemoteId = 'a6e35cbcb7cd6ae4b691f3eee30cd262';
3325
        $draft = $this->createContentDraftVersion1();
3326
        $media = $contentService->loadContentInfoByRemoteId($mediaRemoteId);
3327
3328
        // Create relation between new content object and "Media" page
3329
        $contentService->addRelation(
3330
            $draft->getVersionInfo(),
3331
            $media
3332
        );
3333
3334
        $content = $contentService->publishVersion($draft->versionInfo);
3335
        $newDraft = $contentService->createContentDraft($content->contentInfo);
3336
3337
        return $contentService->loadRelations($newDraft->getVersionInfo());
3338
    }
3339
3340
    /**
3341
     * Test for the createContentDraft() method.
@@ 3899-3932 (lines=34) @@
3896
     * @expectedException \eZ\Publish\API\Repository\Exceptions\BadStateException
3897
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testDeleteRelation
3898
     */
3899
    public function testDeleteRelationThrowsBadStateException()
3900
    {
3901
        $repository = $this->getRepository();
3902
3903
        $contentService = $repository->getContentService();
3904
3905
        /* BEGIN: Use Case */
3906
        // RemoteId of the "Media" page of an eZ Publish demo installation
3907
        $mediaRemoteId = 'a6e35cbcb7cd6ae4b691f3eee30cd262';
3908
3909
        $content = $this->createContentVersion1();
3910
3911
        // Load the destination object
3912
        $media = $contentService->loadContentInfoByRemoteId($mediaRemoteId);
3913
3914
        // Create a new draft
3915
        $draftVersion2 = $contentService->createContentDraft($content->contentInfo);
3916
3917
        // Add a relation
3918
        $contentService->addRelation($draftVersion2->getVersionInfo(), $media);
3919
3920
        // Publish new version
3921
        $contentVersion2 = $contentService->publishVersion(
3922
            $draftVersion2->getVersionInfo()
3923
        );
3924
3925
        // This call will fail with a "BadStateException", because content is
3926
        // published and not a draft.
3927
        $contentService->deleteRelation(
3928
            $contentVersion2->getVersionInfo(),
3929
            $media
3930
        );
3931
        /* END: Use Case */
3932
    }
3933
3934
    /**
3935
     * Test for the deleteRelation() method.