Code Duplication    Length = 51-51 lines in 2 locations

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

@@ 2651-2701 (lines=51) @@
2648
     * @see \eZ\Publish\API\Repository\LocationService::moveSubtree()
2649
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testMoveSubtree
2650
     */
2651
    public function testMoveSubtreeIncrementsChildCountOfNewParent()
2652
    {
2653
        $repository = $this->getRepository();
2654
        $locationService = $repository->getLocationService();
2655
2656
        $newParentLocation = $locationService->loadLocation($this->generateId('location', 56));
2657
2658
        // Load expected properties before move
2659
        $expected = $this->loadLocationProperties($newParentLocation);
2660
        $childCountBefore = $locationService->getLocationChildCount($newParentLocation);
2661
2662
        $mediaLocationId = $this->generateId('location', 43);
2663
        $demoDesignLocationId = $this->generateId('location', 56);
2664
        /* BEGIN: Use Case */
2665
        // $mediaLocationId is the ID of the "Media" page location in
2666
        // an eZ Publish demo installation
2667
2668
        // $demoDesignLocationId is the ID of the "Demo Design" page location in an eZ
2669
        // Publish demo installation
2670
2671
        // Load the location service
2672
        $locationService = $repository->getLocationService();
2673
2674
        // Load location to move
2675
        $locationToMove = $locationService->loadLocation($mediaLocationId);
2676
2677
        // Load new parent location
2678
        $newParentLocation = $locationService->loadLocation($demoDesignLocationId);
2679
2680
        // Move location from "Home" to "Demo Design"
2681
        $locationService->moveSubtree(
2682
            $locationToMove,
2683
            $newParentLocation
2684
        );
2685
2686
        // Load moved location
2687
        $movedLocation = $locationService->loadLocation($mediaLocationId);
2688
2689
        // Reload new parent location
2690
        $newParentLocation = $locationService->loadLocation($demoDesignLocationId);
2691
        /* END: Use Case */
2692
2693
        $this->refreshSearch($repository);
2694
2695
        // Load Subtree properties after move
2696
        $actual = $this->loadLocationProperties($newParentLocation);
2697
        $childCountAfter = $locationService->getLocationChildCount($newParentLocation);
2698
2699
        $this->assertEquals($expected, $actual);
2700
        $this->assertEquals($childCountBefore + 1, $childCountAfter);
2701
    }
2702
2703
    /**
2704
     * Test for the moveSubtree() method.
@@ 2709-2759 (lines=51) @@
2706
     * @see \eZ\Publish\API\Repository\LocationService::moveSubtree()
2707
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testMoveSubtree
2708
     */
2709
    public function testMoveSubtreeDecrementsChildCountOfOldParent()
2710
    {
2711
        $repository = $this->getRepository();
2712
        $locationService = $repository->getLocationService();
2713
2714
        $oldParentLocation = $locationService->loadLocation($this->generateId('location', 1));
2715
2716
        // Load expected properties before move
2717
        $expected = $this->loadLocationProperties($oldParentLocation);
2718
        $childCountBefore = $locationService->getLocationChildCount($oldParentLocation);
2719
2720
        $mediaLocationId = $this->generateId('location', 43);
2721
        $demoDesignLocationId = $this->generateId('location', 56);
2722
        /* BEGIN: Use Case */
2723
        // $mediaLocationId is the ID of the "Media" page location in
2724
        // an eZ Publish demo installation
2725
2726
        // $demoDesignLocationId is the ID of the "Demo Design" page location in an eZ
2727
        // Publish demo installation
2728
2729
        // Load the location service
2730
        $locationService = $repository->getLocationService();
2731
2732
        // Load location to move
2733
        $locationToMove = $locationService->loadLocation($mediaLocationId);
2734
2735
        // Get the location id of the old parent
2736
        $oldParentLocationId = $locationToMove->parentLocationId;
2737
2738
        // Load new parent location
2739
        $newParentLocation = $locationService->loadLocation($demoDesignLocationId);
2740
2741
        // Move location from "Home" to "Demo Design"
2742
        $locationService->moveSubtree(
2743
            $locationToMove,
2744
            $newParentLocation
2745
        );
2746
2747
        // Reload old parent location
2748
        $oldParentLocation = $locationService->loadLocation($oldParentLocationId);
2749
        /* END: Use Case */
2750
2751
        $this->refreshSearch($repository);
2752
2753
        // Load Subtree properties after move
2754
        $actual = $this->loadLocationProperties($oldParentLocation);
2755
        $childCountAfter = $locationService->getLocationChildCount($oldParentLocation);
2756
2757
        $this->assertEquals($expected, $actual);
2758
        $this->assertEquals($childCountBefore - 1, $childCountAfter);
2759
    }
2760
2761
    /**
2762
     * Test moving invisible (hidden by parent) subtree.