Code Duplication    Length = 22-34 lines in 3 locations

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

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

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.