Code Duplication    Length = 51-51 lines in 2 locations

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

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