Code Duplication    Length = 20-29 lines in 4 locations

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

@@ 1335-1354 (lines=20) @@
1332
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocation
1333
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
1334
     */
1335
    public function testUpdateLocationThrowsInvalidArgumentException()
1336
    {
1337
        $repository = $this->getRepository();
1338
1339
        $locationId = $this->generateId('location', 5);
1340
        /* BEGIN: Use Case */
1341
        // $locationId and remoteId is the IDs of an existing, but not the same, location
1342
        $locationService = $repository->getLocationService();
1343
1344
        $originalLocation = $locationService->loadLocation($locationId);
1345
1346
        $updateStruct = $locationService->newLocationUpdateStruct();
1347
1348
        // Remote ID of an existing location with a different locationId
1349
        $updateStruct->remoteId = 'f3e90596361e31d496d4026eb624c983';
1350
1351
        // Throws exception, since remote ID is already taken
1352
        $locationService->updateLocation($originalLocation, $updateStruct);
1353
        /* END: Use Case */
1354
    }
1355
1356
    /**
1357
     * Test for the updateLocation() method.
@@ 1364-1383 (lines=20) @@
1361
     * @dataProvider dataProviderForOutOfRangeLocationPriority
1362
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
1363
     */
1364
    public function testUpdateLocationThrowsInvalidArgumentExceptionPriorityIsOutOfRange($priority)
1365
    {
1366
        $repository = $this->getRepository();
1367
1368
        $locationId = $this->generateId('location', 5);
1369
        /* BEGIN: Use Case */
1370
        // $locationId and remoteId is the IDs of an existing, but not the same, location
1371
        $locationService = $repository->getLocationService();
1372
1373
        $originalLocation = $locationService->loadLocation($locationId);
1374
1375
        $updateStruct = $locationService->newLocationUpdateStruct();
1376
1377
        // Priority value is out of range
1378
        $updateStruct->priority = $priority;
1379
1380
        // Throws exception, since remote ID is already taken
1381
        $locationService->updateLocation($originalLocation, $updateStruct);
1382
        /* END: Use Case */
1383
    }
1384
1385
    /**
1386
     * Test for the updateLocation() method.
@@ 2388-2414 (lines=27) @@
2385
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
2386
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testCopySubtree
2387
     */
2388
    public function testCopySubtreeThrowsInvalidArgumentException()
2389
    {
2390
        $repository = $this->getRepository();
2391
2392
        $communityLocationId = $this->generateId('location', 5);
2393
        /* BEGIN: Use Case */
2394
        // $communityLocationId is the ID of the "Community" page location in
2395
        // an eZ Publish demo installation
2396
2397
        // Load the location service
2398
        $locationService = $repository->getLocationService();
2399
2400
        // Load location to copy
2401
        $locationToCopy = $locationService->loadLocation($communityLocationId);
2402
2403
        // Use a child as new parent
2404
        $childLocations = $locationService->loadLocationChildren($locationToCopy)->locations;
2405
        $newParentLocation = end($childLocations);
2406
2407
        // This call will fail with an "InvalidArgumentException", because the
2408
        // new parent is a child location of the subtree to copy.
2409
        $locationService->copySubtree(
2410
            $locationToCopy,
2411
            $newParentLocation
2412
        );
2413
        /* END: Use Case */
2414
    }
2415
2416
    /**
2417
     * Test for the moveSubtree() method.
@@ 2808-2836 (lines=29) @@
2805
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testMoveSubtree
2806
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
2807
     */
2808
    public function testMoveSubtreeThrowsInvalidArgumentException()
2809
    {
2810
        $repository = $this->getRepository();
2811
        $mediaLocationId = $this->generateId('location', 43);
2812
        $multimediaLocationId = $this->generateId('location', 53);
2813
2814
        /* BEGIN: Use Case */
2815
        // $mediaLocationId is the ID of the "Media" page location in
2816
        // an eZ Publish demo installation
2817
2818
        // $multimediaLocationId is the ID of the "Multimedia" page location in an eZ
2819
        // Publish demo installation
2820
2821
        // Load the location service
2822
        $locationService = $repository->getLocationService();
2823
2824
        // Load location to move
2825
        $locationToMove = $locationService->loadLocation($mediaLocationId);
2826
2827
        // Load new parent location
2828
        $newParentLocation = $locationService->loadLocation($multimediaLocationId);
2829
2830
        // Throws an exception because new parent location is placed below location to move
2831
        $locationService->moveSubtree(
2832
            $locationToMove,
2833
            $newParentLocation
2834
        );
2835
        /* END: Use Case */
2836
    }
2837
2838
    /**
2839
     * Test that Legacy ezcontentobject_tree.path_identification_string field is correctly updated