Code Duplication    Length = 51-51 lines in 2 locations

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

@@ 2563-2613 (lines=51) @@
2560
     * @see \eZ\Publish\API\Repository\LocationService::moveSubtree()
2561
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testMoveSubtree
2562
     */
2563
    public function testMoveSubtreeIncrementsChildCountOfNewParent()
2564
    {
2565
        $repository = $this->getRepository();
2566
        $locationService = $repository->getLocationService();
2567
2568
        $newParentLocation = $locationService->loadLocation($this->generateId('location', 56));
2569
2570
        // Load expected properties before move
2571
        $expected = $this->loadLocationProperties($newParentLocation);
2572
        $childCountBefore = $locationService->getLocationChildCount($newParentLocation);
2573
2574
        $mediaLocationId = $this->generateId('location', 43);
2575
        $demoDesignLocationId = $this->generateId('location', 56);
2576
        /* BEGIN: Use Case */
2577
        // $mediaLocationId is the ID of the "Media" page location in
2578
        // an eZ Publish demo installation
2579
2580
        // $demoDesignLocationId is the ID of the "Demo Design" page location in an eZ
2581
        // Publish demo installation
2582
2583
        // Load the location service
2584
        $locationService = $repository->getLocationService();
2585
2586
        // Load location to move
2587
        $locationToMove = $locationService->loadLocation($mediaLocationId);
2588
2589
        // Load new parent location
2590
        $newParentLocation = $locationService->loadLocation($demoDesignLocationId);
2591
2592
        // Move location from "Home" to "Demo Design"
2593
        $locationService->moveSubtree(
2594
            $locationToMove,
2595
            $newParentLocation
2596
        );
2597
2598
        // Load moved location
2599
        $movedLocation = $locationService->loadLocation($mediaLocationId);
2600
2601
        // Reload new parent location
2602
        $newParentLocation = $locationService->loadLocation($demoDesignLocationId);
2603
        /* END: Use Case */
2604
2605
        $this->refreshSearch($repository);
2606
2607
        // Load Subtree properties after move
2608
        $actual = $this->loadLocationProperties($newParentLocation);
2609
        $childCountAfter = $locationService->getLocationChildCount($newParentLocation);
2610
2611
        $this->assertEquals($expected, $actual);
2612
        $this->assertEquals($childCountBefore + 1, $childCountAfter);
2613
    }
2614
2615
    /**
2616
     * Test for the moveSubtree() method.
@@ 2621-2671 (lines=51) @@
2618
     * @see \eZ\Publish\API\Repository\LocationService::moveSubtree()
2619
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testMoveSubtree
2620
     */
2621
    public function testMoveSubtreeDecrementsChildCountOfOldParent()
2622
    {
2623
        $repository = $this->getRepository();
2624
        $locationService = $repository->getLocationService();
2625
2626
        $oldParentLocation = $locationService->loadLocation($this->generateId('location', 1));
2627
2628
        // Load expected properties before move
2629
        $expected = $this->loadLocationProperties($oldParentLocation);
2630
        $childCountBefore = $locationService->getLocationChildCount($oldParentLocation);
2631
2632
        $mediaLocationId = $this->generateId('location', 43);
2633
        $demoDesignLocationId = $this->generateId('location', 56);
2634
        /* BEGIN: Use Case */
2635
        // $mediaLocationId is the ID of the "Media" page location in
2636
        // an eZ Publish demo installation
2637
2638
        // $demoDesignLocationId is the ID of the "Demo Design" page location in an eZ
2639
        // Publish demo installation
2640
2641
        // Load the location service
2642
        $locationService = $repository->getLocationService();
2643
2644
        // Load location to move
2645
        $locationToMove = $locationService->loadLocation($mediaLocationId);
2646
2647
        // Get the location id of the old parent
2648
        $oldParentLocationId = $locationToMove->parentLocationId;
2649
2650
        // Load new parent location
2651
        $newParentLocation = $locationService->loadLocation($demoDesignLocationId);
2652
2653
        // Move location from "Home" to "Demo Design"
2654
        $locationService->moveSubtree(
2655
            $locationToMove,
2656
            $newParentLocation
2657
        );
2658
2659
        // Reload old parent location
2660
        $oldParentLocation = $locationService->loadLocation($oldParentLocationId);
2661
        /* END: Use Case */
2662
2663
        $this->refreshSearch($repository);
2664
2665
        // Load Subtree properties after move
2666
        $actual = $this->loadLocationProperties($oldParentLocation);
2667
        $childCountAfter = $locationService->getLocationChildCount($oldParentLocation);
2668
2669
        $this->assertEquals($expected, $actual);
2670
        $this->assertEquals($childCountBefore - 1, $childCountAfter);
2671
    }
2672
2673
    /**
2674
     * Test moving invisible (hidden by parent) subtree.