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 90bcb75 commit 482e487
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions cake/tests/cases/libs/model/behaviors/tree.test.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,57 @@ function testDetectNoneExistantParent() {
$this->assertIdentical($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(false);
$this->Tree->save(array('parent_id' => null, 'name' => 'About Us', $parentField => $node1, $leftField => 0, $rightField => 0));
$node11 = $this->Tree->id;
$this->Tree->create(false);
$this->Tree->save(array('parent_id' => null, 'name' => 'Programs', $parentField => $node1, $leftField => 0, $rightField => 0));
$node12 = $this->Tree->id;
$this->Tree->create(false);
$this->Tree->save(array('parent_id' => null, 'name' => 'Mission and History', $parentField => $node11, $leftField => 0, $rightField => 0));
$this->Tree->create(false);
$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->assertNotIdentical($result, false);

$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->assertEqual($expected, $result);
}

/**
* testRecoverFromMissingParent method
*
Expand Down

0 comments on commit 482e487

Please sign in to comment.