Code Duplication    Length = 20-29 lines in 4 locations

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

@@ 1375-1394 (lines=20) @@
1372
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocation
1373
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
1374
     */
1375
    public function testUpdateLocationThrowsInvalidArgumentException()
1376
    {
1377
        $repository = $this->getRepository();
1378
1379
        $locationId = $this->generateId('location', 5);
1380
        /* BEGIN: Use Case */
1381
        // $locationId and remoteId is the IDs of an existing, but not the same, location
1382
        $locationService = $repository->getLocationService();
1383
1384
        $originalLocation = $locationService->loadLocation($locationId);
1385
1386
        $updateStruct = $locationService->newLocationUpdateStruct();
1387
1388
        // Remote ID of an existing location with a different locationId
1389
        $updateStruct->remoteId = 'f3e90596361e31d496d4026eb624c983';
1390
1391
        // Throws exception, since remote ID is already taken
1392
        $locationService->updateLocation($originalLocation, $updateStruct);
1393
        /* END: Use Case */
1394
    }
1395
1396
    /**
1397
     * Test for the updateLocation() method.
@@ 1404-1423 (lines=20) @@
1401
     * @dataProvider dataProviderForOutOfRangeLocationPriority
1402
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
1403
     */
1404
    public function testUpdateLocationThrowsInvalidArgumentExceptionPriorityIsOutOfRange($priority)
1405
    {
1406
        $repository = $this->getRepository();
1407
1408
        $locationId = $this->generateId('location', 5);
1409
        /* BEGIN: Use Case */
1410
        // $locationId and remoteId is the IDs of an existing, but not the same, location
1411
        $locationService = $repository->getLocationService();
1412
1413
        $originalLocation = $locationService->loadLocation($locationId);
1414
1415
        $updateStruct = $locationService->newLocationUpdateStruct();
1416
1417
        // Priority value is out of range
1418
        $updateStruct->priority = $priority;
1419
1420
        // Throws exception, since remote ID is already taken
1421
        $locationService->updateLocation($originalLocation, $updateStruct);
1422
        /* END: Use Case */
1423
    }
1424
1425
    /**
1426
     * Test for the updateLocation() method.
@@ 2453-2479 (lines=27) @@
2450
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
2451
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testCopySubtree
2452
     */
2453
    public function testCopySubtreeThrowsInvalidArgumentException()
2454
    {
2455
        $repository = $this->getRepository();
2456
2457
        $communityLocationId = $this->generateId('location', 5);
2458
        /* BEGIN: Use Case */
2459
        // $communityLocationId is the ID of the "Community" page location in
2460
        // an eZ Publish demo installation
2461
2462
        // Load the location service
2463
        $locationService = $repository->getLocationService();
2464
2465
        // Load location to copy
2466
        $locationToCopy = $locationService->loadLocation($communityLocationId);
2467
2468
        // Use a child as new parent
2469
        $childLocations = $locationService->loadLocationChildren($locationToCopy)->locations;
2470
        $newParentLocation = end($childLocations);
2471
2472
        // This call will fail with an "InvalidArgumentException", because the
2473
        // new parent is a child location of the subtree to copy.
2474
        $locationService->copySubtree(
2475
            $locationToCopy,
2476
            $newParentLocation
2477
        );
2478
        /* END: Use Case */
2479
    }
2480
2481
    /**
2482
     * Test for the moveSubtree() method.
@@ 2873-2901 (lines=29) @@
2870
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testMoveSubtree
2871
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
2872
     */
2873
    public function testMoveSubtreeThrowsInvalidArgumentException()
2874
    {
2875
        $repository = $this->getRepository();
2876
        $mediaLocationId = $this->generateId('location', 43);
2877
        $multimediaLocationId = $this->generateId('location', 53);
2878
2879
        /* BEGIN: Use Case */
2880
        // $mediaLocationId is the ID of the "Media" page location in
2881
        // an eZ Publish demo installation
2882
2883
        // $multimediaLocationId is the ID of the "Multimedia" page location in an eZ
2884
        // Publish demo installation
2885
2886
        // Load the location service
2887
        $locationService = $repository->getLocationService();
2888
2889
        // Load location to move
2890
        $locationToMove = $locationService->loadLocation($mediaLocationId);
2891
2892
        // Load new parent location
2893
        $newParentLocation = $locationService->loadLocation($multimediaLocationId);
2894
2895
        // Throws an exception because new parent location is placed below location to move
2896
        $locationService->moveSubtree(
2897
            $locationToMove,
2898
            $newParentLocation
2899
        );
2900
        /* END: Use Case */
2901
    }
2902
2903
    /**
2904
     * Test that Legacy ezcontentobject_tree.path_identification_string field is correctly updated