Skip to content

Commit 694abf7

Browse files
committed
Failing test for hard-coding 1
1 parent 8dc4d3a commit 694abf7

File tree

1 file changed

+41
-3
lines changed

1 file changed

+41
-3
lines changed

tests/Functional/DbalNestedSetTest.php

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -355,11 +355,8 @@ public function testMoveSubTreeBelowEndParentNode() {
355355
$nodeKey = new NodeKey(7, 1);
356356
$node = $this->nestedSet->getNode($nodeKey);
357357

358-
$this->printTree($this->nestedSet->getTree());
359358
$newRoot = $this->nestedSet->addRootNode(new NodeKey(12, 1));
360-
$this->printTree($this->nestedSet->getTree());
361359
$this->nestedSet->moveSubTreeBelow($newRoot, $node);
362-
$this->printTree($this->nestedSet->getTree());
363360

364361
// Check node is in new position.
365362
$node = $this->nestedSet->getNode($nodeKey);
@@ -386,6 +383,47 @@ public function testMoveSubTreeBelowEndParentNode() {
386383

387384
}
388385

386+
/**
387+
* Tests moving a sub-tree under a brand new child node.
388+
*/
389+
public function testMoveSubTreeBelowEndChildNode() {
390+
391+
$parent = $this->nestedSet->getNode(new NodeKey(1, 1));
392+
$nodeKey = new NodeKey(7, 1);
393+
$node = $this->nestedSet->getNode($nodeKey);
394+
395+
$this->printTree($this->nestedSet->getTree());
396+
$newRoot = $this->nestedSet->addRootNode(new NodeKey(12, 1));
397+
$newChild = $this->nestedSet->addNodeBelow($newRoot, new NodeKey(13, 1));
398+
$this->printTree($this->nestedSet->getTree());
399+
$this->nestedSet->moveSubTreeBelow($newChild, $node);
400+
$this->printTree($this->nestedSet->getTree());
401+
402+
// Check node is in new position.
403+
$node = $this->nestedSet->getNode($nodeKey);
404+
$this->assertEquals(19, $node->getLeft());
405+
$this->assertEquals(24, $node->getRight());
406+
$this->assertEquals(2, $node->getDepth());
407+
408+
// Check children are in new position.
409+
$node = $this->nestedSet->getNode(new NodeKey(10, 1));
410+
$this->assertEquals(20, $node->getLeft());
411+
$this->assertEquals(21, $node->getRight());
412+
$this->assertEquals(3, $node->getDepth());
413+
414+
$node = $this->nestedSet->getNode(new NodeKey(11, 1));
415+
$this->assertEquals(22, $node->getLeft());
416+
$this->assertEquals(23, $node->getRight());
417+
$this->assertEquals(3, $node->getDepth());
418+
419+
// Check old parent is updated.
420+
$node = $this->nestedSet->getNode(new NodeKey(3, 1));
421+
$this->assertEquals(10, $node->getLeft());
422+
$this->assertEquals(15, $node->getRight());
423+
$this->assertEquals(1, $node->getDepth());
424+
425+
}
426+
389427
/**
390428
* Tests moving a sub-tree to the root.
391429
*/

0 commit comments

Comments
 (0)