Code Duplication    Length = 20-29 lines in 4 locations

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

@@ 1144-1163 (lines=20) @@
1141
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocation
1142
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
1143
     */
1144
    public function testUpdateLocationThrowsInvalidArgumentException()
1145
    {
1146
        $repository = $this->getRepository();
1147
1148
        $locationId = $this->generateId('location', 5);
1149
        /* BEGIN: Use Case */
1150
        // $locationId and remoteId is the IDs of an existing, but not the same, location
1151
        $locationService = $repository->getLocationService();
1152
1153
        $originalLocation = $locationService->loadLocation($locationId);
1154
1155
        $updateStruct = $locationService->newLocationUpdateStruct();
1156
1157
        // Remote ID of an existing location with a different locationId
1158
        $updateStruct->remoteId = 'f3e90596361e31d496d4026eb624c983';
1159
1160
        // Throws exception, since remote ID is already taken
1161
        $locationService->updateLocation($originalLocation, $updateStruct);
1162
        /* END: Use Case */
1163
    }
1164
1165
    /**
1166
     * Test for the updateLocation() method.
@@ 1874-1900 (lines=27) @@
1871
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
1872
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testCopySubtree
1873
     */
1874
    public function testCopySubtreeThrowsInvalidArgumentException()
1875
    {
1876
        $repository = $this->getRepository();
1877
1878
        $communityLocationId = $this->generateId('location', 5);
1879
        /* BEGIN: Use Case */
1880
        // $communityLocationId is the ID of the "Community" page location in
1881
        // an eZ Publish demo installation
1882
1883
        // Load the location service
1884
        $locationService = $repository->getLocationService();
1885
1886
        // Load location to copy
1887
        $locationToCopy = $locationService->loadLocation($communityLocationId);
1888
1889
        // Use a child as new parent
1890
        $childLocations = $locationService->loadLocationChildren($locationToCopy)->locations;
1891
        $newParentLocation = end($childLocations);
1892
1893
        // This call will fail with an "InvalidArgumentException", because the
1894
        // new parent is a child location of the subtree to copy.
1895
        $locationService->copySubtree(
1896
            $locationToCopy,
1897
            $newParentLocation
1898
        );
1899
        /* END: Use Case */
1900
    }
1901
1902
    /**
1903
     * Test for the moveSubtree() method.
@@ 2253-2281 (lines=29) @@
2250
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testMoveSubtree
2251
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
2252
     */
2253
    public function testMoveSubtreeThrowsInvalidArgumentException()
2254
    {
2255
        $repository = $this->getRepository();
2256
        $mediaLocationId = $this->generateId('location', 43);
2257
        $multimediaLocationId = $this->generateId('location', 53);
2258
2259
        /* BEGIN: Use Case */
2260
        // $mediaLocationId is the ID of the "Media" page location in
2261
        // an eZ Publish demo installation
2262
2263
        // $multimediaLocationId is the ID of the "Multimedia" page location in an eZ
2264
        // Publish demo installation
2265
2266
        // Load the location service
2267
        $locationService = $repository->getLocationService();
2268
2269
        // Load location to move
2270
        $locationToMove = $locationService->loadLocation($mediaLocationId);
2271
2272
        // Load new parent location
2273
        $newParentLocation = $locationService->loadLocation($multimediaLocationId);
2274
2275
        // Throws an exception because new parent location is placed below location to move
2276
        $locationService->moveSubtree(
2277
            $locationToMove,
2278
            $newParentLocation
2279
        );
2280
        /* END: Use Case */
2281
    }
2282
2283
    /**
2284
     * Loads properties from all locations in the $location's subtree.

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.