Skip to content

Commit 1bed9b3

Browse files
committed
Fixed root nodes not moving
1 parent d16d9d5 commit 1bed9b3

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

src/NodeTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ public function siblings($dir = null)
312312
$parentId = $this->getParentId();
313313

314314
if (is_null($parentId)) {
315-
$query->whereNull($this->getParentId());
315+
$query->whereNull($this->getParentIdName());
316316
} else {
317317
$query->where($this->getParentIdName(), '=', $parentId);
318318
}

tests/NodeTest.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ public function testDefaultCategoryIsSavedAsRoot()
529529
$node = new Category([ 'name' => 'test' ]);
530530
$node->save();
531531

532-
$this->assertEquals(21, $node->_lft);
532+
$this->assertEquals(23, $node->_lft);
533533
$this->assertTreeNotBroken();
534534

535535
$this->assertTrue($node->isRoot());
@@ -573,7 +573,7 @@ public function testCreatesNode()
573573
{
574574
$node = Category::create([ 'name' => 'test' ]);
575575

576-
$this->assertEquals(21, $node->getLft());
576+
$this->assertEquals(23, $node->getLft());
577577
}
578578

579579
public function testCreatesViaRelationship()
@@ -663,6 +663,14 @@ public function testParentIdDirtiness()
663663

664664
$this->assertTrue($node->isDirty('parent_id'));
665665
}
666+
667+
public function testRootNodesMoving()
668+
{
669+
$node = $this->findCategory('store');
670+
$node->down();
671+
672+
$this->assertEquals(3, $node->getLft());
673+
}
666674
}
667675

668676
function all($items)

tests/data/categories.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@
1111
array('id' => 8, 'name' => 'galaxy', '_lft' => 12, '_rgt' => 13, 'parent_id' => 7),
1212
array('id' => 9, 'name' => 'sony', '_lft' => 15, '_rgt' => 16, 'parent_id' => 5),
1313
array('id' => 10, 'name' => 'lenovo', '_lft' => 17, '_rgt' => 18, 'parent_id' => 5),
14+
array('id' => 11, 'name' => 'store 2', '_lft' => 21, '_rgt' => 22, 'parent_id' => null),
1415
);

0 commit comments

Comments
 (0)