Applied patch by floob, fixes #4876

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7234 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
the_undefined 2008-06-22 12:27:54 +00:00
parent f7c447aa32
commit 95522fa3a9
2 changed files with 27 additions and 0 deletions

View file

@ -769,6 +769,9 @@ class TreeBehavior extends ModelBehavior {
if (is_null($instance[$model->alias][$left]) || is_null($instance[$model->alias][$right])) {
$errors[] = array('node', $instance[$model->alias][$model->primaryKey],
'has invalid left or right values');
} elseif ($instance[$model->alias][$left] == $instance[$model->alias][$right]){
$errors[] = array('node', $instance[$model->alias][$model->primaryKey],
'left and right values identical');
} elseif ($instance[$model->alias][$parent]) {
if (!$instance['VerifyParent'][$model->primaryKey]) {
$errors[] = array('node', $instance[$model->alias][$model->primaryKey],

View file

@ -415,6 +415,30 @@ class NumberTreeCase extends CakeTestCase {
$result = $this->NumberTree->verify();
$this->assertIdentical($result, true);
}
/**
* Reproduces a situation where a single node has lft=rght, and all other lft and rght fields follow sequentially
*
* @access public
* @return void
*/
function testDetectEqualLftsRghts() {
$this->NumberTree =& new NumberTree();
$this->NumberTree->initialize(1, 3);
$result = $this->NumberTree->findByName('1.1');
$this->NumberTree->updateAll(array('rght' => $result['NumberTree']['lft']), array('id' => $result['NumberTree']['id']));
$this->NumberTree->updateAll(array('lft' => 'lft-1'), array('lft >' => $result['NumberTree']['lft']));
$this->NumberTree->updateAll(array('rght' => 'rght-1'), array('rght >' => $result['NumberTree']['lft']));
$result = $this->NumberTree->verify();
$this->assertNotIdentical($result, true);
$result = $this->NumberTree->recover();
$this->assertTrue($result);
$result = $this->NumberTree->verify();
$this->assertTrue($result);
}
/**
* testAddOrphan method
*