Code Duplication    Length = 51-51 lines in 2 locations

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

@@ 2759-2809 (lines=51) @@
2756
     * @see \eZ\Publish\API\Repository\LocationService::moveSubtree()
2757
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testMoveSubtree
2758
     */
2759
    public function testMoveSubtreeIncrementsChildCountOfNewParent()
2760
    {
2761
        $repository = $this->getRepository();
2762
        $locationService = $repository->getLocationService();
2763
2764
        $newParentLocation = $locationService->loadLocation($this->generateId('location', 56));
2765
2766
        // Load expected properties before move
2767
        $expected = $this->loadLocationProperties($newParentLocation);
2768
        $childCountBefore = $locationService->getLocationChildCount($newParentLocation);
2769
2770
        $mediaLocationId = $this->generateId('location', 43);
2771
        $demoDesignLocationId = $this->generateId('location', 56);
2772
        /* BEGIN: Use Case */
2773
        // $mediaLocationId is the ID of the "Media" page location in
2774
        // an eZ Publish demo installation
2775
2776
        // $demoDesignLocationId is the ID of the "Demo Design" page location in an eZ
2777
        // Publish demo installation
2778
2779
        // Load the location service
2780
        $locationService = $repository->getLocationService();
2781
2782
        // Load location to move
2783
        $locationToMove = $locationService->loadLocation($mediaLocationId);
2784
2785
        // Load new parent location
2786
        $newParentLocation = $locationService->loadLocation($demoDesignLocationId);
2787
2788
        // Move location from "Home" to "Demo Design"
2789
        $locationService->moveSubtree(
2790
            $locationToMove,
2791
            $newParentLocation
2792
        );
2793
2794
        // Load moved location
2795
        $movedLocation = $locationService->loadLocation($mediaLocationId);
2796
2797
        // Reload new parent location
2798
        $newParentLocation = $locationService->loadLocation($demoDesignLocationId);
2799
        /* END: Use Case */
2800
2801
        $this->refreshSearch($repository);
2802
2803
        // Load Subtree properties after move
2804
        $actual = $this->loadLocationProperties($newParentLocation);
2805
        $childCountAfter = $locationService->getLocationChildCount($newParentLocation);
2806
2807
        $this->assertEquals($expected, $actual);
2808
        $this->assertEquals($childCountBefore + 1, $childCountAfter);
2809
    }
2810
2811
    /**
2812
     * Test for the moveSubtree() method.
@@ 2817-2867 (lines=51) @@
2814
     * @see \eZ\Publish\API\Repository\LocationService::moveSubtree()
2815
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testMoveSubtree
2816
     */
2817
    public function testMoveSubtreeDecrementsChildCountOfOldParent()
2818
    {
2819
        $repository = $this->getRepository();
2820
        $locationService = $repository->getLocationService();
2821
2822
        $oldParentLocation = $locationService->loadLocation($this->generateId('location', 1));
2823
2824
        // Load expected properties before move
2825
        $expected = $this->loadLocationProperties($oldParentLocation);
2826
        $childCountBefore = $locationService->getLocationChildCount($oldParentLocation);
2827
2828
        $mediaLocationId = $this->generateId('location', 43);
2829
        $demoDesignLocationId = $this->generateId('location', 56);
2830
        /* BEGIN: Use Case */
2831
        // $mediaLocationId is the ID of the "Media" page location in
2832
        // an eZ Publish demo installation
2833
2834
        // $demoDesignLocationId is the ID of the "Demo Design" page location in an eZ
2835
        // Publish demo installation
2836
2837
        // Load the location service
2838
        $locationService = $repository->getLocationService();
2839
2840
        // Load location to move
2841
        $locationToMove = $locationService->loadLocation($mediaLocationId);
2842
2843
        // Get the location id of the old parent
2844
        $oldParentLocationId = $locationToMove->parentLocationId;
2845
2846
        // Load new parent location
2847
        $newParentLocation = $locationService->loadLocation($demoDesignLocationId);
2848
2849
        // Move location from "Home" to "Demo Design"
2850
        $locationService->moveSubtree(
2851
            $locationToMove,
2852
            $newParentLocation
2853
        );
2854
2855
        // Reload old parent location
2856
        $oldParentLocation = $locationService->loadLocation($oldParentLocationId);
2857
        /* END: Use Case */
2858
2859
        $this->refreshSearch($repository);
2860
2861
        // Load Subtree properties after move
2862
        $actual = $this->loadLocationProperties($oldParentLocation);
2863
        $childCountAfter = $locationService->getLocationChildCount($oldParentLocation);
2864
2865
        $this->assertEquals($expected, $actual);
2866
        $this->assertEquals($childCountBefore - 1, $childCountAfter);
2867
    }
2868
2869
    /**
2870
     * Test moving invisible (hidden by parent) subtree.