Code Duplication    Length = 51-51 lines in 2 locations

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

@@ 2137-2187 (lines=51) @@
2134
     * @see \eZ\Publish\API\Repository\LocationService::moveSubtree()
2135
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testMoveSubtree
2136
     */
2137
    public function testMoveSubtreeIncrementsChildCountOfNewParent()
2138
    {
2139
        $repository = $this->getRepository();
2140
        $locationService = $repository->getLocationService();
2141
2142
        $newParentLocation = $locationService->loadLocation($this->generateId('location', 56));
2143
2144
        // Load expected properties before move
2145
        $expected = $this->loadLocationProperties($newParentLocation);
2146
        $childCountBefore = $locationService->getLocationChildCount($newParentLocation);
2147
2148
        $mediaLocationId = $this->generateId('location', 43);
2149
        $demoDesignLocationId = $this->generateId('location', 56);
2150
        /* BEGIN: Use Case */
2151
        // $mediaLocationId is the ID of the "Media" page location in
2152
        // an eZ Publish demo installation
2153
2154
        // $demoDesignLocationId is the ID of the "Demo Design" page location in an eZ
2155
        // Publish demo installation
2156
2157
        // Load the location service
2158
        $locationService = $repository->getLocationService();
2159
2160
        // Load location to move
2161
        $locationToMove = $locationService->loadLocation($mediaLocationId);
2162
2163
        // Load new parent location
2164
        $newParentLocation = $locationService->loadLocation($demoDesignLocationId);
2165
2166
        // Move location from "Home" to "Demo Design"
2167
        $locationService->moveSubtree(
2168
            $locationToMove,
2169
            $newParentLocation
2170
        );
2171
2172
        // Load moved location
2173
        $movedLocation = $locationService->loadLocation($mediaLocationId);
2174
2175
        // Reload new parent location
2176
        $newParentLocation = $locationService->loadLocation($demoDesignLocationId);
2177
        /* END: Use Case */
2178
2179
        $this->refreshSearch($repository);
2180
2181
        // Load Subtree properties after move
2182
        $actual = $this->loadLocationProperties($newParentLocation);
2183
        $childCountAfter = $locationService->getLocationChildCount($newParentLocation);
2184
2185
        $this->assertEquals($expected, $actual);
2186
        $this->assertEquals($childCountBefore + 1, $childCountAfter);
2187
    }
2188
2189
    /**
2190
     * Test for the moveSubtree() method.
@@ 2195-2245 (lines=51) @@
2192
     * @see \eZ\Publish\API\Repository\LocationService::moveSubtree()
2193
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testMoveSubtree
2194
     */
2195
    public function testMoveSubtreeDecrementsChildCountOfOldParent()
2196
    {
2197
        $repository = $this->getRepository();
2198
        $locationService = $repository->getLocationService();
2199
2200
        $oldParentLocation = $locationService->loadLocation($this->generateId('location', 1));
2201
2202
        // Load expected properties before move
2203
        $expected = $this->loadLocationProperties($oldParentLocation);
2204
        $childCountBefore = $locationService->getLocationChildCount($oldParentLocation);
2205
2206
        $mediaLocationId = $this->generateId('location', 43);
2207
        $demoDesignLocationId = $this->generateId('location', 56);
2208
        /* BEGIN: Use Case */
2209
        // $mediaLocationId is the ID of the "Media" page location in
2210
        // an eZ Publish demo installation
2211
2212
        // $demoDesignLocationId is the ID of the "Demo Design" page location in an eZ
2213
        // Publish demo installation
2214
2215
        // Load the location service
2216
        $locationService = $repository->getLocationService();
2217
2218
        // Load location to move
2219
        $locationToMove = $locationService->loadLocation($mediaLocationId);
2220
2221
        // Get the location id of the old parent
2222
        $oldParentLocationId = $locationToMove->parentLocationId;
2223
2224
        // Load new parent location
2225
        $newParentLocation = $locationService->loadLocation($demoDesignLocationId);
2226
2227
        // Move location from "Home" to "Demo Design"
2228
        $locationService->moveSubtree(
2229
            $locationToMove,
2230
            $newParentLocation
2231
        );
2232
2233
        // Reload old parent location
2234
        $oldParentLocation = $locationService->loadLocation($oldParentLocationId);
2235
        /* END: Use Case */
2236
2237
        $this->refreshSearch($repository);
2238
2239
        // Load Subtree properties after move
2240
        $actual = $this->loadLocationProperties($oldParentLocation);
2241
        $childCountAfter = $locationService->getLocationChildCount($oldParentLocation);
2242
2243
        $this->assertEquals($expected, $actual);
2244
        $this->assertEquals($childCountBefore - 1, $childCountAfter);
2245
    }
2246
2247
    /**
2248
     * Test for the moveSubtree() method.