Code Duplication    Length = 20-29 lines in 4 locations

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

@@ 316-338 (lines=23) @@
313
     * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
314
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testUnhideLocation
315
     */
316
    public function testUnhideLocationThrowsUnauthorizedException()
317
    {
318
        $repository = $this->getRepository();
319
320
        $editorsGroupId = $this->generateId('group', 13);
321
322
        /* BEGIN: Use Case */
323
        $user = $this->createUserVersion1();
324
325
        $locationService = $repository->getLocationService();
326
327
        $visibleLocation = $locationService->loadLocation($editorsGroupId);
328
329
        // Hide location
330
        $hiddenLocation = $locationService->hideLocation($visibleLocation);
331
332
        // Set current user to newly created user
333
        $repository->setCurrentUser($user);
334
335
        // This call will fail with an "UnauthorizedException"
336
        $locationService->unhideLocation($hiddenLocation);
337
        /* END: Use Case */
338
    }
339
340
    /**
341
     * Test for the deleteLocation() method.

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

@@ 1207-1226 (lines=20) @@
1204
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocation
1205
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
1206
     */
1207
    public function testUpdateLocationThrowsInvalidArgumentException()
1208
    {
1209
        $repository = $this->getRepository();
1210
1211
        $locationId = $this->generateId('location', 5);
1212
        /* BEGIN: Use Case */
1213
        // $locationId and remoteId is the IDs of an existing, but not the same, location
1214
        $locationService = $repository->getLocationService();
1215
1216
        $originalLocation = $locationService->loadLocation($locationId);
1217
1218
        $updateStruct = $locationService->newLocationUpdateStruct();
1219
1220
        // Remote ID of an existing location with a different locationId
1221
        $updateStruct->remoteId = 'f3e90596361e31d496d4026eb624c983';
1222
1223
        // Throws exception, since remote ID is already taken
1224
        $locationService->updateLocation($originalLocation, $updateStruct);
1225
        /* END: Use Case */
1226
    }
1227
1228
    /**
1229
     * Test for the updateLocation() method.
@@ 2217-2243 (lines=27) @@
2214
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
2215
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testCopySubtree
2216
     */
2217
    public function testCopySubtreeThrowsInvalidArgumentException()
2218
    {
2219
        $repository = $this->getRepository();
2220
2221
        $communityLocationId = $this->generateId('location', 5);
2222
        /* BEGIN: Use Case */
2223
        // $communityLocationId is the ID of the "Community" page location in
2224
        // an eZ Publish demo installation
2225
2226
        // Load the location service
2227
        $locationService = $repository->getLocationService();
2228
2229
        // Load location to copy
2230
        $locationToCopy = $locationService->loadLocation($communityLocationId);
2231
2232
        // Use a child as new parent
2233
        $childLocations = $locationService->loadLocationChildren($locationToCopy)->locations;
2234
        $newParentLocation = end($childLocations);
2235
2236
        // This call will fail with an "InvalidArgumentException", because the
2237
        // new parent is a child location of the subtree to copy.
2238
        $locationService->copySubtree(
2239
            $locationToCopy,
2240
            $newParentLocation
2241
        );
2242
        /* END: Use Case */
2243
    }
2244
2245
    /**
2246
     * Test for the moveSubtree() method.
@@ 2596-2624 (lines=29) @@
2593
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testMoveSubtree
2594
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
2595
     */
2596
    public function testMoveSubtreeThrowsInvalidArgumentException()
2597
    {
2598
        $repository = $this->getRepository();
2599
        $mediaLocationId = $this->generateId('location', 43);
2600
        $multimediaLocationId = $this->generateId('location', 53);
2601
2602
        /* BEGIN: Use Case */
2603
        // $mediaLocationId is the ID of the "Media" page location in
2604
        // an eZ Publish demo installation
2605
2606
        // $multimediaLocationId is the ID of the "Multimedia" page location in an eZ
2607
        // Publish demo installation
2608
2609
        // Load the location service
2610
        $locationService = $repository->getLocationService();
2611
2612
        // Load location to move
2613
        $locationToMove = $locationService->loadLocation($mediaLocationId);
2614
2615
        // Load new parent location
2616
        $newParentLocation = $locationService->loadLocation($multimediaLocationId);
2617
2618
        // Throws an exception because new parent location is placed below location to move
2619
        $locationService->moveSubtree(
2620
            $locationToMove,
2621
            $newParentLocation
2622
        );
2623
        /* END: Use Case */
2624
    }
2625
2626
    /**
2627
     * Loads properties from all locations in the $location's subtree.