Code Duplication    Length = 51-51 lines in 2 locations

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

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