Code Duplication    Length = 51-51 lines in 2 locations

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

@@ 2252-2302 (lines=51) @@
2249
     * @see \eZ\Publish\API\Repository\LocationService::moveSubtree()
2250
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testMoveSubtree
2251
     */
2252
    public function testMoveSubtreeIncrementsChildCountOfNewParent()
2253
    {
2254
        $repository = $this->getRepository();
2255
        $locationService = $repository->getLocationService();
2256
2257
        $newParentLocation = $locationService->loadLocation($this->generateId('location', 56));
2258
2259
        // Load expected properties before move
2260
        $expected = $this->loadLocationProperties($newParentLocation);
2261
        $childCountBefore = $locationService->getLocationChildCount($newParentLocation);
2262
2263
        $mediaLocationId = $this->generateId('location', 43);
2264
        $demoDesignLocationId = $this->generateId('location', 56);
2265
        /* BEGIN: Use Case */
2266
        // $mediaLocationId is the ID of the "Media" page location in
2267
        // an eZ Publish demo installation
2268
2269
        // $demoDesignLocationId is the ID of the "Demo Design" page location in an eZ
2270
        // Publish demo installation
2271
2272
        // Load the location service
2273
        $locationService = $repository->getLocationService();
2274
2275
        // Load location to move
2276
        $locationToMove = $locationService->loadLocation($mediaLocationId);
2277
2278
        // Load new parent location
2279
        $newParentLocation = $locationService->loadLocation($demoDesignLocationId);
2280
2281
        // Move location from "Home" to "Demo Design"
2282
        $locationService->moveSubtree(
2283
            $locationToMove,
2284
            $newParentLocation
2285
        );
2286
2287
        // Load moved location
2288
        $movedLocation = $locationService->loadLocation($mediaLocationId);
2289
2290
        // Reload new parent location
2291
        $newParentLocation = $locationService->loadLocation($demoDesignLocationId);
2292
        /* END: Use Case */
2293
2294
        $this->refreshSearch($repository);
2295
2296
        // Load Subtree properties after move
2297
        $actual = $this->loadLocationProperties($newParentLocation);
2298
        $childCountAfter = $locationService->getLocationChildCount($newParentLocation);
2299
2300
        $this->assertEquals($expected, $actual);
2301
        $this->assertEquals($childCountBefore + 1, $childCountAfter);
2302
    }
2303
2304
    /**
2305
     * Test for the moveSubtree() method.
@@ 2310-2360 (lines=51) @@
2307
     * @see \eZ\Publish\API\Repository\LocationService::moveSubtree()
2308
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testMoveSubtree
2309
     */
2310
    public function testMoveSubtreeDecrementsChildCountOfOldParent()
2311
    {
2312
        $repository = $this->getRepository();
2313
        $locationService = $repository->getLocationService();
2314
2315
        $oldParentLocation = $locationService->loadLocation($this->generateId('location', 1));
2316
2317
        // Load expected properties before move
2318
        $expected = $this->loadLocationProperties($oldParentLocation);
2319
        $childCountBefore = $locationService->getLocationChildCount($oldParentLocation);
2320
2321
        $mediaLocationId = $this->generateId('location', 43);
2322
        $demoDesignLocationId = $this->generateId('location', 56);
2323
        /* BEGIN: Use Case */
2324
        // $mediaLocationId is the ID of the "Media" page location in
2325
        // an eZ Publish demo installation
2326
2327
        // $demoDesignLocationId is the ID of the "Demo Design" page location in an eZ
2328
        // Publish demo installation
2329
2330
        // Load the location service
2331
        $locationService = $repository->getLocationService();
2332
2333
        // Load location to move
2334
        $locationToMove = $locationService->loadLocation($mediaLocationId);
2335
2336
        // Get the location id of the old parent
2337
        $oldParentLocationId = $locationToMove->parentLocationId;
2338
2339
        // Load new parent location
2340
        $newParentLocation = $locationService->loadLocation($demoDesignLocationId);
2341
2342
        // Move location from "Home" to "Demo Design"
2343
        $locationService->moveSubtree(
2344
            $locationToMove,
2345
            $newParentLocation
2346
        );
2347
2348
        // Reload old parent location
2349
        $oldParentLocation = $locationService->loadLocation($oldParentLocationId);
2350
        /* END: Use Case */
2351
2352
        $this->refreshSearch($repository);
2353
2354
        // Load Subtree properties after move
2355
        $actual = $this->loadLocationProperties($oldParentLocation);
2356
        $childCountAfter = $locationService->getLocationChildCount($oldParentLocation);
2357
2358
        $this->assertEquals($expected, $actual);
2359
        $this->assertEquals($childCountBefore - 1, $childCountAfter);
2360
    }
2361
2362
    /**
2363
     * Test for the moveSubtree() method.