|
@@ 2480-2530 (lines=51) @@
|
| 2477 |
|
* @see \eZ\Publish\API\Repository\LocationService::moveSubtree() |
| 2478 |
|
* @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testMoveSubtree |
| 2479 |
|
*/ |
| 2480 |
|
public function testMoveSubtreeIncrementsChildCountOfNewParent() |
| 2481 |
|
{ |
| 2482 |
|
$repository = $this->getRepository(); |
| 2483 |
|
$locationService = $repository->getLocationService(); |
| 2484 |
|
|
| 2485 |
|
$newParentLocation = $locationService->loadLocation($this->generateId('location', 56)); |
| 2486 |
|
|
| 2487 |
|
// Load expected properties before move |
| 2488 |
|
$expected = $this->loadLocationProperties($newParentLocation); |
| 2489 |
|
$childCountBefore = $locationService->getLocationChildCount($newParentLocation); |
| 2490 |
|
|
| 2491 |
|
$mediaLocationId = $this->generateId('location', 43); |
| 2492 |
|
$demoDesignLocationId = $this->generateId('location', 56); |
| 2493 |
|
/* BEGIN: Use Case */ |
| 2494 |
|
// $mediaLocationId is the ID of the "Media" page location in |
| 2495 |
|
// an eZ Publish demo installation |
| 2496 |
|
|
| 2497 |
|
// $demoDesignLocationId is the ID of the "Demo Design" page location in an eZ |
| 2498 |
|
// Publish demo installation |
| 2499 |
|
|
| 2500 |
|
// Load the location service |
| 2501 |
|
$locationService = $repository->getLocationService(); |
| 2502 |
|
|
| 2503 |
|
// Load location to move |
| 2504 |
|
$locationToMove = $locationService->loadLocation($mediaLocationId); |
| 2505 |
|
|
| 2506 |
|
// Load new parent location |
| 2507 |
|
$newParentLocation = $locationService->loadLocation($demoDesignLocationId); |
| 2508 |
|
|
| 2509 |
|
// Move location from "Home" to "Demo Design" |
| 2510 |
|
$locationService->moveSubtree( |
| 2511 |
|
$locationToMove, |
| 2512 |
|
$newParentLocation |
| 2513 |
|
); |
| 2514 |
|
|
| 2515 |
|
// Load moved location |
| 2516 |
|
$movedLocation = $locationService->loadLocation($mediaLocationId); |
| 2517 |
|
|
| 2518 |
|
// Reload new parent location |
| 2519 |
|
$newParentLocation = $locationService->loadLocation($demoDesignLocationId); |
| 2520 |
|
/* END: Use Case */ |
| 2521 |
|
|
| 2522 |
|
$this->refreshSearch($repository); |
| 2523 |
|
|
| 2524 |
|
// Load Subtree properties after move |
| 2525 |
|
$actual = $this->loadLocationProperties($newParentLocation); |
| 2526 |
|
$childCountAfter = $locationService->getLocationChildCount($newParentLocation); |
| 2527 |
|
|
| 2528 |
|
$this->assertEquals($expected, $actual); |
| 2529 |
|
$this->assertEquals($childCountBefore + 1, $childCountAfter); |
| 2530 |
|
} |
| 2531 |
|
|
| 2532 |
|
/** |
| 2533 |
|
* Test for the moveSubtree() method. |
|
@@ 2538-2588 (lines=51) @@
|
| 2535 |
|
* @see \eZ\Publish\API\Repository\LocationService::moveSubtree() |
| 2536 |
|
* @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testMoveSubtree |
| 2537 |
|
*/ |
| 2538 |
|
public function testMoveSubtreeDecrementsChildCountOfOldParent() |
| 2539 |
|
{ |
| 2540 |
|
$repository = $this->getRepository(); |
| 2541 |
|
$locationService = $repository->getLocationService(); |
| 2542 |
|
|
| 2543 |
|
$oldParentLocation = $locationService->loadLocation($this->generateId('location', 1)); |
| 2544 |
|
|
| 2545 |
|
// Load expected properties before move |
| 2546 |
|
$expected = $this->loadLocationProperties($oldParentLocation); |
| 2547 |
|
$childCountBefore = $locationService->getLocationChildCount($oldParentLocation); |
| 2548 |
|
|
| 2549 |
|
$mediaLocationId = $this->generateId('location', 43); |
| 2550 |
|
$demoDesignLocationId = $this->generateId('location', 56); |
| 2551 |
|
/* BEGIN: Use Case */ |
| 2552 |
|
// $mediaLocationId is the ID of the "Media" page location in |
| 2553 |
|
// an eZ Publish demo installation |
| 2554 |
|
|
| 2555 |
|
// $demoDesignLocationId is the ID of the "Demo Design" page location in an eZ |
| 2556 |
|
// Publish demo installation |
| 2557 |
|
|
| 2558 |
|
// Load the location service |
| 2559 |
|
$locationService = $repository->getLocationService(); |
| 2560 |
|
|
| 2561 |
|
// Load location to move |
| 2562 |
|
$locationToMove = $locationService->loadLocation($mediaLocationId); |
| 2563 |
|
|
| 2564 |
|
// Get the location id of the old parent |
| 2565 |
|
$oldParentLocationId = $locationToMove->parentLocationId; |
| 2566 |
|
|
| 2567 |
|
// Load new parent location |
| 2568 |
|
$newParentLocation = $locationService->loadLocation($demoDesignLocationId); |
| 2569 |
|
|
| 2570 |
|
// Move location from "Home" to "Demo Design" |
| 2571 |
|
$locationService->moveSubtree( |
| 2572 |
|
$locationToMove, |
| 2573 |
|
$newParentLocation |
| 2574 |
|
); |
| 2575 |
|
|
| 2576 |
|
// Reload old parent location |
| 2577 |
|
$oldParentLocation = $locationService->loadLocation($oldParentLocationId); |
| 2578 |
|
/* END: Use Case */ |
| 2579 |
|
|
| 2580 |
|
$this->refreshSearch($repository); |
| 2581 |
|
|
| 2582 |
|
// Load Subtree properties after move |
| 2583 |
|
$actual = $this->loadLocationProperties($oldParentLocation); |
| 2584 |
|
$childCountAfter = $locationService->getLocationChildCount($oldParentLocation); |
| 2585 |
|
|
| 2586 |
|
$this->assertEquals($expected, $actual); |
| 2587 |
|
$this->assertEquals($childCountBefore - 1, $childCountAfter); |
| 2588 |
|
} |
| 2589 |
|
|
| 2590 |
|
/** |
| 2591 |
|
* Test for the moveSubtree() method. |