Code Duplication    Length = 17-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

@@ 473-489 (lines=17) @@
470
     * @see \eZ\Publish\API\Repository\ContentService::loadContentInfo()
471
     * @group user
472
     */
473
    public function testLoadContentInfo()
474
    {
475
        $repository = $this->getRepository();
476
477
        $mediaFolderId = $this->generateId('object', 41);
478
        /* BEGIN: Use Case */
479
        $contentService = $repository->getContentService();
480
481
        // Load the ContentInfo for "Media" folder
482
        $contentInfo = $contentService->loadContentInfo($mediaFolderId);
483
        /* END: Use Case */
484
485
        $this->assertInstanceOf(
486
            '\\eZ\\Publish\\API\\Repository\\Values\\Content\\ContentInfo',
487
            $contentInfo
488
        );
489
    }
490
491
    /**
492
     * Test for the loadContentInfo() method.
@@ 556-577 (lines=22) @@
553
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
554
     * @group user
555
     */
556
    public function testLoadVersionInfo()
557
    {
558
        $repository = $this->getRepository();
559
560
        $mediaFolderId = $this->generateId('object', 41);
561
        /* BEGIN: Use Case */
562
        // $mediaFolderId contains the ID of the "Media" folder
563
564
        $contentService = $repository->getContentService();
565
566
        // Load the ContentInfo for "Media" folder
567
        $contentInfo = $contentService->loadContentInfo($mediaFolderId);
568
569
        // Now load the current version info of the "Media" folder
570
        $versionInfo = $contentService->loadVersionInfo($contentInfo);
571
        /* END: Use Case */
572
573
        $this->assertInstanceOf(
574
            '\\eZ\\Publish\\API\\Repository\\Values\\Content\\VersionInfo',
575
            $versionInfo
576
        );
577
    }
578
579
    /**
580
     * Test for the loadVersionInfoById() method.
@@ 584-602 (lines=19) @@
581
     *
582
     * @see \eZ\Publish\API\Repository\ContentService::loadVersionInfoById()
583
     */
584
    public function testLoadVersionInfoById()
585
    {
586
        $repository = $this->getRepository();
587
588
        $mediaFolderId = $this->generateId('object', 41);
589
        /* BEGIN: Use Case */
590
        // $mediaFolderId contains the ID of the "Media" folder
591
592
        $contentService = $repository->getContentService();
593
594
        // Load the VersionInfo for "Media" folder
595
        $versionInfo = $contentService->loadVersionInfoById($mediaFolderId);
596
        /* END: Use Case */
597
598
        $this->assertInstanceOf(
599
            '\\eZ\\Publish\\API\\Repository\\Values\\Content\\VersionInfo',
600
            $versionInfo
601
        );
602
    }
603
604
    /**
605
     * Test for the loadVersionInfoById() method.
@@ 630-651 (lines=22) @@
627
     * @see \eZ\Publish\API\Repository\ContentService::loadContentByContentInfo()
628
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
629
     */
630
    public function testLoadContentByContentInfo()
631
    {
632
        $repository = $this->getRepository();
633
634
        $mediaFolderId = $this->generateId('object', 41);
635
        /* BEGIN: Use Case */
636
        // $mediaFolderId contains the ID of the "Media" folder
637
638
        $contentService = $repository->getContentService();
639
640
        // Load the ContentInfo for "Media" folder
641
        $contentInfo = $contentService->loadContentInfo($mediaFolderId);
642
643
        // Now load the current content version for the info instance
644
        $content = $contentService->loadContentByContentInfo($contentInfo);
645
        /* END: Use Case */
646
647
        $this->assertInstanceOf(
648
            '\\eZ\\Publish\\API\\Repository\\Values\\Content\\Content',
649
            $content
650
        );
651
    }
652
653
    /**
654
     * Test for the loadContentByVersionInfo() method.
@@ 692-710 (lines=19) @@
689
     * @group user
690
     * @group field-type
691
     */
692
    public function testLoadContent()
693
    {
694
        $repository = $this->getRepository();
695
696
        $mediaFolderId = $this->generateId('object', 41);
697
        /* BEGIN: Use Case */
698
        // $mediaFolderId contains the ID of the "Media" folder
699
700
        $contentService = $repository->getContentService();
701
702
        // Load the Content for "Media" folder, any language and current version
703
        $content = $contentService->loadContent($mediaFolderId);
704
        /* END: Use Case */
705
706
        $this->assertInstanceOf(
707
            '\\eZ\\Publish\\API\\Repository\\Values\\Content\\Content',
708
            $content
709
        );
710
    }
711
712
    /**
713
     * Test for the loadContent() method.