Code Duplication    Length = 18-22 lines in 4 locations

eZ/Publish/API/Repository/Tests/SectionServiceTest.php 3 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.

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

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