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

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