Skip to content

Commit

Permalink
Added test case for TreeBehavior::recover(). Refs #2392
Browse files Browse the repository at this point in the history
  • Loading branch information
ADmad committed Dec 18, 2011
1 parent 248a2d3 commit 1358af7
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions lib/Cake/Test/Case/Model/Behavior/TreeBehaviorNumberTest.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -173,6 +173,57 @@ public function testDetectNoneExistantParent() {
$this->assertSame($result, true); $this->assertSame($result, true);
} }


/**
* testRecoverUsingParentMode method
*
* @return void
*/
public function testRecoverUsingParentMode() {
extract($this->settings);
$this->Tree = new $modelClass();
$this->Tree->Behaviors->disable('Tree');

$this->Tree->save(array('parent_id' => null, 'name' => 'Main', $parentField => null, $leftField => 0, $rightField => 0));
$node1 = $this->Tree->id;

$this->Tree->create();
$this->Tree->save(array('parent_id' => null, 'name' => 'About Us', $parentField => $node1, $leftField => 0, $rightField => 0));
$node11 = $this->Tree->id;
$this->Tree->create();
$this->Tree->save(array('parent_id' => null, 'name' => 'Programs', $parentField => $node1, $leftField => 0, $rightField => 0));
$node12 = $this->Tree->id;
$this->Tree->create();
$this->Tree->save(array('parent_id' => null, 'name' => 'Mission and History', $parentField => $node11, $leftField => 0, $rightField => 0));
$this->Tree->create();
$this->Tree->save(array('parent_id' => null, 'name' => 'Overview', $parentField => $node12, $leftField => 0, $rightField => 0));

$this->Tree->Behaviors->enable('Tree');

$result = $this->Tree->verify();
$this->assertNotSame($result, true);

$result = $this->Tree->recover();
$this->assertTrue($result);

$result = $this->Tree->verify();
$this->assertTrue($result);

$result = $this->Tree->find('first', array(
'fields' => array('name', $parentField, $leftField, $rightField),
'conditions' => array('name' => 'Main'),
'recursive' => -1
));
$expected = array(
$modelClass => array(
'name' => 'Main',
$parentField => null,
$leftField => 1,
$rightField => 10
)
);
$this->assertEquals($expected, $result);
}

/** /**
* testRecoverFromMissingParent method * testRecoverFromMissingParent method
* *
Expand Down

0 comments on commit 1358af7

Please sign in to comment.