Code Duplication    Length = 20-29 lines in 4 locations

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

@@ 1311-1330 (lines=20) @@
1308
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocation
1309
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
1310
     */
1311
    public function testUpdateLocationThrowsInvalidArgumentException()
1312
    {
1313
        $repository = $this->getRepository();
1314
1315
        $locationId = $this->generateId('location', 5);
1316
        /* BEGIN: Use Case */
1317
        // $locationId and remoteId is the IDs of an existing, but not the same, location
1318
        $locationService = $repository->getLocationService();
1319
1320
        $originalLocation = $locationService->loadLocation($locationId);
1321
1322
        $updateStruct = $locationService->newLocationUpdateStruct();
1323
1324
        // Remote ID of an existing location with a different locationId
1325
        $updateStruct->remoteId = 'f3e90596361e31d496d4026eb624c983';
1326
1327
        // Throws exception, since remote ID is already taken
1328
        $locationService->updateLocation($originalLocation, $updateStruct);
1329
        /* END: Use Case */
1330
    }
1331
1332
    /**
1333
     * Test for the updateLocation() method.
@@ 1340-1359 (lines=20) @@
1337
     * @dataProvider dataProviderForOutOfRangeLocationPriority
1338
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
1339
     */
1340
    public function testUpdateLocationThrowsInvalidArgumentExceptionPriorityIsOutOfRange($priority)
1341
    {
1342
        $repository = $this->getRepository();
1343
1344
        $locationId = $this->generateId('location', 5);
1345
        /* BEGIN: Use Case */
1346
        // $locationId and remoteId is the IDs of an existing, but not the same, location
1347
        $locationService = $repository->getLocationService();
1348
1349
        $originalLocation = $locationService->loadLocation($locationId);
1350
1351
        $updateStruct = $locationService->newLocationUpdateStruct();
1352
1353
        // Priority value is out of range
1354
        $updateStruct->priority = $priority;
1355
1356
        // Throws exception, since remote ID is already taken
1357
        $locationService->updateLocation($originalLocation, $updateStruct);
1358
        /* END: Use Case */
1359
    }
1360
1361
    /**
1362
     * Test for the updateLocation() method.
@@ 2321-2347 (lines=27) @@
2318
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
2319
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testCopySubtree
2320
     */
2321
    public function testCopySubtreeThrowsInvalidArgumentException()
2322
    {
2323
        $repository = $this->getRepository();
2324
2325
        $communityLocationId = $this->generateId('location', 5);
2326
        /* BEGIN: Use Case */
2327
        // $communityLocationId is the ID of the "Community" page location in
2328
        // an eZ Publish demo installation
2329
2330
        // Load the location service
2331
        $locationService = $repository->getLocationService();
2332
2333
        // Load location to copy
2334
        $locationToCopy = $locationService->loadLocation($communityLocationId);
2335
2336
        // Use a child as new parent
2337
        $childLocations = $locationService->loadLocationChildren($locationToCopy)->locations;
2338
        $newParentLocation = end($childLocations);
2339
2340
        // This call will fail with an "InvalidArgumentException", because the
2341
        // new parent is a child location of the subtree to copy.
2342
        $locationService->copySubtree(
2343
            $locationToCopy,
2344
            $newParentLocation
2345
        );
2346
        /* END: Use Case */
2347
    }
2348
2349
    /**
2350
     * Test for the moveSubtree() method.
@@ 2741-2769 (lines=29) @@
2738
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testMoveSubtree
2739
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
2740
     */
2741
    public function testMoveSubtreeThrowsInvalidArgumentException()
2742
    {
2743
        $repository = $this->getRepository();
2744
        $mediaLocationId = $this->generateId('location', 43);
2745
        $multimediaLocationId = $this->generateId('location', 53);
2746
2747
        /* BEGIN: Use Case */
2748
        // $mediaLocationId is the ID of the "Media" page location in
2749
        // an eZ Publish demo installation
2750
2751
        // $multimediaLocationId is the ID of the "Multimedia" page location in an eZ
2752
        // Publish demo installation
2753
2754
        // Load the location service
2755
        $locationService = $repository->getLocationService();
2756
2757
        // Load location to move
2758
        $locationToMove = $locationService->loadLocation($mediaLocationId);
2759
2760
        // Load new parent location
2761
        $newParentLocation = $locationService->loadLocation($multimediaLocationId);
2762
2763
        // Throws an exception because new parent location is placed below location to move
2764
        $locationService->moveSubtree(
2765
            $locationToMove,
2766
            $newParentLocation
2767
        );
2768
        /* END: Use Case */
2769
    }
2770
2771
    /**
2772
     * Test that Legacy ezcontentobject_tree.path_identification_string field is correctly updated