Code Duplication    Length = 20-29 lines in 4 locations

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

@@ 1338-1357 (lines=20) @@
1335
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocation
1336
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
1337
     */
1338
    public function testUpdateLocationThrowsInvalidArgumentException()
1339
    {
1340
        $repository = $this->getRepository();
1341
1342
        $locationId = $this->generateId('location', 5);
1343
        /* BEGIN: Use Case */
1344
        // $locationId and remoteId is the IDs of an existing, but not the same, location
1345
        $locationService = $repository->getLocationService();
1346
1347
        $originalLocation = $locationService->loadLocation($locationId);
1348
1349
        $updateStruct = $locationService->newLocationUpdateStruct();
1350
1351
        // Remote ID of an existing location with a different locationId
1352
        $updateStruct->remoteId = 'f3e90596361e31d496d4026eb624c983';
1353
1354
        // Throws exception, since remote ID is already taken
1355
        $locationService->updateLocation($originalLocation, $updateStruct);
1356
        /* END: Use Case */
1357
    }
1358
1359
    /**
1360
     * Test for the updateLocation() method.
@@ 1367-1386 (lines=20) @@
1364
     * @dataProvider dataProviderForOutOfRangeLocationPriority
1365
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
1366
     */
1367
    public function testUpdateLocationThrowsInvalidArgumentExceptionPriorityIsOutOfRange($priority)
1368
    {
1369
        $repository = $this->getRepository();
1370
1371
        $locationId = $this->generateId('location', 5);
1372
        /* BEGIN: Use Case */
1373
        // $locationId and remoteId is the IDs of an existing, but not the same, location
1374
        $locationService = $repository->getLocationService();
1375
1376
        $originalLocation = $locationService->loadLocation($locationId);
1377
1378
        $updateStruct = $locationService->newLocationUpdateStruct();
1379
1380
        // Priority value is out of range
1381
        $updateStruct->priority = $priority;
1382
1383
        // Throws exception, since remote ID is already taken
1384
        $locationService->updateLocation($originalLocation, $updateStruct);
1385
        /* END: Use Case */
1386
    }
1387
1388
    /**
1389
     * Test for the updateLocation() method.
@@ 2430-2456 (lines=27) @@
2427
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
2428
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testCopySubtree
2429
     */
2430
    public function testCopySubtreeThrowsInvalidArgumentException()
2431
    {
2432
        $repository = $this->getRepository();
2433
2434
        $communityLocationId = $this->generateId('location', 5);
2435
        /* BEGIN: Use Case */
2436
        // $communityLocationId is the ID of the "Community" page location in
2437
        // an eZ Publish demo installation
2438
2439
        // Load the location service
2440
        $locationService = $repository->getLocationService();
2441
2442
        // Load location to copy
2443
        $locationToCopy = $locationService->loadLocation($communityLocationId);
2444
2445
        // Use a child as new parent
2446
        $childLocations = $locationService->loadLocationChildren($locationToCopy)->locations;
2447
        $newParentLocation = end($childLocations);
2448
2449
        // This call will fail with an "InvalidArgumentException", because the
2450
        // new parent is a child location of the subtree to copy.
2451
        $locationService->copySubtree(
2452
            $locationToCopy,
2453
            $newParentLocation
2454
        );
2455
        /* END: Use Case */
2456
    }
2457
2458
    /**
2459
     * Test for the moveSubtree() method.
@@ 2850-2878 (lines=29) @@
2847
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testMoveSubtree
2848
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
2849
     */
2850
    public function testMoveSubtreeThrowsInvalidArgumentException()
2851
    {
2852
        $repository = $this->getRepository();
2853
        $mediaLocationId = $this->generateId('location', 43);
2854
        $multimediaLocationId = $this->generateId('location', 53);
2855
2856
        /* BEGIN: Use Case */
2857
        // $mediaLocationId is the ID of the "Media" page location in
2858
        // an eZ Publish demo installation
2859
2860
        // $multimediaLocationId is the ID of the "Multimedia" page location in an eZ
2861
        // Publish demo installation
2862
2863
        // Load the location service
2864
        $locationService = $repository->getLocationService();
2865
2866
        // Load location to move
2867
        $locationToMove = $locationService->loadLocation($mediaLocationId);
2868
2869
        // Load new parent location
2870
        $newParentLocation = $locationService->loadLocation($multimediaLocationId);
2871
2872
        // Throws an exception because new parent location is placed below location to move
2873
        $locationService->moveSubtree(
2874
            $locationToMove,
2875
            $newParentLocation
2876
        );
2877
        /* END: Use Case */
2878
    }
2879
2880
    /**
2881
     * Test that Legacy ezcontentobject_tree.path_identification_string field is correctly updated