Code Duplication    Length = 51-51 lines in 2 locations

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

@@ 2184-2234 (lines=51) @@
2181
     * @see \eZ\Publish\API\Repository\LocationService::moveSubtree()
2182
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testMoveSubtree
2183
     */
2184
    public function testMoveSubtreeIncrementsChildCountOfNewParent()
2185
    {
2186
        $repository = $this->getRepository();
2187
        $locationService = $repository->getLocationService();
2188
2189
        $newParentLocation = $locationService->loadLocation($this->generateId('location', 56));
2190
2191
        // Load expected properties before move
2192
        $expected = $this->loadLocationProperties($newParentLocation);
2193
        $childCountBefore = $locationService->getLocationChildCount($newParentLocation);
2194
2195
        $mediaLocationId = $this->generateId('location', 43);
2196
        $demoDesignLocationId = $this->generateId('location', 56);
2197
        /* BEGIN: Use Case */
2198
        // $mediaLocationId is the ID of the "Media" page location in
2199
        // an eZ Publish demo installation
2200
2201
        // $demoDesignLocationId is the ID of the "Demo Design" page location in an eZ
2202
        // Publish demo installation
2203
2204
        // Load the location service
2205
        $locationService = $repository->getLocationService();
2206
2207
        // Load location to move
2208
        $locationToMove = $locationService->loadLocation($mediaLocationId);
2209
2210
        // Load new parent location
2211
        $newParentLocation = $locationService->loadLocation($demoDesignLocationId);
2212
2213
        // Move location from "Home" to "Demo Design"
2214
        $locationService->moveSubtree(
2215
            $locationToMove,
2216
            $newParentLocation
2217
        );
2218
2219
        // Load moved location
2220
        $movedLocation = $locationService->loadLocation($mediaLocationId);
2221
2222
        // Reload new parent location
2223
        $newParentLocation = $locationService->loadLocation($demoDesignLocationId);
2224
        /* END: Use Case */
2225
2226
        $this->refreshSearch($repository);
2227
2228
        // Load Subtree properties after move
2229
        $actual = $this->loadLocationProperties($newParentLocation);
2230
        $childCountAfter = $locationService->getLocationChildCount($newParentLocation);
2231
2232
        $this->assertEquals($expected, $actual);
2233
        $this->assertEquals($childCountBefore + 1, $childCountAfter);
2234
    }
2235
2236
    /**
2237
     * Test for the moveSubtree() method.
@@ 2242-2292 (lines=51) @@
2239
     * @see \eZ\Publish\API\Repository\LocationService::moveSubtree()
2240
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testMoveSubtree
2241
     */
2242
    public function testMoveSubtreeDecrementsChildCountOfOldParent()
2243
    {
2244
        $repository = $this->getRepository();
2245
        $locationService = $repository->getLocationService();
2246
2247
        $oldParentLocation = $locationService->loadLocation($this->generateId('location', 1));
2248
2249
        // Load expected properties before move
2250
        $expected = $this->loadLocationProperties($oldParentLocation);
2251
        $childCountBefore = $locationService->getLocationChildCount($oldParentLocation);
2252
2253
        $mediaLocationId = $this->generateId('location', 43);
2254
        $demoDesignLocationId = $this->generateId('location', 56);
2255
        /* BEGIN: Use Case */
2256
        // $mediaLocationId is the ID of the "Media" page location in
2257
        // an eZ Publish demo installation
2258
2259
        // $demoDesignLocationId is the ID of the "Demo Design" page location in an eZ
2260
        // Publish demo installation
2261
2262
        // Load the location service
2263
        $locationService = $repository->getLocationService();
2264
2265
        // Load location to move
2266
        $locationToMove = $locationService->loadLocation($mediaLocationId);
2267
2268
        // Get the location id of the old parent
2269
        $oldParentLocationId = $locationToMove->parentLocationId;
2270
2271
        // Load new parent location
2272
        $newParentLocation = $locationService->loadLocation($demoDesignLocationId);
2273
2274
        // Move location from "Home" to "Demo Design"
2275
        $locationService->moveSubtree(
2276
            $locationToMove,
2277
            $newParentLocation
2278
        );
2279
2280
        // Reload old parent location
2281
        $oldParentLocation = $locationService->loadLocation($oldParentLocationId);
2282
        /* END: Use Case */
2283
2284
        $this->refreshSearch($repository);
2285
2286
        // Load Subtree properties after move
2287
        $actual = $this->loadLocationProperties($oldParentLocation);
2288
        $childCountAfter = $locationService->getLocationChildCount($oldParentLocation);
2289
2290
        $this->assertEquals($expected, $actual);
2291
        $this->assertEquals($childCountBefore - 1, $childCountAfter);
2292
    }
2293
2294
    /**
2295
     * Test for the moveSubtree() method.