Code Duplication    Length = 10-22 lines in 9 locations

eZ/Publish/API/Repository/Tests/ContentServiceTest.php 6 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.
@@ 601-610 (lines=10) @@
598
     * @see \eZ\Publish\API\Repository\ContentService::loadContentInfoList()
599
     * @depends testLoadContentInfoList
600
     */
601
    public function testLoadContentInfoListSkipsNotFoundItems()
602
    {
603
        $repository = $this->getRepository();
604
605
        $nonExistentContentId = $this->generateId('object', self::DB_INT_MAX);
606
        $contentService = $repository->getContentService();
607
        $list = $contentService->loadContentInfoList([$nonExistentContentId]);
608
609
        $this->assertCount(0, $list);
610
    }
611
612
    /**
613
     * Test for the loadContentInfoByRemoteId() method.
@@ 689-710 (lines=22) @@
686
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
687
     * @group user
688
     */
689
    public function testLoadVersionInfo()
690
    {
691
        $repository = $this->getRepository();
692
693
        $mediaFolderId = $this->generateId('object', 41);
694
        /* BEGIN: Use Case */
695
        // $mediaFolderId contains the ID of the "Media" folder
696
697
        $contentService = $repository->getContentService();
698
699
        // Load the ContentInfo for "Media" folder
700
        $contentInfo = $contentService->loadContentInfo($mediaFolderId);
701
702
        // Now load the current version info of the "Media" folder
703
        $versionInfo = $contentService->loadVersionInfo($contentInfo);
704
        /* END: Use Case */
705
706
        $this->assertInstanceOf(
707
            '\\eZ\\Publish\\API\\Repository\\Values\\Content\\VersionInfo',
708
            $versionInfo
709
        );
710
    }
711
712
    /**
713
     * Test for the loadVersionInfoById() method.
@@ 717-737 (lines=21) @@
714
     *
715
     * @see \eZ\Publish\API\Repository\ContentService::loadVersionInfoById()
716
     */
717
    public function testLoadVersionInfoById()
718
    {
719
        $repository = $this->getRepository();
720
721
        $mediaFolderId = $this->generateId('object', 41);
722
        /* BEGIN: Use Case */
723
        // $mediaFolderId contains the ID of the "Media" folder
724
725
        $contentService = $repository->getContentService();
726
727
        // Load the VersionInfo for "Media" folder
728
        $versionInfo = $contentService->loadVersionInfoById($mediaFolderId);
729
        /* END: Use Case */
730
731
        $this->assertInstanceOf(
732
            '\\eZ\\Publish\\API\\Repository\\Values\\Content\\VersionInfo',
733
            $versionInfo
734
        );
735
736
        return $versionInfo;
737
    }
738
739
    /**
740
     * Test for the returned value of the loadVersionInfoById() method.
@@ 799-820 (lines=22) @@
796
     * @see \eZ\Publish\API\Repository\ContentService::loadContentByContentInfo()
797
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
798
     */
799
    public function testLoadContentByContentInfo()
800
    {
801
        $repository = $this->getRepository();
802
803
        $mediaFolderId = $this->generateId('object', 41);
804
        /* BEGIN: Use Case */
805
        // $mediaFolderId contains the ID of the "Media" folder
806
807
        $contentService = $repository->getContentService();
808
809
        // Load the ContentInfo for "Media" folder
810
        $contentInfo = $contentService->loadContentInfo($mediaFolderId);
811
812
        // Now load the current content version for the info instance
813
        $content = $contentService->loadContentByContentInfo($contentInfo);
814
        /* END: Use Case */
815
816
        $this->assertInstanceOf(
817
            '\\eZ\\Publish\\API\\Repository\\Values\\Content\\Content',
818
            $content
819
        );
820
    }
821
822
    /**
823
     * Test for the loadContentByVersionInfo() method.
@@ 861-879 (lines=19) @@
858
     * @group user
859
     * @group field-type
860
     */
861
    public function testLoadContent()
862
    {
863
        $repository = $this->getRepository();
864
865
        $mediaFolderId = $this->generateId('object', 41);
866
        /* BEGIN: Use Case */
867
        // $mediaFolderId contains the ID of the "Media" folder
868
869
        $contentService = $repository->getContentService();
870
871
        // Load the Content for "Media" folder, any language and current version
872
        $content = $contentService->loadContent($mediaFolderId);
873
        /* END: Use Case */
874
875
        $this->assertInstanceOf(
876
            '\\eZ\\Publish\\API\\Repository\\Values\\Content\\Content',
877
            $content
878
        );
879
    }
880
881
    /**
882
     * Test for the loadContent() method.

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

@@ 148-158 (lines=11) @@
145
     * @see \eZ\Publish\API\Repository\ContentService::loadContentInfoList()
146
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfoList
147
     */
148
    public function testLoadContentInfoListSkipsUnauthorizedItems()
149
    {
150
        $repository = $this->getRepository();
151
        $contentId = $this->generateId('object', 10);
152
        $contentService = $repository->getContentService();
153
        $repository->setCurrentUser($this->createAnonymousWithEditorRole());
154
155
        $list = $contentService->loadContentInfoList([$contentId]);
156
157
        $this->assertCount(0, $list);
158
    }
159
160
    /**
161
     * Test for the loadContentInfoByRemoteId() method.
@@ 256-275 (lines=20) @@
253
     * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
254
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadVersionInfoById
255
     */
256
    public function testLoadVersionInfoByIdThrowsUnauthorizedException()
257
    {
258
        $repository = $this->getRepository();
259
260
        $anonymousUserId = $this->generateId('user', 10);
261
        /* BEGIN: Use Case */
262
        // $anonymousUserId is the ID of the "Anonymous User" in an eZ Publish
263
        // demo installation
264
265
        $contentService = $repository->getContentService();
266
267
        $pseudoEditor = $this->createAnonymousWithEditorRole();
268
269
        // Set restricted editor user
270
        $repository->setCurrentUser($pseudoEditor);
271
272
        // This call will fail with a "UnauthorizedException"
273
        $contentService->loadVersionInfoById($anonymousUserId);
274
        /* END: Use Case */
275
    }
276
277
    /**
278
     * Test for the loadVersionInfoById() method.
@@ 284-303 (lines=20) @@
281
     * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
282
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadVersionInfoByIdWithSecondParameter
283
     */
284
    public function testLoadVersionInfoByIdThrowsUnauthorizedExceptionWithSecondParameter()
285
    {
286
        $repository = $this->getRepository();
287
288
        $anonymousUserId = $this->generateId('user', 10);
289
        /* BEGIN: Use Case */
290
        // $anonymousUserId is the ID of the "Anonymous User" in an eZ Publish
291
        // demo installation
292
293
        $contentService = $repository->getContentService();
294
295
        $pseudoEditor = $this->createAnonymousWithEditorRole();
296
297
        // Set restricted editor user
298
        $repository->setCurrentUser($pseudoEditor);
299
300
        // This call will fail with a "UnauthorizedException"
301
        $contentService->loadVersionInfoById($anonymousUserId, 2);
302
        /* END: Use Case */
303
    }
304
305
    /**
306
     * Test for the loadVersionInfoById() method.