Code Duplication    Length = 19-22 lines in 7 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 5 locations

@@ 486-504 (lines=19) @@
483
     * @see \eZ\Publish\API\Repository\ContentService::loadContentInfo()
484
     * @group user
485
     */
486
    public function testLoadContentInfo()
487
    {
488
        $repository = $this->getRepository();
489
490
        $mediaFolderId = $this->generateId('object', 41);
491
        /* BEGIN: Use Case */
492
        $contentService = $repository->getContentService();
493
494
        // Load the ContentInfo for "Media" folder
495
        $contentInfo = $contentService->loadContentInfo($mediaFolderId);
496
        /* END: Use Case */
497
498
        $this->assertInstanceOf(
499
            '\\eZ\\Publish\\API\\Repository\\Values\\Content\\ContentInfo',
500
            $contentInfo
501
        );
502
503
        return $contentInfo;
504
    }
505
506
    /**
507
     * Test for the returned value of the loadContentInfo() method.
@@ 619-640 (lines=22) @@
616
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
617
     * @group user
618
     */
619
    public function testLoadVersionInfo()
620
    {
621
        $repository = $this->getRepository();
622
623
        $mediaFolderId = $this->generateId('object', 41);
624
        /* BEGIN: Use Case */
625
        // $mediaFolderId contains the ID of the "Media" folder
626
627
        $contentService = $repository->getContentService();
628
629
        // Load the ContentInfo for "Media" folder
630
        $contentInfo = $contentService->loadContentInfo($mediaFolderId);
631
632
        // Now load the current version info of the "Media" folder
633
        $versionInfo = $contentService->loadVersionInfo($contentInfo);
634
        /* END: Use Case */
635
636
        $this->assertInstanceOf(
637
            '\\eZ\\Publish\\API\\Repository\\Values\\Content\\VersionInfo',
638
            $versionInfo
639
        );
640
    }
641
642
    /**
643
     * Test for the loadVersionInfoById() method.
@@ 647-667 (lines=21) @@
644
     *
645
     * @see \eZ\Publish\API\Repository\ContentService::loadVersionInfoById()
646
     */
647
    public function testLoadVersionInfoById()
648
    {
649
        $repository = $this->getRepository();
650
651
        $mediaFolderId = $this->generateId('object', 41);
652
        /* BEGIN: Use Case */
653
        // $mediaFolderId contains the ID of the "Media" folder
654
655
        $contentService = $repository->getContentService();
656
657
        // Load the VersionInfo for "Media" folder
658
        $versionInfo = $contentService->loadVersionInfoById($mediaFolderId);
659
        /* END: Use Case */
660
661
        $this->assertInstanceOf(
662
            '\\eZ\\Publish\\API\\Repository\\Values\\Content\\VersionInfo',
663
            $versionInfo
664
        );
665
666
        return $versionInfo;
667
    }
668
669
    /**
670
     * Test for the returned value of the loadVersionInfoById() method.
@@ 726-747 (lines=22) @@
723
     * @see \eZ\Publish\API\Repository\ContentService::loadContentByContentInfo()
724
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
725
     */
726
    public function testLoadContentByContentInfo()
727
    {
728
        $repository = $this->getRepository();
729
730
        $mediaFolderId = $this->generateId('object', 41);
731
        /* BEGIN: Use Case */
732
        // $mediaFolderId contains the ID of the "Media" folder
733
734
        $contentService = $repository->getContentService();
735
736
        // Load the ContentInfo for "Media" folder
737
        $contentInfo = $contentService->loadContentInfo($mediaFolderId);
738
739
        // Now load the current content version for the info instance
740
        $content = $contentService->loadContentByContentInfo($contentInfo);
741
        /* END: Use Case */
742
743
        $this->assertInstanceOf(
744
            '\\eZ\\Publish\\API\\Repository\\Values\\Content\\Content',
745
            $content
746
        );
747
    }
748
749
    /**
750
     * Test for the loadContentByVersionInfo() method.
@@ 788-806 (lines=19) @@
785
     * @group user
786
     * @group field-type
787
     */
788
    public function testLoadContent()
789
    {
790
        $repository = $this->getRepository();
791
792
        $mediaFolderId = $this->generateId('object', 41);
793
        /* BEGIN: Use Case */
794
        // $mediaFolderId contains the ID of the "Media" folder
795
796
        $contentService = $repository->getContentService();
797
798
        // Load the Content for "Media" folder, any language and current version
799
        $content = $contentService->loadContent($mediaFolderId);
800
        /* END: Use Case */
801
802
        $this->assertInstanceOf(
803
            '\\eZ\\Publish\\API\\Repository\\Values\\Content\\Content',
804
            $content
805
        );
806
    }
807
808
    /**
809
     * Test for the loadContent() method.