Permalink
Browse files

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
  • Loading branch information...
1 parent f7c447a commit 95522fa3a98d54aac2b262b9a7c991df966c5cfe @felixge felixge committed Jun 22, 2008
Showing with 27 additions and 0 deletions.
  1. +3 −0 cake/libs/model/behaviors/tree.php
  2. +24 −0 cake/tests/cases/libs/model/behaviors/tree.test.php
@@ -769,6 +769,9 @@ function verify(&$model) {
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],
@@ -415,6 +415,30 @@ function testDetectInvalidLftsRghts() {
$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
*

0 comments on commit 95522fa

Please sign in to comment.