Code Duplication    Length = 51-51 lines in 2 locations

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

@@ 2678-2728 (lines=51) @@
2675
     * @see \eZ\Publish\API\Repository\LocationService::moveSubtree()
2676
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testMoveSubtree
2677
     */
2678
    public function testMoveSubtreeIncrementsChildCountOfNewParent()
2679
    {
2680
        $repository = $this->getRepository();
2681
        $locationService = $repository->getLocationService();
2682
2683
        $newParentLocation = $locationService->loadLocation($this->generateId('location', 56));
2684
2685
        // Load expected properties before move
2686
        $expected = $this->loadLocationProperties($newParentLocation);
2687
        $childCountBefore = $locationService->getLocationChildCount($newParentLocation);
2688
2689
        $mediaLocationId = $this->generateId('location', 43);
2690
        $demoDesignLocationId = $this->generateId('location', 56);
2691
        /* BEGIN: Use Case */
2692
        // $mediaLocationId is the ID of the "Media" page location in
2693
        // an eZ Publish demo installation
2694
2695
        // $demoDesignLocationId is the ID of the "Demo Design" page location in an eZ
2696
        // Publish demo installation
2697
2698
        // Load the location service
2699
        $locationService = $repository->getLocationService();
2700
2701
        // Load location to move
2702
        $locationToMove = $locationService->loadLocation($mediaLocationId);
2703
2704
        // Load new parent location
2705
        $newParentLocation = $locationService->loadLocation($demoDesignLocationId);
2706
2707
        // Move location from "Home" to "Demo Design"
2708
        $locationService->moveSubtree(
2709
            $locationToMove,
2710
            $newParentLocation
2711
        );
2712
2713
        // Load moved location
2714
        $movedLocation = $locationService->loadLocation($mediaLocationId);
2715
2716
        // Reload new parent location
2717
        $newParentLocation = $locationService->loadLocation($demoDesignLocationId);
2718
        /* END: Use Case */
2719
2720
        $this->refreshSearch($repository);
2721
2722
        // Load Subtree properties after move
2723
        $actual = $this->loadLocationProperties($newParentLocation);
2724
        $childCountAfter = $locationService->getLocationChildCount($newParentLocation);
2725
2726
        $this->assertEquals($expected, $actual);
2727
        $this->assertEquals($childCountBefore + 1, $childCountAfter);
2728
    }
2729
2730
    /**
2731
     * Test for the moveSubtree() method.
@@ 2736-2786 (lines=51) @@
2733
     * @see \eZ\Publish\API\Repository\LocationService::moveSubtree()
2734
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testMoveSubtree
2735
     */
2736
    public function testMoveSubtreeDecrementsChildCountOfOldParent()
2737
    {
2738
        $repository = $this->getRepository();
2739
        $locationService = $repository->getLocationService();
2740
2741
        $oldParentLocation = $locationService->loadLocation($this->generateId('location', 1));
2742
2743
        // Load expected properties before move
2744
        $expected = $this->loadLocationProperties($oldParentLocation);
2745
        $childCountBefore = $locationService->getLocationChildCount($oldParentLocation);
2746
2747
        $mediaLocationId = $this->generateId('location', 43);
2748
        $demoDesignLocationId = $this->generateId('location', 56);
2749
        /* BEGIN: Use Case */
2750
        // $mediaLocationId is the ID of the "Media" page location in
2751
        // an eZ Publish demo installation
2752
2753
        // $demoDesignLocationId is the ID of the "Demo Design" page location in an eZ
2754
        // Publish demo installation
2755
2756
        // Load the location service
2757
        $locationService = $repository->getLocationService();
2758
2759
        // Load location to move
2760
        $locationToMove = $locationService->loadLocation($mediaLocationId);
2761
2762
        // Get the location id of the old parent
2763
        $oldParentLocationId = $locationToMove->parentLocationId;
2764
2765
        // Load new parent location
2766
        $newParentLocation = $locationService->loadLocation($demoDesignLocationId);
2767
2768
        // Move location from "Home" to "Demo Design"
2769
        $locationService->moveSubtree(
2770
            $locationToMove,
2771
            $newParentLocation
2772
        );
2773
2774
        // Reload old parent location
2775
        $oldParentLocation = $locationService->loadLocation($oldParentLocationId);
2776
        /* END: Use Case */
2777
2778
        $this->refreshSearch($repository);
2779
2780
        // Load Subtree properties after move
2781
        $actual = $this->loadLocationProperties($oldParentLocation);
2782
        $childCountAfter = $locationService->getLocationChildCount($oldParentLocation);
2783
2784
        $this->assertEquals($expected, $actual);
2785
        $this->assertEquals($childCountBefore - 1, $childCountAfter);
2786
    }
2787
2788
    /**
2789
     * Test moving invisible (hidden by parent) subtree.