@@ 2727-2777 (lines=51) @@ | ||
2724 | * @see \eZ\Publish\API\Repository\LocationService::moveSubtree() |
|
2725 | * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testMoveSubtree |
|
2726 | */ |
|
2727 | public function testMoveSubtreeIncrementsChildCountOfNewParent() |
|
2728 | { |
|
2729 | $repository = $this->getRepository(); |
|
2730 | $locationService = $repository->getLocationService(); |
|
2731 | ||
2732 | $newParentLocation = $locationService->loadLocation($this->generateId('location', 56)); |
|
2733 | ||
2734 | // Load expected properties before move |
|
2735 | $expected = $this->loadLocationProperties($newParentLocation); |
|
2736 | $childCountBefore = $locationService->getLocationChildCount($newParentLocation); |
|
2737 | ||
2738 | $mediaLocationId = $this->generateId('location', 43); |
|
2739 | $demoDesignLocationId = $this->generateId('location', 56); |
|
2740 | /* BEGIN: Use Case */ |
|
2741 | // $mediaLocationId is the ID of the "Media" page location in |
|
2742 | // an eZ Publish demo installation |
|
2743 | ||
2744 | // $demoDesignLocationId is the ID of the "Demo Design" page location in an eZ |
|
2745 | // Publish demo installation |
|
2746 | ||
2747 | // Load the location service |
|
2748 | $locationService = $repository->getLocationService(); |
|
2749 | ||
2750 | // Load location to move |
|
2751 | $locationToMove = $locationService->loadLocation($mediaLocationId); |
|
2752 | ||
2753 | // Load new parent location |
|
2754 | $newParentLocation = $locationService->loadLocation($demoDesignLocationId); |
|
2755 | ||
2756 | // Move location from "Home" to "Demo Design" |
|
2757 | $locationService->moveSubtree( |
|
2758 | $locationToMove, |
|
2759 | $newParentLocation |
|
2760 | ); |
|
2761 | ||
2762 | // Load moved location |
|
2763 | $movedLocation = $locationService->loadLocation($mediaLocationId); |
|
2764 | ||
2765 | // Reload new parent location |
|
2766 | $newParentLocation = $locationService->loadLocation($demoDesignLocationId); |
|
2767 | /* END: Use Case */ |
|
2768 | ||
2769 | $this->refreshSearch($repository); |
|
2770 | ||
2771 | // Load Subtree properties after move |
|
2772 | $actual = $this->loadLocationProperties($newParentLocation); |
|
2773 | $childCountAfter = $locationService->getLocationChildCount($newParentLocation); |
|
2774 | ||
2775 | $this->assertEquals($expected, $actual); |
|
2776 | $this->assertEquals($childCountBefore + 1, $childCountAfter); |
|
2777 | } |
|
2778 | ||
2779 | /** |
|
2780 | * Test for the moveSubtree() method. |
|
@@ 2785-2835 (lines=51) @@ | ||
2782 | * @see \eZ\Publish\API\Repository\LocationService::moveSubtree() |
|
2783 | * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testMoveSubtree |
|
2784 | */ |
|
2785 | public function testMoveSubtreeDecrementsChildCountOfOldParent() |
|
2786 | { |
|
2787 | $repository = $this->getRepository(); |
|
2788 | $locationService = $repository->getLocationService(); |
|
2789 | ||
2790 | $oldParentLocation = $locationService->loadLocation($this->generateId('location', 1)); |
|
2791 | ||
2792 | // Load expected properties before move |
|
2793 | $expected = $this->loadLocationProperties($oldParentLocation); |
|
2794 | $childCountBefore = $locationService->getLocationChildCount($oldParentLocation); |
|
2795 | ||
2796 | $mediaLocationId = $this->generateId('location', 43); |
|
2797 | $demoDesignLocationId = $this->generateId('location', 56); |
|
2798 | /* BEGIN: Use Case */ |
|
2799 | // $mediaLocationId is the ID of the "Media" page location in |
|
2800 | // an eZ Publish demo installation |
|
2801 | ||
2802 | // $demoDesignLocationId is the ID of the "Demo Design" page location in an eZ |
|
2803 | // Publish demo installation |
|
2804 | ||
2805 | // Load the location service |
|
2806 | $locationService = $repository->getLocationService(); |
|
2807 | ||
2808 | // Load location to move |
|
2809 | $locationToMove = $locationService->loadLocation($mediaLocationId); |
|
2810 | ||
2811 | // Get the location id of the old parent |
|
2812 | $oldParentLocationId = $locationToMove->parentLocationId; |
|
2813 | ||
2814 | // Load new parent location |
|
2815 | $newParentLocation = $locationService->loadLocation($demoDesignLocationId); |
|
2816 | ||
2817 | // Move location from "Home" to "Demo Design" |
|
2818 | $locationService->moveSubtree( |
|
2819 | $locationToMove, |
|
2820 | $newParentLocation |
|
2821 | ); |
|
2822 | ||
2823 | // Reload old parent location |
|
2824 | $oldParentLocation = $locationService->loadLocation($oldParentLocationId); |
|
2825 | /* END: Use Case */ |
|
2826 | ||
2827 | $this->refreshSearch($repository); |
|
2828 | ||
2829 | // Load Subtree properties after move |
|
2830 | $actual = $this->loadLocationProperties($oldParentLocation); |
|
2831 | $childCountAfter = $locationService->getLocationChildCount($oldParentLocation); |
|
2832 | ||
2833 | $this->assertEquals($expected, $actual); |
|
2834 | $this->assertEquals($childCountBefore - 1, $childCountAfter); |
|
2835 | } |
|
2836 | ||
2837 | /** |
|
2838 | * Test moving invisible (hidden by parent) subtree. |