Skip to content

Commit

Permalink
Added test for removing a root from the tree
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Apr 5, 2014
1 parent 2d7ce70 commit 159eeee
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions tests/TestCase/Model/Behavior/TreeBehaviorTest.php
Expand Up @@ -607,4 +607,30 @@ public function testRemoveMiddleNodeFromTree() {
$this->assertEquals(range(1, 22), $numbers);
}

/**
* Tests removing the root of a tree
*
* @return void
*/
public function testRemoveRootFromTree() {
$table = TableRegistry::get('NumberTrees');
$table->addBehavior('Tree');
$entity = $table->get(1);
$this->assertSame($entity, $table->removeFromTree($entity));
$result = $table->find('threaded')->order('lft')->hydrate(false)->toArray();
$this->assertEquals(21, $entity->lft);
$this->assertEquals(22, $entity->rght);
$this->assertEquals(null, $entity->parent_id);
$result = $table->find()->order('lft')->hydrate(false);
$expected = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 1];
$this->assertEquals($expected, $result->extract('id')->toArray());
$numbers = [];
$result->each(function($v) use (&$numbers) {
$numbers[] = $v['lft'];
$numbers[] = $v['rght'];
});
sort($numbers);
$this->assertEquals(range(1, 22), $numbers);
}

}

0 comments on commit 159eeee

Please sign in to comment.