Code Duplication    Length = 51-51 lines in 2 locations

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

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