@@ -320,29 +320,11 @@ public function testMoveSubTreeBelow() {
320320 $ node = $ this ->nestedSet ->getNode ($ nodeKey );
321321
322322 $ this ->nestedSet ->moveSubTreeBelow ($ parent , $ node );
323+ $ this ->assertNodeMovedBelow ();
323324
324- // Check node is in new position.
325- $ node = $ this ->nestedSet ->getNode ($ nodeKey );
326- $ this ->assertEquals (2 , $ node ->getLeft ());
327- $ this ->assertEquals (7 , $ node ->getRight ());
328- $ this ->assertEquals (1 , $ node ->getDepth ());
329-
330- // Check children are in new position.
331- $ node = $ this ->nestedSet ->getNode (new NodeKey (10 , 1 ));
332- $ this ->assertEquals (3 , $ node ->getLeft ());
333- $ this ->assertEquals (4 , $ node ->getRight ());
334- $ this ->assertEquals (2 , $ node ->getDepth ());
335-
336- $ node = $ this ->nestedSet ->getNode (new NodeKey (11 , 1 ));
337- $ this ->assertEquals (5 , $ node ->getLeft ());
338- $ this ->assertEquals (6 , $ node ->getRight ());
339- $ this ->assertEquals (2 , $ node ->getDepth ());
340-
341- // Check old parent is updated.
342- $ node = $ this ->nestedSet ->getNode (new NodeKey (3 , 1 ));
343- $ this ->assertEquals (16 , $ node ->getLeft ());
344- $ this ->assertEquals (21 , $ node ->getRight ());
345- $ this ->assertEquals (1 , $ node ->getDepth ());
325+ $ node = $ this ->nestedSet ->getNode (new NodeKey (7 , 1 ));
326+ $ this ->nestedSet ->moveSubTreeBelow ($ parent , $ node );
327+ $ this ->assertNodeMovedBelow ();
346328
347329 }
348330
@@ -455,30 +437,14 @@ public function testMoveSubTreeBefore() {
455437 $ node = $ this ->nestedSet ->getNode ($ nodeKey );
456438
457439 $ this ->nestedSet ->moveSubTreeBefore ($ target , $ node );
440+ $ this ->assertNodeMovedBefore ();
458441
442+ $ node = $ this ->nestedSet ->getNode (new NodeKey (7 , 1 ));
459443 // Check node is in new position.
460444 $ node = $ this ->nestedSet ->getNode ($ nodeKey );
461- $ this ->assertEquals (3 , $ node ->getLeft ());
462- $ this ->assertEquals (8 , $ node ->getRight ());
463- $ this ->assertEquals (2 , $ node ->getDepth ());
464-
465- // Check children are in new position.
466- $ node = $ this ->nestedSet ->getNode (new NodeKey (10 , 1 ));
467- $ this ->assertEquals (4 , $ node ->getLeft ());
468- $ this ->assertEquals (5 , $ node ->getRight ());
469- $ this ->assertEquals (3 , $ node ->getDepth ());
470-
471- $ node = $ this ->nestedSet ->getNode (new NodeKey (11 , 1 ));
472- $ this ->assertEquals (6 , $ node ->getLeft ());
473- $ this ->assertEquals (7 , $ node ->getRight ());
474- $ this ->assertEquals (3 , $ node ->getDepth ());
475-
476- // Check old parent is updated.
477- $ node = $ this ->nestedSet ->getNode (new NodeKey (3 , 1 ));
478- $ this ->assertEquals (16 , $ node ->getLeft ());
479- $ this ->assertEquals (21 , $ node ->getRight ());
480- $ this ->assertEquals (1 , $ node ->getDepth ());
481445
446+ $ this ->nestedSet ->moveSubTreeBefore ($ target , $ node );
447+ $ this ->assertNodeMovedBefore ();
482448 }
483449
484450 /**
@@ -659,7 +625,63 @@ public function printTree($tree) {
659625 $ node ->getDepth (),
660626 ]);
661627 }
662- echo $ table ->getTable ();
628+ echo PHP_EOL . $ table ->getTable ();
629+ }
630+
631+ /**
632+ * Assert node correctly moved below.
633+ */
634+ protected function assertNodeMovedBelow () {
635+ // Check node is in new position.
636+ $ node = $ this ->nestedSet ->getNode (new NodeKey (7 , 1 ));
637+ $ this ->assertEquals (2 , $ node ->getLeft ());
638+ $ this ->assertEquals (7 , $ node ->getRight ());
639+ $ this ->assertEquals (1 , $ node ->getDepth ());
640+
641+ // Check children are in new position.
642+ $ node = $ this ->nestedSet ->getNode (new NodeKey (10 , 1 ));
643+ $ this ->assertEquals (3 , $ node ->getLeft ());
644+ $ this ->assertEquals (4 , $ node ->getRight ());
645+ $ this ->assertEquals (2 , $ node ->getDepth ());
646+
647+ $ node = $ this ->nestedSet ->getNode (new NodeKey (11 , 1 ));
648+ $ this ->assertEquals (5 , $ node ->getLeft ());
649+ $ this ->assertEquals (6 , $ node ->getRight ());
650+ $ this ->assertEquals (2 , $ node ->getDepth ());
651+
652+ // Check old parent is updated.
653+ $ node = $ this ->nestedSet ->getNode (new NodeKey (3 , 1 ));
654+ $ this ->assertEquals (16 , $ node ->getLeft ());
655+ $ this ->assertEquals (21 , $ node ->getRight ());
656+ $ this ->assertEquals (1 , $ node ->getDepth ());
657+ }
658+
659+ /**
660+ * Assert node correctly moved before.
661+ */
662+ protected function assertNodeMovedBefore () {
663+ // Check node is in new position.
664+ $ node = $ this ->nestedSet ->getNode (new NodeKey (7 , 1 ));
665+ $ this ->assertEquals (3 , $ node ->getLeft ());
666+ $ this ->assertEquals (8 , $ node ->getRight ());
667+ $ this ->assertEquals (2 , $ node ->getDepth ());
668+
669+ // Check children are in new position.
670+ $ node = $ this ->nestedSet ->getNode (new NodeKey (10 , 1 ));
671+ $ this ->assertEquals (4 , $ node ->getLeft ());
672+ $ this ->assertEquals (5 , $ node ->getRight ());
673+ $ this ->assertEquals (3 , $ node ->getDepth ());
674+
675+ $ node = $ this ->nestedSet ->getNode (new NodeKey (11 , 1 ));
676+ $ this ->assertEquals (6 , $ node ->getLeft ());
677+ $ this ->assertEquals (7 , $ node ->getRight ());
678+ $ this ->assertEquals (3 , $ node ->getDepth ());
679+
680+ // Check old parent is updated.
681+ $ node = $ this ->nestedSet ->getNode (new NodeKey (3 , 1 ));
682+ $ this ->assertEquals (16 , $ node ->getLeft ());
683+ $ this ->assertEquals (21 , $ node ->getRight ());
684+ $ this ->assertEquals (1 , $ node ->getDepth ());
663685 }
664686
665687}
0 commit comments