Code Duplication    Length = 51-51 lines in 2 locations

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

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