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

@@ 3475-3496 (lines=22) @@
3472
     * @see \eZ\Publish\API\Repository\ContentService::createContentDraft()
3473
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testAddRelationSetsExpectedRelations
3474
     */
3475
    public function testCreateContentDraftWithRelations()
3476
    {
3477
        $repository = $this->getRepository();
3478
3479
        $contentService = $repository->getContentService();
3480
3481
        // RemoteId of the "Media" content of an eZ Publish demo installation
3482
        $mediaRemoteId = 'a6e35cbcb7cd6ae4b691f3eee30cd262';
3483
        $draft = $this->createContentDraftVersion1();
3484
        $media = $contentService->loadContentInfoByRemoteId($mediaRemoteId);
3485
3486
        // Create relation between new content object and "Media" page
3487
        $contentService->addRelation(
3488
            $draft->getVersionInfo(),
3489
            $media
3490
        );
3491
3492
        $content = $contentService->publishVersion($draft->versionInfo);
3493
        $newDraft = $contentService->createContentDraft($content->contentInfo);
3494
3495
        return $contentService->loadRelations($newDraft->getVersionInfo());
3496
    }
3497
3498
    /**
3499
     * Test for the createContentDraft() method.
@@ 4057-4090 (lines=34) @@
4054
     * @expectedException \eZ\Publish\API\Repository\Exceptions\BadStateException
4055
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testDeleteRelation
4056
     */
4057
    public function testDeleteRelationThrowsBadStateException()
4058
    {
4059
        $repository = $this->getRepository();
4060
4061
        $contentService = $repository->getContentService();
4062
4063
        /* BEGIN: Use Case */
4064
        // RemoteId of the "Media" page of an eZ Publish demo installation
4065
        $mediaRemoteId = 'a6e35cbcb7cd6ae4b691f3eee30cd262';
4066
4067
        $content = $this->createContentVersion1();
4068
4069
        // Load the destination object
4070
        $media = $contentService->loadContentInfoByRemoteId($mediaRemoteId);
4071
4072
        // Create a new draft
4073
        $draftVersion2 = $contentService->createContentDraft($content->contentInfo);
4074
4075
        // Add a relation
4076
        $contentService->addRelation($draftVersion2->getVersionInfo(), $media);
4077
4078
        // Publish new version
4079
        $contentVersion2 = $contentService->publishVersion(
4080
            $draftVersion2->getVersionInfo()
4081
        );
4082
4083
        // This call will fail with a "BadStateException", because content is
4084
        // published and not a draft.
4085
        $contentService->deleteRelation(
4086
            $contentVersion2->getVersionInfo(),
4087
            $media
4088
        );
4089
        /* END: Use Case */
4090
    }
4091
4092
    /**
4093
     * Test for the deleteRelation() method.