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

@@ 3533-3554 (lines=22) @@
3530
     * @see \eZ\Publish\API\Repository\ContentService::createContentDraft()
3531
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testAddRelationSetsExpectedRelations
3532
     */
3533
    public function testCreateContentDraftWithRelations()
3534
    {
3535
        $repository = $this->getRepository();
3536
3537
        $contentService = $repository->getContentService();
3538
3539
        // RemoteId of the "Media" content of an eZ Publish demo installation
3540
        $mediaRemoteId = 'a6e35cbcb7cd6ae4b691f3eee30cd262';
3541
        $draft = $this->createContentDraftVersion1();
3542
        $media = $contentService->loadContentInfoByRemoteId($mediaRemoteId);
3543
3544
        // Create relation between new content object and "Media" page
3545
        $contentService->addRelation(
3546
            $draft->getVersionInfo(),
3547
            $media
3548
        );
3549
3550
        $content = $contentService->publishVersion($draft->versionInfo);
3551
        $newDraft = $contentService->createContentDraft($content->contentInfo);
3552
3553
        return $contentService->loadRelations($newDraft->getVersionInfo());
3554
    }
3555
3556
    /**
3557
     * Test for the createContentDraft() method.
@@ 4115-4148 (lines=34) @@
4112
     * @expectedException \eZ\Publish\API\Repository\Exceptions\BadStateException
4113
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testDeleteRelation
4114
     */
4115
    public function testDeleteRelationThrowsBadStateException()
4116
    {
4117
        $repository = $this->getRepository();
4118
4119
        $contentService = $repository->getContentService();
4120
4121
        /* BEGIN: Use Case */
4122
        // RemoteId of the "Media" page of an eZ Publish demo installation
4123
        $mediaRemoteId = 'a6e35cbcb7cd6ae4b691f3eee30cd262';
4124
4125
        $content = $this->createContentVersion1();
4126
4127
        // Load the destination object
4128
        $media = $contentService->loadContentInfoByRemoteId($mediaRemoteId);
4129
4130
        // Create a new draft
4131
        $draftVersion2 = $contentService->createContentDraft($content->contentInfo);
4132
4133
        // Add a relation
4134
        $contentService->addRelation($draftVersion2->getVersionInfo(), $media);
4135
4136
        // Publish new version
4137
        $contentVersion2 = $contentService->publishVersion(
4138
            $draftVersion2->getVersionInfo()
4139
        );
4140
4141
        // This call will fail with a "BadStateException", because content is
4142
        // published and not a draft.
4143
        $contentService->deleteRelation(
4144
            $contentVersion2->getVersionInfo(),
4145
            $media
4146
        );
4147
        /* END: Use Case */
4148
    }
4149
4150
    /**
4151
     * Test for the deleteRelation() method.