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

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