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

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