Code Duplication    Length = 21-24 lines in 3 locations

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

@@ 925-945 (lines=21) @@
922
     * @see \eZ\Publish\API\Repository\ContentService::loadRelations()
923
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadRelations
924
     */
925
    public function testLoadRelationsThrowsUnauthorizedException()
926
    {
927
        /* BEGIN: Use Case */
928
        $mediaEditor = $this->createMediaUserVersion1();
929
930
        $setupRemoteId = '241d538ce310074e602f29f49e44e938';
931
932
        $versionInfo = $this->contentService->loadVersionInfo(
933
            $this->contentService->loadContentInfoByRemoteId(
934
                $setupRemoteId
935
            )
936
        );
937
938
        $this->permissionResolver->setCurrentUserReference($mediaEditor);
939
940
        $this->expectException(UnauthorizedException::class);
941
        $this->expectExceptionMessageRegExp('/\'read\' \'content\'/');
942
943
        $this->contentService->loadRelations($versionInfo);
944
        /* END: Use Case */
945
    }
946
947
    /**
948
     * Test for the loadRelations() method.
@@ 997-1018 (lines=22) @@
994
     * @see \eZ\Publish\API\Repository\ContentService::addRelation()
995
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testAddRelation
996
     */
997
    public function testAddRelationThrowsUnauthorizedException()
998
    {
999
        /* BEGIN: Use Case */
1000
        $mediaRemoteId = 'a6e35cbcb7cd6ae4b691f3eee30cd262';
1001
1002
        $draft = $this->createContentDraftVersion1();
1003
1004
        $versionInfo = $draft->getVersionInfo();
1005
1006
        $media = $this->contentService->loadContentInfoByRemoteId($mediaRemoteId);
1007
1008
        $this->permissionResolver->setCurrentUserReference($this->anonymousUser);
1009
1010
        $this->expectException(UnauthorizedException::class);
1011
        $this->expectExceptionMessageRegExp('/\'versionread\' \'content\'/');
1012
1013
        $this->contentService->addRelation(
1014
            $versionInfo,
1015
            $media
1016
        );
1017
        /* END: Use Case */
1018
    }
1019
1020
    /**
1021
     * Test for the deleteRelation() method.

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

@@ 3328-3351 (lines=24) @@
3325
     * @see \eZ\Publish\API\Repository\ContentService::addRelation()
3326
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testPublishVersionFromContentDraft
3327
     */
3328
    public function testAddRelation()
3329
    {
3330
        /* BEGIN: Use Case */
3331
        // RemoteId of the "Media" content of an eZ Publish demo installation
3332
        $mediaRemoteId = 'a6e35cbcb7cd6ae4b691f3eee30cd262';
3333
3334
        $draft = $this->createContentDraftVersion1();
3335
3336
        $media = $this->contentService->loadContentInfoByRemoteId($mediaRemoteId);
3337
3338
        // Create relation between new content object and "Media" page
3339
        $relation = $this->contentService->addRelation(
3340
            $draft->getVersionInfo(),
3341
            $media
3342
        );
3343
        /* END: Use Case */
3344
3345
        $this->assertInstanceOf(
3346
            '\\eZ\\Publish\\API\\Repository\\Values\\Content\\Relation',
3347
            $relation
3348
        );
3349
3350
        return $this->contentService->loadRelations($draft->getVersionInfo());
3351
    }
3352
3353
    /**
3354
     * Test for the addRelation() method.