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

@@ 3417-3438 (lines=22) @@
3414
     * @see \eZ\Publish\API\Repository\ContentService::createContentDraft()
3415
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testAddRelationSetsExpectedRelations
3416
     */
3417
    public function testCreateContentDraftWithRelations()
3418
    {
3419
        $repository = $this->getRepository();
3420
3421
        $contentService = $repository->getContentService();
3422
3423
        // RemoteId of the "Media" content of an eZ Publish demo installation
3424
        $mediaRemoteId = 'a6e35cbcb7cd6ae4b691f3eee30cd262';
3425
        $draft = $this->createContentDraftVersion1();
3426
        $media = $contentService->loadContentInfoByRemoteId($mediaRemoteId);
3427
3428
        // Create relation between new content object and "Media" page
3429
        $contentService->addRelation(
3430
            $draft->getVersionInfo(),
3431
            $media
3432
        );
3433
3434
        $content = $contentService->publishVersion($draft->versionInfo);
3435
        $newDraft = $contentService->createContentDraft($content->contentInfo);
3436
3437
        return $contentService->loadRelations($newDraft->getVersionInfo());
3438
    }
3439
3440
    /**
3441
     * Test for the createContentDraft() method.
@@ 3999-4032 (lines=34) @@
3996
     * @expectedException \eZ\Publish\API\Repository\Exceptions\BadStateException
3997
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testDeleteRelation
3998
     */
3999
    public function testDeleteRelationThrowsBadStateException()
4000
    {
4001
        $repository = $this->getRepository();
4002
4003
        $contentService = $repository->getContentService();
4004
4005
        /* BEGIN: Use Case */
4006
        // RemoteId of the "Media" page of an eZ Publish demo installation
4007
        $mediaRemoteId = 'a6e35cbcb7cd6ae4b691f3eee30cd262';
4008
4009
        $content = $this->createContentVersion1();
4010
4011
        // Load the destination object
4012
        $media = $contentService->loadContentInfoByRemoteId($mediaRemoteId);
4013
4014
        // Create a new draft
4015
        $draftVersion2 = $contentService->createContentDraft($content->contentInfo);
4016
4017
        // Add a relation
4018
        $contentService->addRelation($draftVersion2->getVersionInfo(), $media);
4019
4020
        // Publish new version
4021
        $contentVersion2 = $contentService->publishVersion(
4022
            $draftVersion2->getVersionInfo()
4023
        );
4024
4025
        // This call will fail with a "BadStateException", because content is
4026
        // published and not a draft.
4027
        $contentService->deleteRelation(
4028
            $contentVersion2->getVersionInfo(),
4029
            $media
4030
        );
4031
        /* END: Use Case */
4032
    }
4033
4034
    /**
4035
     * Test for the deleteRelation() method.