/** * Move a term that has children, to right after the another term that at its right. * * For instance, move 'F' after 'B2', which is a descendant of 'B' * * Before: | After: * root | root * A B C D E (F) G | A B C D E F G * B1 B2 B2 F1 F2 | B1 B2 (F) B3 * ^---------------------+ | F2 F2 */ public function testDescentWithChildrenToSpecifiedTermChildFromRight() { $this->seed('TaxonomySeeder'); $root = Taxonomy::root(); $expect = [['id' => 2, 'name' => 'A', 'code' => 'a', 'left' => 2, 'right' => 3], ['id' => 3, 'name' => 'B', 'code' => 'b', 'left' => 4, 'right' => 17], ['id' => 11, 'name' => 'B1', 'code' => 'b1', 'left' => 5, 'right' => 6], ['id' => 12, 'name' => 'B2', 'code' => 'b2', 'left' => 7, 'right' => 8], ['id' => 7, 'name' => 'F', 'code' => 'f', 'left' => 9, 'right' => 14], ['id' => 9, 'name' => 'F1', 'code' => 'f1', 'left' => 10, 'right' => 11], ['id' => 10, 'name' => 'F2', 'code' => 'f2', 'left' => 12, 'right' => 13], ['id' => 13, 'name' => 'B3', 'code' => 'b3', 'left' => 15, 'right' => 16], ['id' => 4, 'name' => 'C', 'code' => 'c', 'left' => 18, 'right' => 19], ['id' => 5, 'name' => 'D', 'code' => 'd', 'left' => 20, 'right' => 21], ['id' => 6, 'name' => 'E', 'code' => 'e', 'left' => 22, 'right' => 23], ['id' => 8, 'name' => 'G', 'code' => 'g', 'left' => 24, 'right' => 25]]; $root->addTerm('A', 'a'); $b = $root->addTerm('B', 'b'); $root->addTerm('C', 'c'); $root->addTerm('D', 'd'); $root->addTerm('E', 'e'); $f = $root->addTerm('F', 'f'); $root->addTerm('G', 'g'); $f->addTerm('F1', 'f1'); $f->addTerm('F2', 'f2'); $b->addTerm('B1', 'b1'); $b->addTerm('B2', 'b2'); $b->addTerm('B3', 'b3'); Taxonomy::findByCode('f')->moveTo('b', 'b2'); $result = Taxonomy::root()->children()->toArray(); $result = $this->onlyKeys($result, ['id', 'name', 'code', 'left', 'right']); $this->assertTrue($expect === $result); }