Code Duplication    Length = 51-51 lines in 2 locations

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

@@ 2329-2379 (lines=51) @@
2326
     * @see \eZ\Publish\API\Repository\LocationService::moveSubtree()
2327
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testMoveSubtree
2328
     */
2329
    public function testMoveSubtreeIncrementsChildCountOfNewParent()
2330
    {
2331
        $repository = $this->getRepository();
2332
        $locationService = $repository->getLocationService();
2333
2334
        $newParentLocation = $locationService->loadLocation($this->generateId('location', 56));
2335
2336
        // Load expected properties before move
2337
        $expected = $this->loadLocationProperties($newParentLocation);
2338
        $childCountBefore = $locationService->getLocationChildCount($newParentLocation);
2339
2340
        $mediaLocationId = $this->generateId('location', 43);
2341
        $demoDesignLocationId = $this->generateId('location', 56);
2342
        /* BEGIN: Use Case */
2343
        // $mediaLocationId is the ID of the "Media" page location in
2344
        // an eZ Publish demo installation
2345
2346
        // $demoDesignLocationId is the ID of the "Demo Design" page location in an eZ
2347
        // Publish demo installation
2348
2349
        // Load the location service
2350
        $locationService = $repository->getLocationService();
2351
2352
        // Load location to move
2353
        $locationToMove = $locationService->loadLocation($mediaLocationId);
2354
2355
        // Load new parent location
2356
        $newParentLocation = $locationService->loadLocation($demoDesignLocationId);
2357
2358
        // Move location from "Home" to "Demo Design"
2359
        $locationService->moveSubtree(
2360
            $locationToMove,
2361
            $newParentLocation
2362
        );
2363
2364
        // Load moved location
2365
        $movedLocation = $locationService->loadLocation($mediaLocationId);
2366
2367
        // Reload new parent location
2368
        $newParentLocation = $locationService->loadLocation($demoDesignLocationId);
2369
        /* END: Use Case */
2370
2371
        $this->refreshSearch($repository);
2372
2373
        // Load Subtree properties after move
2374
        $actual = $this->loadLocationProperties($newParentLocation);
2375
        $childCountAfter = $locationService->getLocationChildCount($newParentLocation);
2376
2377
        $this->assertEquals($expected, $actual);
2378
        $this->assertEquals($childCountBefore + 1, $childCountAfter);
2379
    }
2380
2381
    /**
2382
     * Test for the moveSubtree() method.
@@ 2387-2437 (lines=51) @@
2384
     * @see \eZ\Publish\API\Repository\LocationService::moveSubtree()
2385
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testMoveSubtree
2386
     */
2387
    public function testMoveSubtreeDecrementsChildCountOfOldParent()
2388
    {
2389
        $repository = $this->getRepository();
2390
        $locationService = $repository->getLocationService();
2391
2392
        $oldParentLocation = $locationService->loadLocation($this->generateId('location', 1));
2393
2394
        // Load expected properties before move
2395
        $expected = $this->loadLocationProperties($oldParentLocation);
2396
        $childCountBefore = $locationService->getLocationChildCount($oldParentLocation);
2397
2398
        $mediaLocationId = $this->generateId('location', 43);
2399
        $demoDesignLocationId = $this->generateId('location', 56);
2400
        /* BEGIN: Use Case */
2401
        // $mediaLocationId is the ID of the "Media" page location in
2402
        // an eZ Publish demo installation
2403
2404
        // $demoDesignLocationId is the ID of the "Demo Design" page location in an eZ
2405
        // Publish demo installation
2406
2407
        // Load the location service
2408
        $locationService = $repository->getLocationService();
2409
2410
        // Load location to move
2411
        $locationToMove = $locationService->loadLocation($mediaLocationId);
2412
2413
        // Get the location id of the old parent
2414
        $oldParentLocationId = $locationToMove->parentLocationId;
2415
2416
        // Load new parent location
2417
        $newParentLocation = $locationService->loadLocation($demoDesignLocationId);
2418
2419
        // Move location from "Home" to "Demo Design"
2420
        $locationService->moveSubtree(
2421
            $locationToMove,
2422
            $newParentLocation
2423
        );
2424
2425
        // Reload old parent location
2426
        $oldParentLocation = $locationService->loadLocation($oldParentLocationId);
2427
        /* END: Use Case */
2428
2429
        $this->refreshSearch($repository);
2430
2431
        // Load Subtree properties after move
2432
        $actual = $this->loadLocationProperties($oldParentLocation);
2433
        $childCountAfter = $locationService->getLocationChildCount($oldParentLocation);
2434
2435
        $this->assertEquals($expected, $actual);
2436
        $this->assertEquals($childCountBefore - 1, $childCountAfter);
2437
    }
2438
2439
    /**
2440
     * Test for the moveSubtree() method.