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

@@ 1191-1210 (lines=20) @@
1188
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocation
1189
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
1190
     */
1191
    public function testUpdateLocationThrowsInvalidArgumentException()
1192
    {
1193
        $repository = $this->getRepository();
1194
1195
        $locationId = $this->generateId('location', 5);
1196
        /* BEGIN: Use Case */
1197
        // $locationId and remoteId is the IDs of an existing, but not the same, location
1198
        $locationService = $repository->getLocationService();
1199
1200
        $originalLocation = $locationService->loadLocation($locationId);
1201
1202
        $updateStruct = $locationService->newLocationUpdateStruct();
1203
1204
        // Remote ID of an existing location with a different locationId
1205
        $updateStruct->remoteId = 'f3e90596361e31d496d4026eb624c983';
1206
1207
        // Throws exception, since remote ID is already taken
1208
        $locationService->updateLocation($originalLocation, $updateStruct);
1209
        /* END: Use Case */
1210
    }
1211
1212
    /**
1213
     * Test for the updateLocation() method.
@@ 1989-2015 (lines=27) @@
1986
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
1987
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testCopySubtree
1988
     */
1989
    public function testCopySubtreeThrowsInvalidArgumentException()
1990
    {
1991
        $repository = $this->getRepository();
1992
1993
        $communityLocationId = $this->generateId('location', 5);
1994
        /* BEGIN: Use Case */
1995
        // $communityLocationId is the ID of the "Community" page location in
1996
        // an eZ Publish demo installation
1997
1998
        // Load the location service
1999
        $locationService = $repository->getLocationService();
2000
2001
        // Load location to copy
2002
        $locationToCopy = $locationService->loadLocation($communityLocationId);
2003
2004
        // Use a child as new parent
2005
        $childLocations = $locationService->loadLocationChildren($locationToCopy)->locations;
2006
        $newParentLocation = end($childLocations);
2007
2008
        // This call will fail with an "InvalidArgumentException", because the
2009
        // new parent is a child location of the subtree to copy.
2010
        $locationService->copySubtree(
2011
            $locationToCopy,
2012
            $newParentLocation
2013
        );
2014
        /* END: Use Case */
2015
    }
2016
2017
    /**
2018
     * Test for the moveSubtree() method.
@@ 2368-2396 (lines=29) @@
2365
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testMoveSubtree
2366
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
2367
     */
2368
    public function testMoveSubtreeThrowsInvalidArgumentException()
2369
    {
2370
        $repository = $this->getRepository();
2371
        $mediaLocationId = $this->generateId('location', 43);
2372
        $multimediaLocationId = $this->generateId('location', 53);
2373
2374
        /* BEGIN: Use Case */
2375
        // $mediaLocationId is the ID of the "Media" page location in
2376
        // an eZ Publish demo installation
2377
2378
        // $multimediaLocationId is the ID of the "Multimedia" page location in an eZ
2379
        // Publish demo installation
2380
2381
        // Load the location service
2382
        $locationService = $repository->getLocationService();
2383
2384
        // Load location to move
2385
        $locationToMove = $locationService->loadLocation($mediaLocationId);
2386
2387
        // Load new parent location
2388
        $newParentLocation = $locationService->loadLocation($multimediaLocationId);
2389
2390
        // Throws an exception because new parent location is placed below location to move
2391
        $locationService->moveSubtree(
2392
            $locationToMove,
2393
            $newParentLocation
2394
        );
2395
        /* END: Use Case */
2396
    }
2397
2398
    /**
2399
     * Loads properties from all locations in the $location's subtree.