Skip to content
Browse files

Added test case for TreeBehavior::recover(). Refs #2392

  • Loading branch information...
1 parent 248a2d3 commit 1358af783bb685366f491845111354f581db77db @ADmad ADmad committed Dec 18, 2011
Showing with 51 additions and 0 deletions.
  1. +51 −0 lib/Cake/Test/Case/Model/Behavior/TreeBehaviorNumberTest.php
View
51 lib/Cake/Test/Case/Model/Behavior/TreeBehaviorNumberTest.php
@@ -174,6 +174,57 @@ public function testDetectNoneExistantParent() {
}
/**
+ * 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
*
* @return void

0 comments on commit 1358af7

Please sign in to comment.
Something went wrong with that request. Please try again.