Code Duplication    Length = 51-51 lines in 2 locations

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

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