Code Duplication    Length = 51-51 lines in 2 locations

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

@@ 2814-2864 (lines=51) @@
2811
     * @see \eZ\Publish\API\Repository\LocationService::moveSubtree()
2812
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testMoveSubtree
2813
     */
2814
    public function testMoveSubtreeIncrementsChildCountOfNewParent()
2815
    {
2816
        $repository = $this->getRepository();
2817
        $locationService = $repository->getLocationService();
2818
2819
        $newParentLocation = $locationService->loadLocation($this->generateId('location', 43));
2820
2821
        // Load expected properties before move
2822
        $expected = $this->loadLocationProperties($newParentLocation);
2823
        $childCountBefore = $locationService->getLocationChildCount($newParentLocation);
2824
2825
        $mediaLocationId = $this->generateId('location', 43);
2826
        $demoDesignLocationId = $this->generateId('location', 56);
2827
        /* BEGIN: Use Case */
2828
        // $mediaLocationId is the ID of the "Media" page location in
2829
        // an eZ Publish demo installation
2830
2831
        // $demoDesignLocationId is the ID of the "Demo Design" page location in an eZ
2832
        // Publish demo installation
2833
2834
        // Load the location service
2835
        $locationService = $repository->getLocationService();
2836
2837
        // Load location to move
2838
        $locationToMove = $locationService->loadLocation($demoDesignLocationId);
2839
2840
        // Load new parent location
2841
        $newParentLocation = $locationService->loadLocation($mediaLocationId);
2842
2843
        // Move location from "Demo Design" to "Home"
2844
        $locationService->moveSubtree(
2845
            $locationToMove,
2846
            $newParentLocation
2847
        );
2848
2849
        // Load moved location
2850
        $movedLocation = $locationService->loadLocation($demoDesignLocationId);
2851
2852
        // Reload new parent location
2853
        $newParentLocation = $locationService->loadLocation($mediaLocationId);
2854
        /* END: Use Case */
2855
2856
        $this->refreshSearch($repository);
2857
2858
        // Load Subtree properties after move
2859
        $actual = $this->loadLocationProperties($newParentLocation);
2860
        $childCountAfter = $locationService->getLocationChildCount($newParentLocation);
2861
2862
        $this->assertEquals($expected, $actual);
2863
        $this->assertEquals($childCountBefore + 1, $childCountAfter);
2864
    }
2865
2866
    /**
2867
     * Test for the moveSubtree() method.
@@ 2872-2922 (lines=51) @@
2869
     * @see \eZ\Publish\API\Repository\LocationService::moveSubtree()
2870
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testMoveSubtree
2871
     */
2872
    public function testMoveSubtreeDecrementsChildCountOfOldParent()
2873
    {
2874
        $repository = $this->getRepository();
2875
        $locationService = $repository->getLocationService();
2876
2877
        $oldParentLocation = $locationService->loadLocation($this->generateId('location', 1));
2878
2879
        // Load expected properties before move
2880
        $expected = $this->loadLocationProperties($oldParentLocation);
2881
        $childCountBefore = $locationService->getLocationChildCount($oldParentLocation);
2882
2883
        $homeLocationId = $this->generateId('location', 2);
2884
        $mediaLocationId = $this->generateId('location', 43);
2885
        /* BEGIN: Use Case */
2886
        // $homeLocationId is the ID of the "Home" page location in
2887
        // an eZ Publish demo installation
2888
2889
        // $mediaLocationId is the ID of the "Media" page location in an eZ
2890
        // Publish demo installation
2891
2892
        // Load the location service
2893
        $locationService = $repository->getLocationService();
2894
2895
        // Load location to move
2896
        $locationToMove = $locationService->loadLocation($mediaLocationId);
2897
2898
        // Get the location id of the old parent
2899
        $oldParentLocationId = $locationToMove->parentLocationId;
2900
2901
        // Load new parent location
2902
        $newParentLocation = $locationService->loadLocation($homeLocationId);
2903
2904
        // Move location from "Demo Design" to "Home"
2905
        $locationService->moveSubtree(
2906
            $locationToMove,
2907
            $newParentLocation
2908
        );
2909
2910
        // Reload old parent location
2911
        $oldParentLocation = $locationService->loadLocation($oldParentLocationId);
2912
        /* END: Use Case */
2913
2914
        $this->refreshSearch($repository);
2915
2916
        // Load Subtree properties after move
2917
        $actual = $this->loadLocationProperties($oldParentLocation);
2918
        $childCountAfter = $locationService->getLocationChildCount($oldParentLocation);
2919
2920
        $this->assertEquals($expected, $actual);
2921
        $this->assertEquals($childCountBefore - 1, $childCountAfter);
2922
    }
2923
2924
    /**
2925
     * Test moving invisible (hidden by parent) subtree.