Code Duplication    Length = 51-51 lines in 2 locations

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

@@ 2855-2905 (lines=51) @@
2852
     * @see \eZ\Publish\API\Repository\LocationService::moveSubtree()
2853
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testMoveSubtree
2854
     */
2855
    public function testMoveSubtreeIncrementsChildCountOfNewParent()
2856
    {
2857
        $repository = $this->getRepository();
2858
        $locationService = $repository->getLocationService();
2859
2860
        $newParentLocation = $locationService->loadLocation($this->generateId('location', 43));
2861
2862
        // Load expected properties before move
2863
        $expected = $this->loadLocationProperties($newParentLocation);
2864
        $childCountBefore = $locationService->getLocationChildCount($newParentLocation);
2865
2866
        $mediaLocationId = $this->generateId('location', 43);
2867
        $demoDesignLocationId = $this->generateId('location', 56);
2868
        /* BEGIN: Use Case */
2869
        // $mediaLocationId is the ID of the "Media" page location in
2870
        // an eZ Publish demo installation
2871
2872
        // $demoDesignLocationId is the ID of the "Demo Design" page location in an eZ
2873
        // Publish demo installation
2874
2875
        // Load the location service
2876
        $locationService = $repository->getLocationService();
2877
2878
        // Load location to move
2879
        $locationToMove = $locationService->loadLocation($demoDesignLocationId);
2880
2881
        // Load new parent location
2882
        $newParentLocation = $locationService->loadLocation($mediaLocationId);
2883
2884
        // Move location from "Demo Design" to "Home"
2885
        $locationService->moveSubtree(
2886
            $locationToMove,
2887
            $newParentLocation
2888
        );
2889
2890
        // Load moved location
2891
        $movedLocation = $locationService->loadLocation($demoDesignLocationId);
2892
2893
        // Reload new parent location
2894
        $newParentLocation = $locationService->loadLocation($mediaLocationId);
2895
        /* END: Use Case */
2896
2897
        $this->refreshSearch($repository);
2898
2899
        // Load Subtree properties after move
2900
        $actual = $this->loadLocationProperties($newParentLocation);
2901
        $childCountAfter = $locationService->getLocationChildCount($newParentLocation);
2902
2903
        $this->assertEquals($expected, $actual);
2904
        $this->assertEquals($childCountBefore + 1, $childCountAfter);
2905
    }
2906
2907
    /**
2908
     * Test for the moveSubtree() method.
@@ 2913-2963 (lines=51) @@
2910
     * @see \eZ\Publish\API\Repository\LocationService::moveSubtree()
2911
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testMoveSubtree
2912
     */
2913
    public function testMoveSubtreeDecrementsChildCountOfOldParent()
2914
    {
2915
        $repository = $this->getRepository();
2916
        $locationService = $repository->getLocationService();
2917
2918
        $oldParentLocation = $locationService->loadLocation($this->generateId('location', 1));
2919
2920
        // Load expected properties before move
2921
        $expected = $this->loadLocationProperties($oldParentLocation);
2922
        $childCountBefore = $locationService->getLocationChildCount($oldParentLocation);
2923
2924
        $homeLocationId = $this->generateId('location', 2);
2925
        $mediaLocationId = $this->generateId('location', 43);
2926
        /* BEGIN: Use Case */
2927
        // $homeLocationId is the ID of the "Home" page location in
2928
        // an eZ Publish demo installation
2929
2930
        // $mediaLocationId is the ID of the "Media" page location in an eZ
2931
        // Publish demo installation
2932
2933
        // Load the location service
2934
        $locationService = $repository->getLocationService();
2935
2936
        // Load location to move
2937
        $locationToMove = $locationService->loadLocation($mediaLocationId);
2938
2939
        // Get the location id of the old parent
2940
        $oldParentLocationId = $locationToMove->parentLocationId;
2941
2942
        // Load new parent location
2943
        $newParentLocation = $locationService->loadLocation($homeLocationId);
2944
2945
        // Move location from "Demo Design" to "Home"
2946
        $locationService->moveSubtree(
2947
            $locationToMove,
2948
            $newParentLocation
2949
        );
2950
2951
        // Reload old parent location
2952
        $oldParentLocation = $locationService->loadLocation($oldParentLocationId);
2953
        /* END: Use Case */
2954
2955
        $this->refreshSearch($repository);
2956
2957
        // Load Subtree properties after move
2958
        $actual = $this->loadLocationProperties($oldParentLocation);
2959
        $childCountAfter = $locationService->getLocationChildCount($oldParentLocation);
2960
2961
        $this->assertEquals($expected, $actual);
2962
        $this->assertEquals($childCountBefore - 1, $childCountAfter);
2963
    }
2964
2965
    /**
2966
     * Test moving invisible (hidden by parent) subtree.