@@ -346,6 +346,81 @@ 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+ $ newRoot = $ this ->nestedSet ->addRootNode (new NodeKey (12 , 1 ));
359+ $ this ->nestedSet ->moveSubTreeBelow ($ newRoot , $ node );
360+
361+ // Check node is in new position.
362+ $ node = $ this ->nestedSet ->getNode ($ nodeKey );
363+ $ this ->assertEquals (18 , $ node ->getLeft ());
364+ $ this ->assertEquals (23 , $ node ->getRight ());
365+ $ this ->assertEquals (1 , $ node ->getDepth ());
366+
367+ // Check children are in new position.
368+ $ node = $ this ->nestedSet ->getNode (new NodeKey (10 , 1 ));
369+ $ this ->assertEquals (19 , $ node ->getLeft ());
370+ $ this ->assertEquals (20 , $ node ->getRight ());
371+ $ this ->assertEquals (2 , $ node ->getDepth ());
372+
373+ $ node = $ this ->nestedSet ->getNode (new NodeKey (11 , 1 ));
374+ $ this ->assertEquals (21 , $ node ->getLeft ());
375+ $ this ->assertEquals (22 , $ node ->getRight ());
376+ $ this ->assertEquals (2 , $ node ->getDepth ());
377+
378+ // Check old parent is updated.
379+ $ node = $ this ->nestedSet ->getNode (new NodeKey (3 , 1 ));
380+ $ this ->assertEquals (10 , $ node ->getLeft ());
381+ $ this ->assertEquals (15 , $ node ->getRight ());
382+ $ this ->assertEquals (1 , $ node ->getDepth ());
383+
384+ }
385+
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+ $ newRoot = $ this ->nestedSet ->addRootNode (new NodeKey (12 , 1 ));
396+ $ newChild = $ this ->nestedSet ->addNodeBelow ($ newRoot , new NodeKey (13 , 1 ));
397+ $ this ->nestedSet ->moveSubTreeBelow ($ newChild , $ node );
398+
399+ // Check node is in new position.
400+ $ node = $ this ->nestedSet ->getNode ($ nodeKey );
401+ $ this ->assertEquals (19 , $ node ->getLeft ());
402+ $ this ->assertEquals (24 , $ node ->getRight ());
403+ $ this ->assertEquals (2 , $ node ->getDepth ());
404+
405+ // Check children are in new position.
406+ $ node = $ this ->nestedSet ->getNode (new NodeKey (10 , 1 ));
407+ $ this ->assertEquals (20 , $ node ->getLeft ());
408+ $ this ->assertEquals (21 , $ node ->getRight ());
409+ $ this ->assertEquals (3 , $ node ->getDepth ());
410+
411+ $ node = $ this ->nestedSet ->getNode (new NodeKey (11 , 1 ));
412+ $ this ->assertEquals (22 , $ node ->getLeft ());
413+ $ this ->assertEquals (23 , $ node ->getRight ());
414+ $ this ->assertEquals (3 , $ node ->getDepth ());
415+
416+ // Check old parent is updated.
417+ $ node = $ this ->nestedSet ->getNode (new NodeKey (3 , 1 ));
418+ $ this ->assertEquals (10 , $ node ->getLeft ());
419+ $ this ->assertEquals (15 , $ node ->getRight ());
420+ $ this ->assertEquals (1 , $ node ->getDepth ());
421+
422+ }
423+
349424 /**
350425 * Tests moving a sub-tree to the root.
351426 */
@@ -461,6 +536,13 @@ public function testValidateTableInvalidFirstChars() {
461536 $ this ->nestedSet = new DbalNestedSet ($ this ->connection , "1abc " );
462537 }
463538
539+ /**
540+ * Test get tree works.
541+ */
542+ public function testGetTree () {
543+ $ this ->assertCount (11 , $ this ->nestedSet ->getTree ());
544+ }
545+
464546 /**
465547 * Loads the test data.
466548 */
0 commit comments