Code Duplication    Length = 22-34 lines in 3 locations

eZ/Publish/API/Repository/Tests/ContentServiceAuthorizationTest.php 1 location

@@ 871-896 (lines=26) @@
868
     * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
869
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentDraftWithSecondParameter
870
     */
871
    public function testCreateContentDraftThrowsUnauthorizedExceptionWithSecondParameter()
872
    {
873
        $repository = $this->getRepository();
874
875
        $contentService = $repository->getContentService();
876
877
        $anonymousUserId = $this->generateId('user', 10);
878
        /* BEGIN: Use Case */
879
        // $anonymousUserId is the ID of the "Anonymous User" in an eZ Publish
880
        // demo installation
881
        $content = $this->createContentVersion1();
882
883
        // Get ContentInfo and VersionInfo instances
884
        $contentInfo = $content->contentInfo;
885
        $versionInfo = $content->getVersionInfo();
886
887
        // Load the user service
888
        $userService = $repository->getUserService();
889
890
        // Set anonymous user
891
        $repository->setCurrentUser($userService->loadUser($anonymousUserId));
892
893
        // This call will fail with a "UnauthorizedException"
894
        $contentService->createContentDraft($contentInfo, $versionInfo);
895
        /* END: Use Case */
896
    }
897
898
    /**
899
     * Test for the loadContentDrafts() method.

eZ/Publish/API/Repository/Tests/ContentServiceTest.php 2 locations

@@ 3572-3593 (lines=22) @@
3569
     * @see \eZ\Publish\API\Repository\ContentService::createContentDraft()
3570
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testAddRelationSetsExpectedRelations
3571
     */
3572
    public function testCreateContentDraftWithRelations()
3573
    {
3574
        $repository = $this->getRepository();
3575
3576
        $contentService = $repository->getContentService();
3577
3578
        // RemoteId of the "Media" content of an eZ Publish demo installation
3579
        $mediaRemoteId = 'a6e35cbcb7cd6ae4b691f3eee30cd262';
3580
        $draft = $this->createContentDraftVersion1();
3581
        $media = $contentService->loadContentInfoByRemoteId($mediaRemoteId);
3582
3583
        // Create relation between new content object and "Media" page
3584
        $contentService->addRelation(
3585
            $draft->getVersionInfo(),
3586
            $media
3587
        );
3588
3589
        $content = $contentService->publishVersion($draft->versionInfo);
3590
        $newDraft = $contentService->createContentDraft($content->contentInfo);
3591
3592
        return $contentService->loadRelations($newDraft->getVersionInfo());
3593
    }
3594
3595
    /**
3596
     * Test for the createContentDraft() method.
@@ 4154-4187 (lines=34) @@
4151
     * @expectedException \eZ\Publish\API\Repository\Exceptions\BadStateException
4152
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testDeleteRelation
4153
     */
4154
    public function testDeleteRelationThrowsBadStateException()
4155
    {
4156
        $repository = $this->getRepository();
4157
4158
        $contentService = $repository->getContentService();
4159
4160
        /* BEGIN: Use Case */
4161
        // RemoteId of the "Media" page of an eZ Publish demo installation
4162
        $mediaRemoteId = 'a6e35cbcb7cd6ae4b691f3eee30cd262';
4163
4164
        $content = $this->createContentVersion1();
4165
4166
        // Load the destination object
4167
        $media = $contentService->loadContentInfoByRemoteId($mediaRemoteId);
4168
4169
        // Create a new draft
4170
        $draftVersion2 = $contentService->createContentDraft($content->contentInfo);
4171
4172
        // Add a relation
4173
        $contentService->addRelation($draftVersion2->getVersionInfo(), $media);
4174
4175
        // Publish new version
4176
        $contentVersion2 = $contentService->publishVersion(
4177
            $draftVersion2->getVersionInfo()
4178
        );
4179
4180
        // This call will fail with a "BadStateException", because content is
4181
        // published and not a draft.
4182
        $contentService->deleteRelation(
4183
            $contentVersion2->getVersionInfo(),
4184
            $media
4185
        );
4186
        /* END: Use Case */
4187
    }
4188
4189
    /**
4190
     * Test for the deleteRelation() method.