Code Duplication    Length = 20-27 lines in 4 locations

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

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

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

@@ 1374-1393 (lines=20) @@
1371
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocation
1372
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
1373
     */
1374
    public function testUpdateLocationThrowsInvalidArgumentException()
1375
    {
1376
        $repository = $this->getRepository();
1377
1378
        $locationId = $this->generateId('location', 5);
1379
        /* BEGIN: Use Case */
1380
        // $locationId and remoteId is the IDs of an existing, but not the same, location
1381
        $locationService = $repository->getLocationService();
1382
1383
        $originalLocation = $locationService->loadLocation($locationId);
1384
1385
        $updateStruct = $locationService->newLocationUpdateStruct();
1386
1387
        // Remote ID of an existing location with a different locationId
1388
        $updateStruct->remoteId = 'f3e90596361e31d496d4026eb624c983';
1389
1390
        // Throws exception, since remote ID is already taken
1391
        $locationService->updateLocation($originalLocation, $updateStruct);
1392
        /* END: Use Case */
1393
    }
1394
1395
    /**
1396
     * Test for the updateLocation() method.
@@ 2495-2521 (lines=27) @@
2492
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
2493
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testCopySubtree
2494
     */
2495
    public function testCopySubtreeThrowsInvalidArgumentException()
2496
    {
2497
        $repository = $this->getRepository();
2498
2499
        $communityLocationId = $this->generateId('location', 5);
2500
        /* BEGIN: Use Case */
2501
        // $communityLocationId is the ID of the "Community" page location in
2502
        // an eZ Publish demo installation
2503
2504
        // Load the location service
2505
        $locationService = $repository->getLocationService();
2506
2507
        // Load location to copy
2508
        $locationToCopy = $locationService->loadLocation($communityLocationId);
2509
2510
        // Use a child as new parent
2511
        $childLocations = $locationService->loadLocationChildren($locationToCopy)->locations;
2512
        $newParentLocation = end($childLocations);
2513
2514
        // This call will fail with an "InvalidArgumentException", because the
2515
        // new parent is a child location of the subtree to copy.
2516
        $locationService->copySubtree(
2517
            $locationToCopy,
2518
            $newParentLocation
2519
        );
2520
        /* END: Use Case */
2521
    }
2522
2523
    /**
2524
     * Test for the moveSubtree() method.
@@ 2612-2633 (lines=22) @@
2609
     * @covers \eZ\Publish\API\Repository\LocationService::moveSubtree
2610
     * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocation
2611
     */
2612
    public function testMoveSubtreeThrowsExceptionOnMoveToSame(): void
2613
    {
2614
        $repository = $this->getRepository();
2615
2616
        $mediaLocationId = $this->generateId('location', 43);
2617
        /* BEGIN: Use Case */
2618
        // $mediaLocationId is the ID of the "Media" page location in
2619
        // an eZ Publish demo installation
2620
2621
        // Load the location service
2622
        $locationService = $repository->getLocationService();
2623
2624
        // Load location to move
2625
        $locationToMove = $locationService->loadLocation($mediaLocationId);
2626
2627
        // Load parent location
2628
        $newParentLocation = $locationService->loadLocation($locationToMove->parentLocationId);
2629
2630
        // Move location from "Home" to "Home"
2631
        $this->expectException(InvalidArgumentException::class);
2632
        $locationService->moveSubtree($locationToMove, $newParentLocation);
2633
    }
2634
2635
    /**
2636
     * Test for the moveSubtree() method.