Code Duplication    Length = 51-51 lines in 2 locations

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

@@ 1932-1982 (lines=51) @@
1929
     * @see \eZ\Publish\API\Repository\LocationService::moveSubtree()
1930
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testMoveSubtree
1931
     */
1932
    public function testMoveSubtreeIncrementsChildCountOfNewParent()
1933
    {
1934
        $repository = $this->getRepository();
1935
        $locationService = $repository->getLocationService();
1936
1937
        $newParentLocation = $locationService->loadLocation($this->generateId('location', 56));
1938
1939
        // Load expected properties before move
1940
        $expected = $this->loadLocationProperties($newParentLocation);
1941
        $childCountBefore = $locationService->getLocationChildCount($newParentLocation);
1942
1943
        $mediaLocationId = $this->generateId('location', 43);
1944
        $demoDesignLocationId = $this->generateId('location', 56);
1945
        /* BEGIN: Use Case */
1946
        // $mediaLocationId is the ID of the "Media" page location in
1947
        // an eZ Publish demo installation
1948
1949
        // $demoDesignLocationId is the ID of the "Demo Design" page location in an eZ
1950
        // Publish demo installation
1951
1952
        // Load the location service
1953
        $locationService = $repository->getLocationService();
1954
1955
        // Load location to move
1956
        $locationToMove = $locationService->loadLocation($mediaLocationId);
1957
1958
        // Load new parent location
1959
        $newParentLocation = $locationService->loadLocation($demoDesignLocationId);
1960
1961
        // Move location from "Home" to "Demo Design"
1962
        $locationService->moveSubtree(
1963
            $locationToMove,
1964
            $newParentLocation
1965
        );
1966
1967
        // Load moved location
1968
        $movedLocation = $locationService->loadLocation($mediaLocationId);
1969
1970
        // Reload new parent location
1971
        $newParentLocation = $locationService->loadLocation($demoDesignLocationId);
1972
        /* END: Use Case */
1973
1974
        $this->refreshSearch($repository);
1975
1976
        // Load Subtree properties after move
1977
        $actual = $this->loadLocationProperties($newParentLocation);
1978
        $childCountAfter = $locationService->getLocationChildCount($newParentLocation);
1979
1980
        $this->assertEquals($expected, $actual);
1981
        $this->assertEquals($childCountBefore + 1, $childCountAfter);
1982
    }
1983
1984
    /**
1985
     * Test for the moveSubtree() method.
@@ 1990-2040 (lines=51) @@
1987
     * @see \eZ\Publish\API\Repository\LocationService::moveSubtree()
1988
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testMoveSubtree
1989
     */
1990
    public function testMoveSubtreeDecrementsChildCountOfOldParent()
1991
    {
1992
        $repository = $this->getRepository();
1993
        $locationService = $repository->getLocationService();
1994
1995
        $oldParentLocation = $locationService->loadLocation($this->generateId('location', 1));
1996
1997
        // Load expected properties before move
1998
        $expected = $this->loadLocationProperties($oldParentLocation);
1999
        $childCountBefore = $locationService->getLocationChildCount($oldParentLocation);
2000
2001
        $mediaLocationId = $this->generateId('location', 43);
2002
        $demoDesignLocationId = $this->generateId('location', 56);
2003
        /* BEGIN: Use Case */
2004
        // $mediaLocationId is the ID of the "Media" page location in
2005
        // an eZ Publish demo installation
2006
2007
        // $demoDesignLocationId is the ID of the "Demo Design" page location in an eZ
2008
        // Publish demo installation
2009
2010
        // Load the location service
2011
        $locationService = $repository->getLocationService();
2012
2013
        // Load location to move
2014
        $locationToMove = $locationService->loadLocation($mediaLocationId);
2015
2016
        // Get the location id of the old parent
2017
        $oldParentLocationId = $locationToMove->parentLocationId;
2018
2019
        // Load new parent location
2020
        $newParentLocation = $locationService->loadLocation($demoDesignLocationId);
2021
2022
        // Move location from "Home" to "Demo Design"
2023
        $locationService->moveSubtree(
2024
            $locationToMove,
2025
            $newParentLocation
2026
        );
2027
2028
        // Reload old parent location
2029
        $oldParentLocation = $locationService->loadLocation($oldParentLocationId);
2030
        /* END: Use Case */
2031
2032
        $this->refreshSearch($repository);
2033
2034
        // Load Subtree properties after move
2035
        $actual = $this->loadLocationProperties($oldParentLocation);
2036
        $childCountAfter = $locationService->getLocationChildCount($oldParentLocation);
2037
2038
        $this->assertEquals($expected, $actual);
2039
        $this->assertEquals($childCountBefore - 1, $childCountAfter);
2040
    }
2041
2042
    /**
2043
     * Test for the moveSubtree() method.