Code Duplication    Length = 51-51 lines in 2 locations

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

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