From 95522fa3a98d54aac2b262b9a7c991df966c5cfe Mon Sep 17 00:00:00 2001 From: the_undefined Date: Sun, 22 Jun 2008 12:27:54 +0000 Subject: [PATCH] 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 --- cake/libs/model/behaviors/tree.php | 3 +++ .../cases/libs/model/behaviors/tree.test.php | 24 +++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/cake/libs/model/behaviors/tree.php b/cake/libs/model/behaviors/tree.php index 844db147e..8cf3799c8 100644 --- a/cake/libs/model/behaviors/tree.php +++ b/cake/libs/model/behaviors/tree.php @@ -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], diff --git a/cake/tests/cases/libs/model/behaviors/tree.test.php b/cake/tests/cases/libs/model/behaviors/tree.test.php index e33dec56a..6bf12aeb6 100644 --- a/cake/tests/cases/libs/model/behaviors/tree.test.php +++ b/cake/tests/cases/libs/model/behaviors/tree.test.php @@ -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 *