Code Duplication    Length = 18-22 lines in 6 locations

eZ/Publish/API/Repository/Tests/SectionServiceAuthorizationTest.php 1 location

@@ 28-49 (lines=22) @@
25
     * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
26
     * @depends eZ\Publish\API\Repository\Tests\SectionServiceTest::testCreateSection
27
     */
28
    public function testCreateSectionThrowsUnauthorizedException()
29
    {
30
        $repository = $this->getRepository();
31
32
        $anonymousUserId = $this->generateId('user', 10);
33
        /* BEGIN: Use Case */
34
        // $anonymousUserId is the ID of the "Anonymous" user in a eZ
35
        // Publish demo installation.
36
        $userService = $repository->getUserService();
37
        $sectionService = $repository->getSectionService();
38
39
        $sectionCreate = $sectionService->newSectionCreateStruct();
40
        $sectionCreate->name = 'Test Section';
41
        $sectionCreate->identifier = 'uniqueKey';
42
43
        // Set anonymous user
44
        $repository->setCurrentUser($userService->loadUser($anonymousUserId));
45
46
        // This call will fail with a "UnauthorizedException"
47
        $sectionService->createSection($sectionCreate);
48
        /* END: Use Case */
49
    }
50
51
    /**
52
     * Test for the loadSection() method.

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

@@ 439-456 (lines=18) @@
436
     * @see \eZ\Publish\API\Repository\SectionService::loadSectionByIdentifier()
437
     * @depends eZ\Publish\API\Repository\Tests\SectionServiceTest::testCreateSection
438
     */
439
    public function testLoadSectionByIdentifier()
440
    {
441
        $repository = $this->getRepository();
442
443
        /* BEGIN: Use Case */
444
        $sectionService = $repository->getSectionService();
445
446
        $sectionCreate = $sectionService->newSectionCreateStruct();
447
        $sectionCreate->name = 'Test Section';
448
        $sectionCreate->identifier = 'uniqueKey';
449
450
        $sectionId = $sectionService->createSection($sectionCreate)->id;
451
452
        $section = $sectionService->loadSectionByIdentifier('uniqueKey');
453
        /* END: Use Case */
454
455
        $this->assertEquals($sectionId, $section->id);
456
    }
457
458
    /**
459
     * Test for the loadSectionByIdentifier() method.
@@ 649-667 (lines=19) @@
646
     * @see \eZ\Publish\API\Repository\SectionService::countAssignedContents()
647
     * @depends eZ\Publish\API\Repository\Tests\SectionServiceTest::testCreateSection
648
     */
649
    public function testCountAssignedContentsReturnsZeroByDefault()
650
    {
651
        $repository = $this->getRepository();
652
653
        /* BEGIN: Use Case */
654
        $sectionService = $repository->getSectionService();
655
656
        $sectionCreate = $sectionService->newSectionCreateStruct();
657
        $sectionCreate->name = 'Test Section';
658
        $sectionCreate->identifier = 'uniqueKey';
659
660
        $section = $sectionService->createSection($sectionCreate);
661
662
        // The number of assigned contents should be zero
663
        $assignedContents = $sectionService->countAssignedContents($section);
664
        /* END: Use Case */
665
666
        $this->assertSame(0, $assignedContents);
667
    }
668
669
    /**
670
     * Test for the isSectionUsed() method.
@@ 675-693 (lines=19) @@
672
     * @see \eZ\Publish\API\Repository\SectionService::isSectionUsed()
673
     * @depends eZ\Publish\API\Repository\Tests\SectionServiceTest::testCreateSection
674
     */
675
    public function testIsSectionUsedReturnsZeroByDefault()
676
    {
677
        $repository = $this->getRepository();
678
679
        /* BEGIN: Use Case */
680
        $sectionService = $repository->getSectionService();
681
682
        $sectionCreate = $sectionService->newSectionCreateStruct();
683
        $sectionCreate->name = 'Test Section';
684
        $sectionCreate->identifier = 'uniqueKey';
685
686
        $section = $sectionService->createSection($sectionCreate);
687
688
        // The number of assigned contents should be zero
689
        $isSectionUsed = $sectionService->isSectionUsed($section);
690
        /* END: Use Case */
691
692
        $this->assertFalse($isSectionUsed);
693
    }
694
695
    /**
696
     * Test for the deleteSection() method.
@@ 701-719 (lines=19) @@
698
     * @see \eZ\Publish\API\Repository\SectionService::deleteSection()
699
     * @depends eZ\Publish\API\Repository\Tests\SectionServiceTest::testLoadSections
700
     */
701
    public function testDeleteSection()
702
    {
703
        $repository = $this->getRepository();
704
705
        /* BEGIN: Use Case */
706
        $sectionService = $repository->getSectionService();
707
708
        $sectionCreate = $sectionService->newSectionCreateStruct();
709
        $sectionCreate->name = 'Test Section';
710
        $sectionCreate->identifier = 'uniqueKey';
711
712
        $section = $sectionService->createSection($sectionCreate);
713
714
        // Delete the newly created section
715
        $sectionService->deleteSection($section);
716
        /* END: Use Case */
717
718
        $this->assertEquals(6, count($sectionService->loadSections()));
719
    }
720
721
    /**
722
     * Test for the deleteSection() method.
@@ 728-747 (lines=20) @@
725
     * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException
726
     * @depends eZ\Publish\API\Repository\Tests\SectionServiceTest::testDeleteSection
727
     */
728
    public function testDeleteSectionThrowsNotFoundException()
729
    {
730
        $repository = $this->getRepository();
731
732
        /* BEGIN: Use Case */
733
        $sectionService = $repository->getSectionService();
734
735
        $sectionCreate = $sectionService->newSectionCreateStruct();
736
        $sectionCreate->name = 'Test Section';
737
        $sectionCreate->identifier = 'uniqueKey';
738
739
        $section = $sectionService->createSection($sectionCreate);
740
741
        // Delete the newly created section
742
        $sectionService->deleteSection($section);
743
744
        // This call should fail with a NotFoundException
745
        $sectionService->deleteSection($section);
746
        /* END: Use Case */
747
    }
748
749
    /**
750
     * Test for the deleteSection() method.