Code Duplication    Length = 22-30 lines in 3 locations

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

@@ 2614-2639 (lines=26) @@
2611
     * @covers \eZ\Publish\API\Repository\LocationService::moveSubtree
2612
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocation
2613
     */
2614
    public function testMoveSubtreeThrowsExceptionOnMoveNotIntoContainer(): void
2615
    {
2616
        $repository = $this->getRepository();
2617
2618
        $mediaLocationId = $this->generateId('location', 43);
2619
        $demoDesignLocationId = $this->generateId('location', 56);
2620
        /* BEGIN: Use Case */
2621
        // $mediaLocationId is the ID of the "Media" page location in
2622
        // an eZ Publish demo installation
2623
2624
        // $demoDesignLocationId is the ID of the "Demo Design" page location in an eZ
2625
        // Publish demo installation
2626
2627
        // Load the location service
2628
        $locationService = $repository->getLocationService();
2629
2630
        // Load location to move
2631
        $locationToMove = $locationService->loadLocation($mediaLocationId);
2632
2633
        // Load new parent location
2634
        $newParentLocation = $locationService->loadLocation($demoDesignLocationId);
2635
2636
        // Move location from "Home" to "Demo Design" (not container)
2637
        $this->expectException(InvalidArgumentException::class);
2638
        $locationService->moveSubtree($locationToMove, $newParentLocation);
2639
    }
2640
2641
    /**
2642
     * Test for the moveSubtree() method.
@@ 2647-2668 (lines=22) @@
2644
     * @covers \eZ\Publish\API\Repository\LocationService::moveSubtree
2645
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocation
2646
     */
2647
    public function testMoveSubtreeThrowsExceptionOnMoveToSame(): void
2648
    {
2649
        $repository = $this->getRepository();
2650
2651
        $mediaLocationId = $this->generateId('location', 43);
2652
        /* BEGIN: Use Case */
2653
        // $mediaLocationId is the ID of the "Media" page location in
2654
        // an eZ Publish demo installation
2655
2656
        // Load the location service
2657
        $locationService = $repository->getLocationService();
2658
2659
        // Load location to move
2660
        $locationToMove = $locationService->loadLocation($mediaLocationId);
2661
2662
        // Load parent location
2663
        $newParentLocation = $locationService->loadLocation($locationToMove->parentLocationId);
2664
2665
        // Move location from "Home" to "Home"
2666
        $this->expectException(InvalidArgumentException::class);
2667
        $locationService->moveSubtree($locationToMove, $newParentLocation);
2668
    }
2669
2670
    /**
2671
     * Test for the moveSubtree() method.
@@ 3011-3040 (lines=30) @@
3008
     *
3009
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testMoveSubtree
3010
     */
3011
    public function testMoveSubtreeThrowsInvalidArgumentException(): void
3012
    {
3013
        $repository = $this->getRepository();
3014
        $mediaLocationId = $this->generateId('location', 43);
3015
        $multimediaLocationId = $this->generateId('location', 53);
3016
3017
        /* BEGIN: Use Case */
3018
        // $mediaLocationId is the ID of the "Media" page location in
3019
        // an eZ Publish demo installation
3020
3021
        // $multimediaLocationId is the ID of the "Multimedia" page location in an eZ
3022
        // Publish demo installation
3023
3024
        // Load the location service
3025
        $locationService = $repository->getLocationService();
3026
3027
        // Load location to move
3028
        $locationToMove = $locationService->loadLocation($mediaLocationId);
3029
3030
        // Load new parent location
3031
        $newParentLocation = $locationService->loadLocation($multimediaLocationId);
3032
3033
        // Throws an exception because new parent location is placed below location to move
3034
        $this->expectException(InvalidArgumentException::class);
3035
        $locationService->moveSubtree(
3036
            $locationToMove,
3037
            $newParentLocation
3038
        );
3039
        /* END: Use Case */
3040
    }
3041
3042
    /**
3043
     * Test that Legacy ezcontentobject_tree.path_identification_string field is correctly updated