Code Duplication    Length = 22-34 lines in 3 locations

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

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

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.