Code Duplication    Length = 19-21 lines in 5 locations

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

@@ 212-231 (lines=20) @@
209
     * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
210
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadVersionInfoById
211
     */
212
    public function testLoadVersionInfoByIdThrowsUnauthorizedException()
213
    {
214
        $repository = $this->getRepository();
215
216
        $anonymousUserId = $this->generateId('user', 10);
217
        /* BEGIN: Use Case */
218
        // $anonymousUserId is the ID of the "Anonymous User" in an eZ Publish
219
        // demo installation
220
221
        $contentService = $repository->getContentService();
222
223
        $pseudoEditor = $this->createAnonymousWithEditorRole();
224
225
        // Set restricted editor user
226
        $repository->setCurrentUser($pseudoEditor);
227
228
        // This call will fail with a "UnauthorizedException"
229
        $contentService->loadVersionInfoById($anonymousUserId);
230
        /* END: Use Case */
231
    }
232
233
    /**
234
     * Test for the loadVersionInfoById() method.
@@ 240-259 (lines=20) @@
237
     * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
238
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadVersionInfoByIdWithSecondParameter
239
     */
240
    public function testLoadVersionInfoByIdThrowsUnauthorizedExceptionWithSecondParameter()
241
    {
242
        $repository = $this->getRepository();
243
244
        $anonymousUserId = $this->generateId('user', 10);
245
        /* BEGIN: Use Case */
246
        // $anonymousUserId is the ID of the "Anonymous User" in an eZ Publish
247
        // demo installation
248
249
        $contentService = $repository->getContentService();
250
251
        $pseudoEditor = $this->createAnonymousWithEditorRole();
252
253
        // Set restricted editor user
254
        $repository->setCurrentUser($pseudoEditor);
255
256
        // This call will fail with a "UnauthorizedException"
257
        $contentService->loadVersionInfoById($anonymousUserId, 2);
258
        /* END: Use Case */
259
    }
260
261
    /**
262
     * Test for the loadVersionInfoById() method.

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

@@ 485-503 (lines=19) @@
482
     * @see \eZ\Publish\API\Repository\ContentService::loadContentInfo()
483
     * @group user
484
     */
485
    public function testLoadContentInfo()
486
    {
487
        $repository = $this->getRepository();
488
489
        $mediaFolderId = $this->generateId('object', 41);
490
        /* BEGIN: Use Case */
491
        $contentService = $repository->getContentService();
492
493
        // Load the ContentInfo for "Media" folder
494
        $contentInfo = $contentService->loadContentInfo($mediaFolderId);
495
        /* END: Use Case */
496
497
        $this->assertInstanceOf(
498
            '\\eZ\\Publish\\API\\Repository\\Values\\Content\\ContentInfo',
499
            $contentInfo
500
        );
501
502
        return $contentInfo;
503
    }
504
505
    /**
506
     * Test for the returned value of the loadContentInfo() method.
@@ 646-666 (lines=21) @@
643
     *
644
     * @see \eZ\Publish\API\Repository\ContentService::loadVersionInfoById()
645
     */
646
    public function testLoadVersionInfoById()
647
    {
648
        $repository = $this->getRepository();
649
650
        $mediaFolderId = $this->generateId('object', 41);
651
        /* BEGIN: Use Case */
652
        // $mediaFolderId contains the ID of the "Media" folder
653
654
        $contentService = $repository->getContentService();
655
656
        // Load the VersionInfo for "Media" folder
657
        $versionInfo = $contentService->loadVersionInfoById($mediaFolderId);
658
        /* END: Use Case */
659
660
        $this->assertInstanceOf(
661
            '\\eZ\\Publish\\API\\Repository\\Values\\Content\\VersionInfo',
662
            $versionInfo
663
        );
664
665
        return $versionInfo;
666
    }
667
668
    /**
669
     * Test for the returned value of the loadVersionInfoById() method.
@@ 787-805 (lines=19) @@
784
     * @group user
785
     * @group field-type
786
     */
787
    public function testLoadContent()
788
    {
789
        $repository = $this->getRepository();
790
791
        $mediaFolderId = $this->generateId('object', 41);
792
        /* BEGIN: Use Case */
793
        // $mediaFolderId contains the ID of the "Media" folder
794
795
        $contentService = $repository->getContentService();
796
797
        // Load the Content for "Media" folder, any language and current version
798
        $content = $contentService->loadContent($mediaFolderId);
799
        /* END: Use Case */
800
801
        $this->assertInstanceOf(
802
            '\\eZ\\Publish\\API\\Repository\\Values\\Content\\Content',
803
            $content
804
        );
805
    }
806
807
    /**
808
     * Test for the loadContent() method.