Code Duplication    Length = 51-51 lines in 2 locations

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

@@ 1856-1906 (lines=51) @@
1853
     * @see \eZ\Publish\API\Repository\LocationService::moveSubtree()
1854
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testMoveSubtree
1855
     */
1856
    public function testMoveSubtreeIncrementsChildCountOfNewParent()
1857
    {
1858
        $repository = $this->getRepository();
1859
        $locationService = $repository->getLocationService();
1860
1861
        $newParentLocation = $locationService->loadLocation($this->generateId('location', 56));
1862
1863
        // Load expected properties before move
1864
        $expected = $this->loadLocationProperties($newParentLocation);
1865
        $childCountBefore = $locationService->getLocationChildCount($newParentLocation);
1866
1867
        $mediaLocationId = $this->generateId('location', 43);
1868
        $demoDesignLocationId = $this->generateId('location', 56);
1869
        /* BEGIN: Use Case */
1870
        // $mediaLocationId is the ID of the "Media" page location in
1871
        // an eZ Publish demo installation
1872
1873
        // $demoDesignLocationId is the ID of the "Demo Design" page location in an eZ
1874
        // Publish demo installation
1875
1876
        // Load the location service
1877
        $locationService = $repository->getLocationService();
1878
1879
        // Load location to move
1880
        $locationToMove = $locationService->loadLocation($mediaLocationId);
1881
1882
        // Load new parent location
1883
        $newParentLocation = $locationService->loadLocation($demoDesignLocationId);
1884
1885
        // Move location from "Home" to "Demo Design"
1886
        $locationService->moveSubtree(
1887
            $locationToMove,
1888
            $newParentLocation
1889
        );
1890
1891
        // Load moved location
1892
        $movedLocation = $locationService->loadLocation($mediaLocationId);
1893
1894
        // Reload new parent location
1895
        $newParentLocation = $locationService->loadLocation($demoDesignLocationId);
1896
        /* END: Use Case */
1897
1898
        $this->refreshSearch($repository);
1899
1900
        // Load Subtree properties after move
1901
        $actual = $this->loadLocationProperties($newParentLocation);
1902
        $childCountAfter = $locationService->getLocationChildCount($newParentLocation);
1903
1904
        $this->assertEquals($expected, $actual);
1905
        $this->assertEquals($childCountBefore + 1, $childCountAfter);
1906
    }
1907
1908
    /**
1909
     * Test for the moveSubtree() method.
@@ 1914-1964 (lines=51) @@
1911
     * @see \eZ\Publish\API\Repository\LocationService::moveSubtree()
1912
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testMoveSubtree
1913
     */
1914
    public function testMoveSubtreeDecrementsChildCountOfOldParent()
1915
    {
1916
        $repository = $this->getRepository();
1917
        $locationService = $repository->getLocationService();
1918
1919
        $oldParentLocation = $locationService->loadLocation($this->generateId('location', 1));
1920
1921
        // Load expected properties before move
1922
        $expected = $this->loadLocationProperties($oldParentLocation);
1923
        $childCountBefore = $locationService->getLocationChildCount($oldParentLocation);
1924
1925
        $mediaLocationId = $this->generateId('location', 43);
1926
        $demoDesignLocationId = $this->generateId('location', 56);
1927
        /* BEGIN: Use Case */
1928
        // $mediaLocationId is the ID of the "Media" page location in
1929
        // an eZ Publish demo installation
1930
1931
        // $demoDesignLocationId is the ID of the "Demo Design" page location in an eZ
1932
        // Publish demo installation
1933
1934
        // Load the location service
1935
        $locationService = $repository->getLocationService();
1936
1937
        // Load location to move
1938
        $locationToMove = $locationService->loadLocation($mediaLocationId);
1939
1940
        // Get the location id of the old parent
1941
        $oldParentLocationId = $locationToMove->parentLocationId;
1942
1943
        // Load new parent location
1944
        $newParentLocation = $locationService->loadLocation($demoDesignLocationId);
1945
1946
        // Move location from "Home" to "Demo Design"
1947
        $locationService->moveSubtree(
1948
            $locationToMove,
1949
            $newParentLocation
1950
        );
1951
1952
        // Reload old parent location
1953
        $oldParentLocation = $locationService->loadLocation($oldParentLocationId);
1954
        /* END: Use Case */
1955
1956
        $this->refreshSearch($repository);
1957
1958
        // Load Subtree properties after move
1959
        $actual = $this->loadLocationProperties($oldParentLocation);
1960
        $childCountAfter = $locationService->getLocationChildCount($oldParentLocation);
1961
1962
        $this->assertEquals($expected, $actual);
1963
        $this->assertEquals($childCountBefore - 1, $childCountAfter);
1964
    }
1965
1966
    /**
1967
     * Test for the moveSubtree() method.