Code Duplication    Length = 20-29 lines in 4 locations

eZ/Publish/API/Repository/Tests/LocationServiceAuthorizationTest.php 1 location

@@ 337-359 (lines=23) @@
334
     * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
335
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testUnhideLocation
336
     */
337
    public function testUnhideLocationThrowsUnauthorizedException()
338
    {
339
        $repository = $this->getRepository();
340
341
        $editorsGroupId = $this->generateId('group', 13);
342
343
        /* BEGIN: Use Case */
344
        $user = $this->createUserVersion1();
345
346
        $locationService = $repository->getLocationService();
347
348
        $visibleLocation = $locationService->loadLocation($editorsGroupId);
349
350
        // Hide location
351
        $hiddenLocation = $locationService->hideLocation($visibleLocation);
352
353
        // Set current user to newly created user
354
        $repository->setCurrentUser($user);
355
356
        // This call will fail with an "UnauthorizedException"
357
        $locationService->unhideLocation($hiddenLocation);
358
        /* END: Use Case */
359
    }
360
361
    /**
362
     * Test for the deleteLocation() method.

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

@@ 1290-1309 (lines=20) @@
1287
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocation
1288
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
1289
     */
1290
    public function testUpdateLocationThrowsInvalidArgumentException()
1291
    {
1292
        $repository = $this->getRepository();
1293
1294
        $locationId = $this->generateId('location', 5);
1295
        /* BEGIN: Use Case */
1296
        // $locationId and remoteId is the IDs of an existing, but not the same, location
1297
        $locationService = $repository->getLocationService();
1298
1299
        $originalLocation = $locationService->loadLocation($locationId);
1300
1301
        $updateStruct = $locationService->newLocationUpdateStruct();
1302
1303
        // Remote ID of an existing location with a different locationId
1304
        $updateStruct->remoteId = 'f3e90596361e31d496d4026eb624c983';
1305
1306
        // Throws exception, since remote ID is already taken
1307
        $locationService->updateLocation($originalLocation, $updateStruct);
1308
        /* END: Use Case */
1309
    }
1310
1311
    /**
1312
     * Test for the updateLocation() method.
@@ 2300-2326 (lines=27) @@
2297
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
2298
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testCopySubtree
2299
     */
2300
    public function testCopySubtreeThrowsInvalidArgumentException()
2301
    {
2302
        $repository = $this->getRepository();
2303
2304
        $communityLocationId = $this->generateId('location', 5);
2305
        /* BEGIN: Use Case */
2306
        // $communityLocationId is the ID of the "Community" page location in
2307
        // an eZ Publish demo installation
2308
2309
        // Load the location service
2310
        $locationService = $repository->getLocationService();
2311
2312
        // Load location to copy
2313
        $locationToCopy = $locationService->loadLocation($communityLocationId);
2314
2315
        // Use a child as new parent
2316
        $childLocations = $locationService->loadLocationChildren($locationToCopy)->locations;
2317
        $newParentLocation = end($childLocations);
2318
2319
        // This call will fail with an "InvalidArgumentException", because the
2320
        // new parent is a child location of the subtree to copy.
2321
        $locationService->copySubtree(
2322
            $locationToCopy,
2323
            $newParentLocation
2324
        );
2325
        /* END: Use Case */
2326
    }
2327
2328
    /**
2329
     * Test for the moveSubtree() method.
@@ 2720-2748 (lines=29) @@
2717
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testMoveSubtree
2718
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
2719
     */
2720
    public function testMoveSubtreeThrowsInvalidArgumentException()
2721
    {
2722
        $repository = $this->getRepository();
2723
        $mediaLocationId = $this->generateId('location', 43);
2724
        $multimediaLocationId = $this->generateId('location', 53);
2725
2726
        /* BEGIN: Use Case */
2727
        // $mediaLocationId is the ID of the "Media" page location in
2728
        // an eZ Publish demo installation
2729
2730
        // $multimediaLocationId is the ID of the "Multimedia" page location in an eZ
2731
        // Publish demo installation
2732
2733
        // Load the location service
2734
        $locationService = $repository->getLocationService();
2735
2736
        // Load location to move
2737
        $locationToMove = $locationService->loadLocation($mediaLocationId);
2738
2739
        // Load new parent location
2740
        $newParentLocation = $locationService->loadLocation($multimediaLocationId);
2741
2742
        // Throws an exception because new parent location is placed below location to move
2743
        $locationService->moveSubtree(
2744
            $locationToMove,
2745
            $newParentLocation
2746
        );
2747
        /* END: Use Case */
2748
    }
2749
2750
    /**
2751
     * Loads properties from all locations in the $location's subtree.