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

@@ 2896-2917 (lines=22) @@
2893
     * @see \eZ\Publish\API\Repository\ContentService::createContentDraft()
2894
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testAddRelationSetsExpectedRelations
2895
     */
2896
    public function testCreateContentDraftWithRelations()
2897
    {
2898
        $repository = $this->getRepository();
2899
2900
        $contentService = $repository->getContentService();
2901
2902
        // RemoteId of the "Media" content of an eZ Publish demo installation
2903
        $mediaRemoteId = 'a6e35cbcb7cd6ae4b691f3eee30cd262';
2904
        $draft = $this->createContentDraftVersion1();
2905
        $media = $contentService->loadContentInfoByRemoteId($mediaRemoteId);
2906
2907
        // Create relation between new content object and "Media" page
2908
        $contentService->addRelation(
2909
            $draft->getVersionInfo(),
2910
            $media
2911
        );
2912
2913
        $content = $contentService->publishVersion($draft->versionInfo);
2914
        $newDraft = $contentService->createContentDraft($content->contentInfo);
2915
2916
        return $contentService->loadRelations($newDraft->getVersionInfo());
2917
    }
2918
2919
    /**
2920
     * Test for the createContentDraft() method.
@@ 3478-3511 (lines=34) @@
3475
     * @expectedException \eZ\Publish\API\Repository\Exceptions\BadStateException
3476
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testDeleteRelation
3477
     */
3478
    public function testDeleteRelationThrowsBadStateException()
3479
    {
3480
        $repository = $this->getRepository();
3481
3482
        $contentService = $repository->getContentService();
3483
3484
        /* BEGIN: Use Case */
3485
        // RemoteId of the "Media" page of an eZ Publish demo installation
3486
        $mediaRemoteId = 'a6e35cbcb7cd6ae4b691f3eee30cd262';
3487
3488
        $content = $this->createContentVersion1();
3489
3490
        // Load the destination object
3491
        $media = $contentService->loadContentInfoByRemoteId($mediaRemoteId);
3492
3493
        // Create a new draft
3494
        $draftVersion2 = $contentService->createContentDraft($content->contentInfo);
3495
3496
        // Add a relation
3497
        $contentService->addRelation($draftVersion2->getVersionInfo(), $media);
3498
3499
        // Publish new version
3500
        $contentVersion2 = $contentService->publishVersion(
3501
            $draftVersion2->getVersionInfo()
3502
        );
3503
3504
        // This call will fail with a "BadStateException", because content is
3505
        // published and not a draft.
3506
        $contentService->deleteRelation(
3507
            $contentVersion2->getVersionInfo(),
3508
            $media
3509
        );
3510
        /* END: Use Case */
3511
    }
3512
3513
    /**
3514
     * Test for the deleteRelation() method.