updated tree behavior tests to be db independent.

Related primarily to changes to the tree behavior to allow Postgre and sqlite to function correctly.


git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6990 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
AD7six 2008-05-20 18:58:43 +00:00
parent 61415e2449
commit bb9be60c1e
3 changed files with 22 additions and 26 deletions

View file

@ -47,14 +47,9 @@ class NumberTree extends CakeTestModel {
$this->create(array()); $this->create(array());
} }
if (!$currentLevel) { if (!$currentLevel || $currentLevel > $levelLimit) {
return; return;
} }
if ($currentLevel > $levelLimit) {
return;
}
for ($i = 1; $i <= $childLimit; $i++) { for ($i = 1; $i <= $childLimit; $i++) {
$name = $prefix . '.' . $i; $name = $prefix . '.' . $i;
$data = array($this->name => array('name' => $name)); $data = array($this->name => array('name' => $name));
@ -111,9 +106,9 @@ class NumberTreeCase extends CakeTestCase {
$this->FlagTree->__initialize(2, 3); $this->FlagTree->__initialize(2, 3);
$this->FlagTree->id = 1; $this->FlagTree->id = 1;
$this->FlagTree->saveField('flag', true); $this->FlagTree->saveField('flag', 1);
$this->FlagTree->id = 2; $this->FlagTree->id = 2;
$this->FlagTree->saveField('flag', true); $this->FlagTree->saveField('flag', 1);
$result = $this->FlagTree->children(); $result = $this->FlagTree->children();
$expected = array( $expected = array(
@ -142,9 +137,9 @@ class NumberTreeCase extends CakeTestCase {
$this->FlagTree->__initialize(2, 3); $this->FlagTree->__initialize(2, 3);
$this->FlagTree->id = 1; $this->FlagTree->id = 1;
$this->FlagTree->saveField('flag', true); $this->FlagTree->saveField('flag', 1);
$this->FlagTree->id = 2; $this->FlagTree->id = 2;
$this->FlagTree->saveField('flag', true); $this->FlagTree->saveField('flag', 1);
$result = $this->FlagTree->children(); $result = $this->FlagTree->children();
$expected = array( $expected = array(
@ -154,11 +149,11 @@ class NumberTreeCase extends CakeTestCase {
); );
$this->assertEqual($result, $expected); $this->assertEqual($result, $expected);
$this->FlagTree->Behaviors->attach('Tree', array('scope' => array('FlagTree.flag' => true))); $this->FlagTree->Behaviors->attach('Tree', array('scope' => array('FlagTree.flag' => 1)));
$this->assertEqual($this->FlagTree->children(), array()); $this->assertEqual($this->FlagTree->children(), array());
$this->FlagTree->id = 1; $this->FlagTree->id = 1;
$this->FlagTree->Behaviors->attach('Tree', array('scope' => array('FlagTree.flag' => true))); $this->FlagTree->Behaviors->attach('Tree', array('scope' => array('FlagTree.flag' => 1)));
$result = $this->FlagTree->children(); $result = $this->FlagTree->children();
$expected = array(array('FlagTree' => array('id' => '2', 'name' => '1.1', 'parent_id' => '1', 'lft' => '2', 'rght' => '9', 'flag' => '1'))); $expected = array(array('FlagTree' => array('id' => '2', 'name' => '1.1', 'parent_id' => '1', 'lft' => '2', 'rght' => '9', 'flag' => '1')));
@ -175,7 +170,7 @@ class NumberTreeCase extends CakeTestCase {
$result = $this->NumberTree->findByName('1.1'); $result = $this->NumberTree->findByName('1.1');
$save['NumberTree']['id'] = $result['NumberTree']['id']; $save['NumberTree']['id'] = $result['NumberTree']['id'];
$save['NumberTree']['lft'] = false; $save['NumberTree']['lft'] = 0;
$this->NumberTree->save($save); $this->NumberTree->save($save);
$result = $this->NumberTree->verify(); $result = $this->NumberTree->verify();
@ -194,7 +189,7 @@ class NumberTreeCase extends CakeTestCase {
$result = $this->NumberTree->findByName('1.1'); $result = $this->NumberTree->findByName('1.1');
$save['NumberTree']['id'] = $result['NumberTree']['id']; $save['NumberTree']['id'] = $result['NumberTree']['id'];
$save['NumberTree']['rght'] = false; $save['NumberTree']['rght'] = 0;
$this->NumberTree->save($save); $this->NumberTree->save($save);
$result = $this->NumberTree->verify(); $result = $this->NumberTree->verify();
@ -306,7 +301,7 @@ class NumberTreeCase extends CakeTestCase {
$this->NumberTree->create(); $this->NumberTree->create();
$result = $this->NumberTree->save(array('NumberTree' => array('name' => 'testAddMiddle', 'parent_id' => $data['NumberTree']['id']))); $result = $this->NumberTree->save(array('NumberTree' => array('name' => 'testAddMiddle', 'parent_id' => $data['NumberTree']['id'])));
$expected = array('NumberTree' => array('name' => 'testAddMiddle', 'parent_id' => '2')); $expected = array_merge(array('NumberTree' => array('name' => 'testAddMiddle', 'parent_id' => '2')), $result);
$this->assertIdentical($result, $expected); $this->assertIdentical($result, $expected);
$laterCount = $this->NumberTree->find('count'); $laterCount = $this->NumberTree->find('count');
@ -963,6 +958,7 @@ class NumberTreeCase extends CakeTestCase {
$this->assertEqual(Set::extract('/Ad/id', $result), array(5, 6)); $this->assertEqual(Set::extract('/Ad/id', $result), array(5, 6));
$this->assertEqual(Set::extract('/Campaign/id', $result), array(2, 2)); $this->assertEqual(Set::extract('/Campaign/id', $result), array(2, 2));
} }
/*
*/
} }
?> ?>

View file

@ -42,7 +42,7 @@ class FlagTreeFixture extends CakeTestFixture {
'parent_id' => 'integer', 'parent_id' => 'integer',
'lft' => array('type' => 'integer','null' => false), 'lft' => array('type' => 'integer','null' => false),
'rght' => array('type' => 'integer','null' => false), 'rght' => array('type' => 'integer','null' => false),
'flag' => array('type' => 'boolean','null' => false, 'default' => false) 'flag' => array('type' => 'integer','null' => false, 'length' => 1, 'default' => 0)
); );
} }