Code Duplication    Length = 51-51 lines in 2 locations

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

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