Skip to content

Commit

Permalink
Assigning null to parent_id attribute now sets the node as root as we…
Browse files Browse the repository at this point in the history
…ll (performing the same behaviour as 'makeRoot()'). Fixes etrepat#54.
  • Loading branch information
etrepat committed Mar 27, 2014
1 parent 383b0d4 commit a822bfc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
4 changes: 1 addition & 3 deletions src/Baum/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -929,9 +929,7 @@ public function setDefaultLeftAndRight() {
* @return void
*/
public function storeNewParent() {
$dirty = $this->getDirty();

if ( isset($dirty[$this->getParentColumnName()]) )
if ( $this->isDirty($this->getParentColumnName()) )
static::$moveToNewParentId = $this->getParentId();
else
static::$moveToNewParentId = FALSE;
Expand Down
17 changes: 17 additions & 0 deletions tests/BaumTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,23 @@ public function testMakeRoot() {
$this->assertTrue(Category::isValid());
}

public function testNullifyParentColumnMakesItRoot() {
$node = $this->categories('Child 2');

$node->parent_id = null;

$node->save();

$this->assertNull($node->parent()->first());
$this->assertEquals(0, $node->getLevel());
$this->assertEquals(7, $node->getLeft());
$this->assertEquals(10, $node->getRight());

$this->assertEquals(1, $this->categories('Child 2.1')->getLevel());

$this->assertTrue(Category::isValid());
}

public function testMakeChildOf() {
$this->categories('Child 1')->makeChildOf($this->categories('Child 3'));

Expand Down

0 comments on commit a822bfc

Please sign in to comment.