Skip to content

Commit

Permalink
Test to prove broken tree behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
dakota committed Feb 12, 2016
1 parent 5d29633 commit ee8e168
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions tests/TestCase/ORM/Behavior/TreeBehaviorTest.php
Expand Up @@ -852,6 +852,43 @@ public function testAddLeaf()
$this->assertMpttValues($expected, $this->table);
}

/**
* Tests adding a root element to the tree when all other root elements have children
*
* @return void
*/
public function testAddRoot()
{
$table = $this->table;

//First add a child to the empty root element
$alien = $table->find()->where(['name' => 'alien hardware'])->first();
$entity = new Entity(['name' => 'plasma rifle', 'parent_id' => $alien->id], ['markNew' => true]);
$table->save($entity);

$entity = new Entity(['name' => 'carpentry', 'parent_id' => null], ['markNew' => true]);
$this->assertSame($entity, $table->save($entity));
$this->assertEquals(25, $entity->lft);
$this->assertEquals(26, $entity->rght);

$expected = [
' 1:20 - 1:electronics',
'_ 2: 9 - 2:televisions',
'__ 3: 4 - 3:tube',
'__ 5: 6 - 4:lcd',
'__ 7: 8 - 5:plasma',
'_10:19 - 6:portable',
'__11:14 - 7:mp3',
'___12:13 - 8:flash',
'__15:16 - 9:cd',
'__17:18 - 10:radios',
'21:24 - 11:alien hardware',
'_22:23 - 12:plasma rifle',
'25:26 - 13:carpentry',
];
$this->assertMpttValues($expected, $this->table);
}

/**
* Tests moving a subtree to the right
*
Expand Down

0 comments on commit ee8e168

Please sign in to comment.