Code Duplication    Length = 20-29 lines in 4 locations

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

@@ 1337-1356 (lines=20) @@
1334
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocation
1335
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
1336
     */
1337
    public function testUpdateLocationThrowsInvalidArgumentException()
1338
    {
1339
        $repository = $this->getRepository();
1340
1341
        $locationId = $this->generateId('location', 5);
1342
        /* BEGIN: Use Case */
1343
        // $locationId and remoteId is the IDs of an existing, but not the same, location
1344
        $locationService = $repository->getLocationService();
1345
1346
        $originalLocation = $locationService->loadLocation($locationId);
1347
1348
        $updateStruct = $locationService->newLocationUpdateStruct();
1349
1350
        // Remote ID of an existing location with a different locationId
1351
        $updateStruct->remoteId = 'f3e90596361e31d496d4026eb624c983';
1352
1353
        // Throws exception, since remote ID is already taken
1354
        $locationService->updateLocation($originalLocation, $updateStruct);
1355
        /* END: Use Case */
1356
    }
1357
1358
    /**
1359
     * Test for the updateLocation() method.
@@ 1366-1385 (lines=20) @@
1363
     * @dataProvider dataProviderForOutOfRangeLocationPriority
1364
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
1365
     */
1366
    public function testUpdateLocationThrowsInvalidArgumentExceptionPriorityIsOutOfRange($priority)
1367
    {
1368
        $repository = $this->getRepository();
1369
1370
        $locationId = $this->generateId('location', 5);
1371
        /* BEGIN: Use Case */
1372
        // $locationId and remoteId is the IDs of an existing, but not the same, location
1373
        $locationService = $repository->getLocationService();
1374
1375
        $originalLocation = $locationService->loadLocation($locationId);
1376
1377
        $updateStruct = $locationService->newLocationUpdateStruct();
1378
1379
        // Priority value is out of range
1380
        $updateStruct->priority = $priority;
1381
1382
        // Throws exception, since remote ID is already taken
1383
        $locationService->updateLocation($originalLocation, $updateStruct);
1384
        /* END: Use Case */
1385
    }
1386
1387
    /**
1388
     * Test for the updateLocation() method.
@@ 2415-2441 (lines=27) @@
2412
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
2413
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testCopySubtree
2414
     */
2415
    public function testCopySubtreeThrowsInvalidArgumentException()
2416
    {
2417
        $repository = $this->getRepository();
2418
2419
        $communityLocationId = $this->generateId('location', 5);
2420
        /* BEGIN: Use Case */
2421
        // $communityLocationId is the ID of the "Community" page location in
2422
        // an eZ Publish demo installation
2423
2424
        // Load the location service
2425
        $locationService = $repository->getLocationService();
2426
2427
        // Load location to copy
2428
        $locationToCopy = $locationService->loadLocation($communityLocationId);
2429
2430
        // Use a child as new parent
2431
        $childLocations = $locationService->loadLocationChildren($locationToCopy)->locations;
2432
        $newParentLocation = end($childLocations);
2433
2434
        // This call will fail with an "InvalidArgumentException", because the
2435
        // new parent is a child location of the subtree to copy.
2436
        $locationService->copySubtree(
2437
            $locationToCopy,
2438
            $newParentLocation
2439
        );
2440
        /* END: Use Case */
2441
    }
2442
2443
    /**
2444
     * Test for the moveSubtree() method.
@@ 2835-2863 (lines=29) @@
2832
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testMoveSubtree
2833
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
2834
     */
2835
    public function testMoveSubtreeThrowsInvalidArgumentException()
2836
    {
2837
        $repository = $this->getRepository();
2838
        $mediaLocationId = $this->generateId('location', 43);
2839
        $multimediaLocationId = $this->generateId('location', 53);
2840
2841
        /* BEGIN: Use Case */
2842
        // $mediaLocationId is the ID of the "Media" page location in
2843
        // an eZ Publish demo installation
2844
2845
        // $multimediaLocationId is the ID of the "Multimedia" page location in an eZ
2846
        // Publish demo installation
2847
2848
        // Load the location service
2849
        $locationService = $repository->getLocationService();
2850
2851
        // Load location to move
2852
        $locationToMove = $locationService->loadLocation($mediaLocationId);
2853
2854
        // Load new parent location
2855
        $newParentLocation = $locationService->loadLocation($multimediaLocationId);
2856
2857
        // Throws an exception because new parent location is placed below location to move
2858
        $locationService->moveSubtree(
2859
            $locationToMove,
2860
            $newParentLocation
2861
        );
2862
        /* END: Use Case */
2863
    }
2864
2865
    /**
2866
     * Test that Legacy ezcontentobject_tree.path_identification_string field is correctly updated