Code Duplication    Length = 45-50 lines in 2 locations

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

@@ 540-589 (lines=50) @@
537
     * @see \eZ\Publish\API\Repository\SectionService::assignSection()
538
     * @depends eZ\Publish\API\Repository\Tests\SectionServiceTest::testCountAssignedContents
539
     */
540
    public function testAssignSection()
541
    {
542
        $repository = $this->getRepository();
543
        $sectionService = $repository->getSectionService();
544
545
        $standardSectionId = $this->generateId('section', 1);
546
        $mediaSectionId = $this->generateId('section', 3);
547
548
        $beforeStandardCount = $sectionService->countAssignedContents(
549
            $sectionService->loadSection($standardSectionId)
550
        );
551
        $beforeMediaCount = $sectionService->countAssignedContents(
552
            $sectionService->loadSection($mediaSectionId)
553
        );
554
555
        /* BEGIN: Use Case */
556
        // $mediaSectionId contains the ID of the "Media" section in a eZ
557
        // Publish demo installation.
558
559
        // RemoteId of the "Media" page of an eZ Publish demo installation
560
        $mediaRemoteId = 'a6e35cbcb7cd6ae4b691f3eee30cd262';
561
562
        $contentService = $repository->getContentService();
563
        $sectionService = $repository->getSectionService();
564
565
        // Load a content info instance
566
        $contentInfo = $contentService->loadContentInfoByRemoteId(
567
            $mediaRemoteId
568
        );
569
570
        // Load the "Standard" section
571
        $section = $sectionService->loadSection($standardSectionId);
572
573
        // Assign Section to ContentInfo
574
        $sectionService->assignSection($contentInfo, $section);
575
        /* END: Use Case */
576
577
        $this->assertEquals(
578
            $beforeStandardCount + 1,
579
            $sectionService->countAssignedContents(
580
                $sectionService->loadSection($standardSectionId)
581
            )
582
        );
583
        $this->assertEquals(
584
            $beforeMediaCount - 1,
585
            $sectionService->countAssignedContents(
586
                $sectionService->loadSection($mediaSectionId)
587
            )
588
        );
589
    }
590
591
    /**
592
     * Test for the assignSectionToSubtree() method.
@@ 597-641 (lines=45) @@
594
     * @see \eZ\Publish\API\Repository\SectionService::assignSectionToSubtree()
595
     * @depends eZ\Publish\API\Repository\Tests\SectionServiceTest::testCreateSection
596
     */
597
    public function testAssignSectionToSubtree()
598
    {
599
        $repository = $this->getRepository();
600
        $sectionService = $repository->getSectionService();
601
602
        $standardSectionId = $this->generateId('section', 1);
603
        $mediaSectionId = $this->generateId('section', 3);
604
605
        $beforeStandardCount = $sectionService->countAssignedContents(
606
            $sectionService->loadSection($standardSectionId)
607
        );
608
609
        $beforeMediaCount = $sectionService->countAssignedContents(
610
            $sectionService->loadSection($mediaSectionId)
611
        );
612
613
        // RemoteId of the "Media" page of an eZ Publish demo installation
614
        $mediaRemoteId = '75c715a51699d2d309a924eca6a95145';
615
616
        /* BEGIN: Use Case */
617
        $locationService = $repository->getLocationService();
618
619
        // Load a location instance
620
        $location = $locationService->loadLocationByRemoteId($mediaRemoteId);
621
622
        // Load the "Standard" section
623
        $section = $sectionService->loadSection($standardSectionId);
624
625
        // Assign Section to ContentInfo
626
        $sectionService->assignSectionToSubtree($location, $section);
627
628
        /* END: Use Case */
629
        $this->assertEquals(
630
            $beforeStandardCount + 4,
631
            $sectionService->countAssignedContents(
632
                $sectionService->loadSection($standardSectionId)
633
            )
634
        );
635
        $this->assertEquals(
636
            $beforeMediaCount - 4,
637
            $sectionService->countAssignedContents(
638
                $sectionService->loadSection($mediaSectionId)
639
            )
640
        );
641
    }
642
643
    /**
644
     * Test for the countAssignedContents() method.