Code Duplication    Length = 20-29 lines in 5 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/TrashServiceTest.php 1 location

@@ 154-173 (lines=20) @@
151
     * @see \eZ\Publish\API\Repository\TrashService::trash()
152
     * @depends eZ\Publish\API\Repository\Tests\TrashServiceTest::testTrash
153
     */
154
    public function testTrashDecrementsChildCountOnParentLocation()
155
    {
156
        $repository = $this->getRepository();
157
        $locationService = $repository->getLocationService();
158
159
        $baseLocationId = $this->generateId('location', 1);
160
161
        $location = $locationService->loadLocation($baseLocationId);
162
163
        $childCount = $locationService->getLocationChildCount($location);
164
165
        $this->createTrashItem();
166
167
        $this->refreshSearch($repository);
168
169
        $this->assertEquals(
170
            $childCount - 1,
171
            $locationService->getLocationChildCount($location)
172
        );
173
    }
174
175
    /**
176
     * Test sending a location to trash updates Content mainLocation.

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

@@ 1205-1224 (lines=20) @@
1202
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocation
1203
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
1204
     */
1205
    public function testUpdateLocationThrowsInvalidArgumentException()
1206
    {
1207
        $repository = $this->getRepository();
1208
1209
        $locationId = $this->generateId('location', 5);
1210
        /* BEGIN: Use Case */
1211
        // $locationId and remoteId is the IDs of an existing, but not the same, location
1212
        $locationService = $repository->getLocationService();
1213
1214
        $originalLocation = $locationService->loadLocation($locationId);
1215
1216
        $updateStruct = $locationService->newLocationUpdateStruct();
1217
1218
        // Remote ID of an existing location with a different locationId
1219
        $updateStruct->remoteId = 'f3e90596361e31d496d4026eb624c983';
1220
1221
        // Throws exception, since remote ID is already taken
1222
        $locationService->updateLocation($originalLocation, $updateStruct);
1223
        /* END: Use Case */
1224
    }
1225
1226
    /**
1227
     * Test for the updateLocation() method.
@@ 2003-2029 (lines=27) @@
2000
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
2001
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testCopySubtree
2002
     */
2003
    public function testCopySubtreeThrowsInvalidArgumentException()
2004
    {
2005
        $repository = $this->getRepository();
2006
2007
        $communityLocationId = $this->generateId('location', 5);
2008
        /* BEGIN: Use Case */
2009
        // $communityLocationId is the ID of the "Community" page location in
2010
        // an eZ Publish demo installation
2011
2012
        // Load the location service
2013
        $locationService = $repository->getLocationService();
2014
2015
        // Load location to copy
2016
        $locationToCopy = $locationService->loadLocation($communityLocationId);
2017
2018
        // Use a child as new parent
2019
        $childLocations = $locationService->loadLocationChildren($locationToCopy)->locations;
2020
        $newParentLocation = end($childLocations);
2021
2022
        // This call will fail with an "InvalidArgumentException", because the
2023
        // new parent is a child location of the subtree to copy.
2024
        $locationService->copySubtree(
2025
            $locationToCopy,
2026
            $newParentLocation
2027
        );
2028
        /* END: Use Case */
2029
    }
2030
2031
    /**
2032
     * Test for the moveSubtree() method.
@@ 2382-2410 (lines=29) @@
2379
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testMoveSubtree
2380
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
2381
     */
2382
    public function testMoveSubtreeThrowsInvalidArgumentException()
2383
    {
2384
        $repository = $this->getRepository();
2385
        $mediaLocationId = $this->generateId('location', 43);
2386
        $multimediaLocationId = $this->generateId('location', 53);
2387
2388
        /* BEGIN: Use Case */
2389
        // $mediaLocationId is the ID of the "Media" page location in
2390
        // an eZ Publish demo installation
2391
2392
        // $multimediaLocationId is the ID of the "Multimedia" page location in an eZ
2393
        // Publish demo installation
2394
2395
        // Load the location service
2396
        $locationService = $repository->getLocationService();
2397
2398
        // Load location to move
2399
        $locationToMove = $locationService->loadLocation($mediaLocationId);
2400
2401
        // Load new parent location
2402
        $newParentLocation = $locationService->loadLocation($multimediaLocationId);
2403
2404
        // Throws an exception because new parent location is placed below location to move
2405
        $locationService->moveSubtree(
2406
            $locationToMove,
2407
            $newParentLocation
2408
        );
2409
        /* END: Use Case */
2410
    }
2411
2412
    /**
2413
     * Loads properties from all locations in the $location's subtree.