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