Code Duplication    Length = 19-22 lines in 7 locations

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

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

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

@@ 518-536 (lines=19) @@
515
     * @see \eZ\Publish\API\Repository\ContentService::loadContentInfo()
516
     * @group user
517
     */
518
    public function testLoadContentInfo()
519
    {
520
        $repository = $this->getRepository();
521
522
        $mediaFolderId = $this->generateId('object', 41);
523
        /* BEGIN: Use Case */
524
        $contentService = $repository->getContentService();
525
526
        // Load the ContentInfo for "Media" folder
527
        $contentInfo = $contentService->loadContentInfo($mediaFolderId);
528
        /* END: Use Case */
529
530
        $this->assertInstanceOf(
531
            '\\eZ\\Publish\\API\\Repository\\Values\\Content\\ContentInfo',
532
            $contentInfo
533
        );
534
535
        return $contentInfo;
536
    }
537
538
    /**
539
     * Test for the returned value of the loadContentInfo() method.
@@ 651-672 (lines=22) @@
648
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
649
     * @group user
650
     */
651
    public function testLoadVersionInfo()
652
    {
653
        $repository = $this->getRepository();
654
655
        $mediaFolderId = $this->generateId('object', 41);
656
        /* BEGIN: Use Case */
657
        // $mediaFolderId contains the ID of the "Media" folder
658
659
        $contentService = $repository->getContentService();
660
661
        // Load the ContentInfo for "Media" folder
662
        $contentInfo = $contentService->loadContentInfo($mediaFolderId);
663
664
        // Now load the current version info of the "Media" folder
665
        $versionInfo = $contentService->loadVersionInfo($contentInfo);
666
        /* END: Use Case */
667
668
        $this->assertInstanceOf(
669
            '\\eZ\\Publish\\API\\Repository\\Values\\Content\\VersionInfo',
670
            $versionInfo
671
        );
672
    }
673
674
    /**
675
     * Test for the loadVersionInfoById() method.
@@ 679-699 (lines=21) @@
676
     *
677
     * @see \eZ\Publish\API\Repository\ContentService::loadVersionInfoById()
678
     */
679
    public function testLoadVersionInfoById()
680
    {
681
        $repository = $this->getRepository();
682
683
        $mediaFolderId = $this->generateId('object', 41);
684
        /* BEGIN: Use Case */
685
        // $mediaFolderId contains the ID of the "Media" folder
686
687
        $contentService = $repository->getContentService();
688
689
        // Load the VersionInfo for "Media" folder
690
        $versionInfo = $contentService->loadVersionInfoById($mediaFolderId);
691
        /* END: Use Case */
692
693
        $this->assertInstanceOf(
694
            '\\eZ\\Publish\\API\\Repository\\Values\\Content\\VersionInfo',
695
            $versionInfo
696
        );
697
698
        return $versionInfo;
699
    }
700
701
    /**
702
     * Test for the returned value of the loadVersionInfoById() method.
@@ 761-782 (lines=22) @@
758
     * @see \eZ\Publish\API\Repository\ContentService::loadContentByContentInfo()
759
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
760
     */
761
    public function testLoadContentByContentInfo()
762
    {
763
        $repository = $this->getRepository();
764
765
        $mediaFolderId = $this->generateId('object', 41);
766
        /* BEGIN: Use Case */
767
        // $mediaFolderId contains the ID of the "Media" folder
768
769
        $contentService = $repository->getContentService();
770
771
        // Load the ContentInfo for "Media" folder
772
        $contentInfo = $contentService->loadContentInfo($mediaFolderId);
773
774
        // Now load the current content version for the info instance
775
        $content = $contentService->loadContentByContentInfo($contentInfo);
776
        /* END: Use Case */
777
778
        $this->assertInstanceOf(
779
            '\\eZ\\Publish\\API\\Repository\\Values\\Content\\Content',
780
            $content
781
        );
782
    }
783
784
    /**
785
     * Test for the loadContentByVersionInfo() method.
@@ 823-841 (lines=19) @@
820
     * @group user
821
     * @group field-type
822
     */
823
    public function testLoadContent()
824
    {
825
        $repository = $this->getRepository();
826
827
        $mediaFolderId = $this->generateId('object', 41);
828
        /* BEGIN: Use Case */
829
        // $mediaFolderId contains the ID of the "Media" folder
830
831
        $contentService = $repository->getContentService();
832
833
        // Load the Content for "Media" folder, any language and current version
834
        $content = $contentService->loadContent($mediaFolderId);
835
        /* END: Use Case */
836
837
        $this->assertInstanceOf(
838
            '\\eZ\\Publish\\API\\Repository\\Values\\Content\\Content',
839
            $content
840
        );
841
    }
842
843
    /**
844
     * Test for the loadContent() method.