Skip to content

Commit 602f0cd

Browse files
committed
Test for moving to new parentnode
1 parent 8c13b99 commit 602f0cd

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

tests/Functional/DbalNestedSetTest.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,46 @@ public function testMoveSubTreeBelow() {
346346

347347
}
348348

349+
/**
350+
* Tests moving a sub-tree under a brand new parent node.
351+
*/
352+
public function testMoveSubTreeBelowEndParentNode() {
353+
354+
$parent = $this->nestedSet->getNode(new NodeKey(1, 1));
355+
$nodeKey = new NodeKey(7, 1);
356+
$node = $this->nestedSet->getNode($nodeKey);
357+
358+
$this->printTree($this->nestedSet->getTree());
359+
$newRoot = $this->nestedSet->addRootNode(new NodeKey(12, 1));
360+
$this->printTree($this->nestedSet->getTree());
361+
$this->nestedSet->moveSubTreeBelow($newRoot, $node);
362+
$this->printTree($this->nestedSet->getTree());
363+
364+
// Check node is in new position.
365+
$node = $this->nestedSet->getNode($nodeKey);
366+
$this->assertEquals(18, $node->getLeft());
367+
$this->assertEquals(23, $node->getRight());
368+
$this->assertEquals(1, $node->getDepth());
369+
370+
// Check children are in new position.
371+
$node = $this->nestedSet->getNode(new NodeKey(10, 1));
372+
$this->assertEquals(19, $node->getLeft());
373+
$this->assertEquals(20, $node->getRight());
374+
$this->assertEquals(2, $node->getDepth());
375+
376+
$node = $this->nestedSet->getNode(new NodeKey(11, 1));
377+
$this->assertEquals(21, $node->getLeft());
378+
$this->assertEquals(22, $node->getRight());
379+
$this->assertEquals(2, $node->getDepth());
380+
381+
// Check old parent is updated.
382+
$node = $this->nestedSet->getNode(new NodeKey(3, 1));
383+
$this->assertEquals(10, $node->getLeft());
384+
$this->assertEquals(15, $node->getRight());
385+
$this->assertEquals(1, $node->getDepth());
386+
387+
}
388+
349389
/**
350390
* Tests moving a sub-tree to the root.
351391
*/

0 commit comments

Comments
 (0)