Code Duplication    Length = 51-51 lines in 2 locations

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

@@ 2065-2115 (lines=51) @@
2062
     * @see \eZ\Publish\API\Repository\LocationService::moveSubtree()
2063
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testMoveSubtree
2064
     */
2065
    public function testMoveSubtreeIncrementsChildCountOfNewParent()
2066
    {
2067
        $repository = $this->getRepository();
2068
        $locationService = $repository->getLocationService();
2069
2070
        $newParentLocation = $locationService->loadLocation($this->generateId('location', 56));
2071
2072
        // Load expected properties before move
2073
        $expected = $this->loadLocationProperties($newParentLocation);
2074
        $childCountBefore = $locationService->getLocationChildCount($newParentLocation);
2075
2076
        $mediaLocationId = $this->generateId('location', 43);
2077
        $demoDesignLocationId = $this->generateId('location', 56);
2078
        /* BEGIN: Use Case */
2079
        // $mediaLocationId is the ID of the "Media" page location in
2080
        // an eZ Publish demo installation
2081
2082
        // $demoDesignLocationId is the ID of the "Demo Design" page location in an eZ
2083
        // Publish demo installation
2084
2085
        // Load the location service
2086
        $locationService = $repository->getLocationService();
2087
2088
        // Load location to move
2089
        $locationToMove = $locationService->loadLocation($mediaLocationId);
2090
2091
        // Load new parent location
2092
        $newParentLocation = $locationService->loadLocation($demoDesignLocationId);
2093
2094
        // Move location from "Home" to "Demo Design"
2095
        $locationService->moveSubtree(
2096
            $locationToMove,
2097
            $newParentLocation
2098
        );
2099
2100
        // Load moved location
2101
        $movedLocation = $locationService->loadLocation($mediaLocationId);
2102
2103
        // Reload new parent location
2104
        $newParentLocation = $locationService->loadLocation($demoDesignLocationId);
2105
        /* END: Use Case */
2106
2107
        $this->refreshSearch($repository);
2108
2109
        // Load Subtree properties after move
2110
        $actual = $this->loadLocationProperties($newParentLocation);
2111
        $childCountAfter = $locationService->getLocationChildCount($newParentLocation);
2112
2113
        $this->assertEquals($expected, $actual);
2114
        $this->assertEquals($childCountBefore + 1, $childCountAfter);
2115
    }
2116
2117
    /**
2118
     * Test for the moveSubtree() method.
@@ 2123-2173 (lines=51) @@
2120
     * @see \eZ\Publish\API\Repository\LocationService::moveSubtree()
2121
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testMoveSubtree
2122
     */
2123
    public function testMoveSubtreeDecrementsChildCountOfOldParent()
2124
    {
2125
        $repository = $this->getRepository();
2126
        $locationService = $repository->getLocationService();
2127
2128
        $oldParentLocation = $locationService->loadLocation($this->generateId('location', 1));
2129
2130
        // Load expected properties before move
2131
        $expected = $this->loadLocationProperties($oldParentLocation);
2132
        $childCountBefore = $locationService->getLocationChildCount($oldParentLocation);
2133
2134
        $mediaLocationId = $this->generateId('location', 43);
2135
        $demoDesignLocationId = $this->generateId('location', 56);
2136
        /* BEGIN: Use Case */
2137
        // $mediaLocationId is the ID of the "Media" page location in
2138
        // an eZ Publish demo installation
2139
2140
        // $demoDesignLocationId is the ID of the "Demo Design" page location in an eZ
2141
        // Publish demo installation
2142
2143
        // Load the location service
2144
        $locationService = $repository->getLocationService();
2145
2146
        // Load location to move
2147
        $locationToMove = $locationService->loadLocation($mediaLocationId);
2148
2149
        // Get the location id of the old parent
2150
        $oldParentLocationId = $locationToMove->parentLocationId;
2151
2152
        // Load new parent location
2153
        $newParentLocation = $locationService->loadLocation($demoDesignLocationId);
2154
2155
        // Move location from "Home" to "Demo Design"
2156
        $locationService->moveSubtree(
2157
            $locationToMove,
2158
            $newParentLocation
2159
        );
2160
2161
        // Reload old parent location
2162
        $oldParentLocation = $locationService->loadLocation($oldParentLocationId);
2163
        /* END: Use Case */
2164
2165
        $this->refreshSearch($repository);
2166
2167
        // Load Subtree properties after move
2168
        $actual = $this->loadLocationProperties($oldParentLocation);
2169
        $childCountAfter = $locationService->getLocationChildCount($oldParentLocation);
2170
2171
        $this->assertEquals($expected, $actual);
2172
        $this->assertEquals($childCountBefore - 1, $childCountAfter);
2173
    }
2174
2175
    /**
2176
     * Test for the moveSubtree() method.