mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-09-07 12:02:41 +00:00
fixes #6003 tree behavior fails with uuids
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7997 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
704188e2b9
commit
b9ea171429
2 changed files with 289 additions and 88 deletions
|
@ -227,7 +227,11 @@ class TreeBehavior extends ModelBehavior {
|
||||||
} elseif (isset($Model->data[$Model->alias][$left]) && isset($Model->data[$Model->alias][$right])) {
|
} elseif (isset($Model->data[$Model->alias][$left]) && isset($Model->data[$Model->alias][$right])) {
|
||||||
$data = $Model->data[$Model->alias];
|
$data = $Model->data[$Model->alias];
|
||||||
} else {
|
} else {
|
||||||
list($data) = array_values($Model->find('first', array('conditions' => array($scope, $Model->escapeField() => $id), 'recursive' => $recursive)));
|
$data = $Model->find('first', array('conditions' => array($scope, $Model->escapeField() => $id), 'recursive' => $recursive));
|
||||||
|
if (!$data) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
$data = $data[$Model->alias];
|
||||||
}
|
}
|
||||||
return ($data[$right] - $data[$left] - 1) / 2;
|
return ($data[$right] - $data[$left] - 1) / 2;
|
||||||
}
|
}
|
||||||
|
@ -591,6 +595,7 @@ class TreeBehavior extends ModelBehavior {
|
||||||
$this->_setParent($Model, $array[$Model->alias][$parent]);
|
$this->_setParent($Model, $array[$Model->alias][$parent]);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
$db =& ConnectionManager::getDataSource($Model->useDbConfig);
|
||||||
foreach ($Model->find('all', array('conditions' => $scope, 'fields' => array($Model->primaryKey, $parent), 'order' => $left)) as $array) {
|
foreach ($Model->find('all', array('conditions' => $scope, 'fields' => array($Model->primaryKey, $parent), 'order' => $left)) as $array) {
|
||||||
$path = $this->getpath($Model, $array[$Model->alias][$Model->primaryKey]);
|
$path = $this->getpath($Model, $array[$Model->alias][$Model->primaryKey]);
|
||||||
if ($path == null || count($path) < 2) {
|
if ($path == null || count($path) < 2) {
|
||||||
|
@ -598,7 +603,7 @@ class TreeBehavior extends ModelBehavior {
|
||||||
} else {
|
} else {
|
||||||
$parentId = $path[count($path) - 2][$Model->alias][$Model->primaryKey];
|
$parentId = $path[count($path) - 2][$Model->alias][$Model->primaryKey];
|
||||||
}
|
}
|
||||||
$Model->updateAll(array($parent => $parentId), array($Model->escapeField() => $array[$Model->alias][$Model->primaryKey]));
|
$Model->updateAll(array($parent => $db->value($parentId, $parent)), array($Model->escapeField() => $array[$Model->alias][$Model->primaryKey]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -679,7 +684,8 @@ class TreeBehavior extends ModelBehavior {
|
||||||
$parentNode[$right] = $node[$right] + 1;
|
$parentNode[$right] = $node[$right] + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
$Model->updateAll(array($parent => $node[$parent]), array($parent => $node[$Model->primaryKey]));
|
$db =& ConnectionManager::getDataSource($Model->useDbConfig);
|
||||||
|
$Model->updateAll(array($parent => $db->value($node[$parent], $parent)), array($parent => $node[$Model->primaryKey]));
|
||||||
$this->__sync($Model, 1, '-', 'BETWEEN ' . ($node[$left] + 1) . ' AND ' . ($node[$right] - 1));
|
$this->__sync($Model, 1, '-', 'BETWEEN ' . ($node[$left] + 1) . ' AND ' . ($node[$right] - 1));
|
||||||
$this->__sync($Model, 2, '-', '> ' . ($node[$right]));
|
$this->__sync($Model, 2, '-', '> ' . ($node[$right]));
|
||||||
$Model->id = $id;
|
$Model->id = $id;
|
||||||
|
|
|
@ -307,8 +307,8 @@ class NumberTreeCase extends CakeTestCase {
|
||||||
|
|
||||||
$children = $this->Tree->children($data[$modelClass]['id'], true, array('name'));
|
$children = $this->Tree->children($data[$modelClass]['id'], true, array('name'));
|
||||||
$expects = array(array($modelClass => array('name' => '1.1.1')),
|
$expects = array(array($modelClass => array('name' => '1.1.1')),
|
||||||
array($modelClass => array('name' => '1.1.2')),
|
array($modelClass => array('name' => '1.1.2')),
|
||||||
array($modelClass => array('name' => 'testAddMiddle')));
|
array($modelClass => array('name' => 'testAddMiddle')));
|
||||||
$this->assertIdentical($children, $expects);
|
$this->assertIdentical($children, $expects);
|
||||||
|
|
||||||
$validTree = $this->Tree->verify();
|
$validTree = $this->Tree->verify();
|
||||||
|
@ -358,8 +358,8 @@ class NumberTreeCase extends CakeTestCase {
|
||||||
$this->Tree->saveField($parentField, $parent_id);
|
$this->Tree->saveField($parentField, $parent_id);
|
||||||
$direct = $this->Tree->children($parent_id, true, array('id', 'name', $parentField, $leftField, $rightField));
|
$direct = $this->Tree->children($parent_id, true, array('id', 'name', $parentField, $leftField, $rightField));
|
||||||
$expects = array(array($modelClass => array('id' => 2, 'name' => '1.1', $parentField => 1, $leftField => 2, $rightField => 5)),
|
$expects = array(array($modelClass => array('id' => 2, 'name' => '1.1', $parentField => 1, $leftField => 2, $rightField => 5)),
|
||||||
array($modelClass => array('id' => 5, 'name' => '1.2', $parentField => 1, $leftField => 6, $rightField => 11)),
|
array($modelClass => array('id' => 5, 'name' => '1.2', $parentField => 1, $leftField => 6, $rightField => 11)),
|
||||||
array($modelClass => array('id' => 3, 'name' => '1.1.1', $parentField => 1, $leftField => 12, $rightField => 13)));
|
array($modelClass => array('id' => 3, 'name' => '1.1.1', $parentField => 1, $leftField => 12, $rightField => 13)));
|
||||||
$this->assertEqual($direct, $expects);
|
$this->assertEqual($direct, $expects);
|
||||||
$validTree = $this->Tree->verify();
|
$validTree = $this->Tree->verify();
|
||||||
$this->assertIdentical($validTree, true);
|
$this->assertIdentical($validTree, true);
|
||||||
|
@ -386,8 +386,8 @@ class NumberTreeCase extends CakeTestCase {
|
||||||
|
|
||||||
$result = $this->Tree->children($parent_id, true, array('id', 'name', $parentField, $leftField, $rightField));
|
$result = $this->Tree->children($parent_id, true, array('id', 'name', $parentField, $leftField, $rightField));
|
||||||
$expected = array(array($modelClass => array('id' => 2, 'name' => '1.1', $parentField => 1, $leftField => 2, $rightField => 5)),
|
$expected = array(array($modelClass => array('id' => 2, 'name' => '1.1', $parentField => 1, $leftField => 2, $rightField => 5)),
|
||||||
array($modelClass => array('id' => 5, 'name' => '1.2', $parentField => 1, $leftField => 6, $rightField => 11)),
|
array($modelClass => array('id' => 5, 'name' => '1.2', $parentField => 1, $leftField => 6, $rightField => 11)),
|
||||||
array($modelClass => array('id' => 3, 'name' => '1.1.1', $parentField => 1, $leftField => 12, $rightField => 13)));
|
array($modelClass => array('id' => 3, 'name' => '1.1.1', $parentField => 1, $leftField => 12, $rightField => 13)));
|
||||||
$this->assertEqual($result, $expected);
|
$this->assertEqual($result, $expected);
|
||||||
$this->assertTrue($this->Tree->verify());
|
$this->assertTrue($this->Tree->verify());
|
||||||
}
|
}
|
||||||
|
@ -430,8 +430,8 @@ class NumberTreeCase extends CakeTestCase {
|
||||||
|
|
||||||
$result = $this->Tree->children($parent_id, true, array('name'));
|
$result = $this->Tree->children($parent_id, true, array('name'));
|
||||||
$expects = array(array($modelClass => array('name' => '1.1.1')),
|
$expects = array(array($modelClass => array('name' => '1.1.1')),
|
||||||
array($modelClass => array('name' => '1.1.2')),
|
array($modelClass => array('name' => '1.1.2')),
|
||||||
array($modelClass => array('name' => '1.2')));
|
array($modelClass => array('name' => '1.2')));
|
||||||
$this->assertEqual($result, $expects);
|
$this->assertEqual($result, $expects);
|
||||||
|
|
||||||
$validTree = $this->Tree->verify();
|
$validTree = $this->Tree->verify();
|
||||||
|
@ -458,8 +458,8 @@ class NumberTreeCase extends CakeTestCase {
|
||||||
|
|
||||||
$result = $this->Tree->children($parent_id, true, array('name'));
|
$result = $this->Tree->children($parent_id, true, array('name'));
|
||||||
$expects = array(array($modelClass => array('name' => '1.2.1')),
|
$expects = array(array($modelClass => array('name' => '1.2.1')),
|
||||||
array($modelClass => array('name' => '1.2.2')),
|
array($modelClass => array('name' => '1.2.2')),
|
||||||
array($modelClass => array('name' => '1.1')));
|
array($modelClass => array('name' => '1.1')));
|
||||||
$this->assertEqual($result, $expects);
|
$this->assertEqual($result, $expects);
|
||||||
|
|
||||||
$validTree = $this->Tree->verify();
|
$validTree = $this->Tree->verify();
|
||||||
|
@ -568,7 +568,7 @@ class NumberTreeCase extends CakeTestCase {
|
||||||
$this->Tree->id = $parent[$modelClass]['id'];
|
$this->Tree->id = $parent[$modelClass]['id'];
|
||||||
$result = $this->Tree->children(null, true, array('name'));
|
$result = $this->Tree->children(null, true, array('name'));
|
||||||
$expected = array(array($modelClass => array('name' => '1.2', )),
|
$expected = array(array($modelClass => array('name' => '1.2', )),
|
||||||
array($modelClass => array('name' => '1.1', )));
|
array($modelClass => array('name' => '1.1', )));
|
||||||
$this->assertIdentical($result, $expected);
|
$this->assertIdentical($result, $expected);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
@ -590,7 +590,7 @@ class NumberTreeCase extends CakeTestCase {
|
||||||
$this->Tree->id = $parent[$modelClass]['id'];
|
$this->Tree->id = $parent[$modelClass]['id'];
|
||||||
$result = $this->Tree->children(null, true, array('name'));
|
$result = $this->Tree->children(null, true, array('name'));
|
||||||
$expected = array(array($modelClass => array('name' => '1.1', )),
|
$expected = array(array($modelClass => array('name' => '1.1', )),
|
||||||
array($modelClass => array('name' => '1.2', )));
|
array($modelClass => array('name' => '1.2', )));
|
||||||
$this->assertIdentical($result, $expected);
|
$this->assertIdentical($result, $expected);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
@ -611,16 +611,16 @@ class NumberTreeCase extends CakeTestCase {
|
||||||
$this->Tree->id = $parent[$modelClass]['id'];
|
$this->Tree->id = $parent[$modelClass]['id'];
|
||||||
$result = $this->Tree->children(null, true, array('name'));
|
$result = $this->Tree->children(null, true, array('name'));
|
||||||
$expected = array(
|
$expected = array(
|
||||||
array($modelClass => array('name' => '1.1', )),
|
array($modelClass => array('name' => '1.1', )),
|
||||||
array($modelClass => array('name' => '1.2', )),
|
array($modelClass => array('name' => '1.2', )),
|
||||||
array($modelClass => array('name' => '1.5', )),
|
array($modelClass => array('name' => '1.5', )),
|
||||||
array($modelClass => array('name' => '1.3', )),
|
array($modelClass => array('name' => '1.3', )),
|
||||||
array($modelClass => array('name' => '1.4', )),
|
array($modelClass => array('name' => '1.4', )),
|
||||||
array($modelClass => array('name' => '1.6', )),
|
array($modelClass => array('name' => '1.6', )),
|
||||||
array($modelClass => array('name' => '1.7', )),
|
array($modelClass => array('name' => '1.7', )),
|
||||||
array($modelClass => array('name' => '1.8', )),
|
array($modelClass => array('name' => '1.8', )),
|
||||||
array($modelClass => array('name' => '1.9', )),
|
array($modelClass => array('name' => '1.9', )),
|
||||||
array($modelClass => array('name' => '1.10', )));
|
array($modelClass => array('name' => '1.10', )));
|
||||||
$this->assertIdentical($result, $expected);
|
$this->assertIdentical($result, $expected);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
@ -641,16 +641,16 @@ class NumberTreeCase extends CakeTestCase {
|
||||||
$this->Tree->id = $parent[$modelClass]['id'];
|
$this->Tree->id = $parent[$modelClass]['id'];
|
||||||
$result = $this->Tree->children(null, true, array('name'));
|
$result = $this->Tree->children(null, true, array('name'));
|
||||||
$expected = array(
|
$expected = array(
|
||||||
array($modelClass => array('name' => '1.5', )),
|
array($modelClass => array('name' => '1.5', )),
|
||||||
array($modelClass => array('name' => '1.1', )),
|
array($modelClass => array('name' => '1.1', )),
|
||||||
array($modelClass => array('name' => '1.2', )),
|
array($modelClass => array('name' => '1.2', )),
|
||||||
array($modelClass => array('name' => '1.3', )),
|
array($modelClass => array('name' => '1.3', )),
|
||||||
array($modelClass => array('name' => '1.4', )),
|
array($modelClass => array('name' => '1.4', )),
|
||||||
array($modelClass => array('name' => '1.6', )),
|
array($modelClass => array('name' => '1.6', )),
|
||||||
array($modelClass => array('name' => '1.7', )),
|
array($modelClass => array('name' => '1.7', )),
|
||||||
array($modelClass => array('name' => '1.8', )),
|
array($modelClass => array('name' => '1.8', )),
|
||||||
array($modelClass => array('name' => '1.9', )),
|
array($modelClass => array('name' => '1.9', )),
|
||||||
array($modelClass => array('name' => '1.10', )));
|
array($modelClass => array('name' => '1.10', )));
|
||||||
$this->assertIdentical($result, $expected);
|
$this->assertIdentical($result, $expected);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
@ -671,7 +671,7 @@ class NumberTreeCase extends CakeTestCase {
|
||||||
$this->Tree->id = $parent[$modelClass]['id'];
|
$this->Tree->id = $parent[$modelClass]['id'];
|
||||||
$result = $this->Tree->children(null, true, array('name'));
|
$result = $this->Tree->children(null, true, array('name'));
|
||||||
$expected = array(array($modelClass => array('name' => '1.2', )),
|
$expected = array(array($modelClass => array('name' => '1.2', )),
|
||||||
array($modelClass => array('name' => '1.1', )));
|
array($modelClass => array('name' => '1.1', )));
|
||||||
$this->assertIdentical($result, $expected);
|
$this->assertIdentical($result, $expected);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
@ -692,7 +692,7 @@ class NumberTreeCase extends CakeTestCase {
|
||||||
$this->Tree->id = $parent[$modelClass]['id'];
|
$this->Tree->id = $parent[$modelClass]['id'];
|
||||||
$result = $this->Tree->children(null, true, array('name'));
|
$result = $this->Tree->children(null, true, array('name'));
|
||||||
$expected = array(array($modelClass => array('name' => '1.1', )),
|
$expected = array(array($modelClass => array('name' => '1.1', )),
|
||||||
array($modelClass => array('name' => '1.2', )));
|
array($modelClass => array('name' => '1.2', )));
|
||||||
$this->assertIdentical($result, $expected);
|
$this->assertIdentical($result, $expected);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
@ -713,16 +713,16 @@ class NumberTreeCase extends CakeTestCase {
|
||||||
$this->Tree->id = $parent[$modelClass]['id'];
|
$this->Tree->id = $parent[$modelClass]['id'];
|
||||||
$result = $this->Tree->children(null, true, array('name'));
|
$result = $this->Tree->children(null, true, array('name'));
|
||||||
$expected = array(
|
$expected = array(
|
||||||
array($modelClass => array('name' => '1.1', )),
|
array($modelClass => array('name' => '1.1', )),
|
||||||
array($modelClass => array('name' => '1.2', )),
|
array($modelClass => array('name' => '1.2', )),
|
||||||
array($modelClass => array('name' => '1.3', )),
|
array($modelClass => array('name' => '1.3', )),
|
||||||
array($modelClass => array('name' => '1.4', )),
|
array($modelClass => array('name' => '1.4', )),
|
||||||
array($modelClass => array('name' => '1.6', )),
|
array($modelClass => array('name' => '1.6', )),
|
||||||
array($modelClass => array('name' => '1.7', )),
|
array($modelClass => array('name' => '1.7', )),
|
||||||
array($modelClass => array('name' => '1.8', )),
|
array($modelClass => array('name' => '1.8', )),
|
||||||
array($modelClass => array('name' => '1.9', )),
|
array($modelClass => array('name' => '1.9', )),
|
||||||
array($modelClass => array('name' => '1.10', )),
|
array($modelClass => array('name' => '1.10', )),
|
||||||
array($modelClass => array('name' => '1.5', )));
|
array($modelClass => array('name' => '1.5', )));
|
||||||
$this->assertIdentical($result, $expected);
|
$this->assertIdentical($result, $expected);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
@ -743,16 +743,16 @@ class NumberTreeCase extends CakeTestCase {
|
||||||
$this->Tree->id = $parent[$modelClass]['id'];
|
$this->Tree->id = $parent[$modelClass]['id'];
|
||||||
$result = $this->Tree->children(null, true, array('name'));
|
$result = $this->Tree->children(null, true, array('name'));
|
||||||
$expected = array(
|
$expected = array(
|
||||||
array($modelClass => array('name' => '1.1', )),
|
array($modelClass => array('name' => '1.1', )),
|
||||||
array($modelClass => array('name' => '1.2', )),
|
array($modelClass => array('name' => '1.2', )),
|
||||||
array($modelClass => array('name' => '1.3', )),
|
array($modelClass => array('name' => '1.3', )),
|
||||||
array($modelClass => array('name' => '1.4', )),
|
array($modelClass => array('name' => '1.4', )),
|
||||||
array($modelClass => array('name' => '1.6', )),
|
array($modelClass => array('name' => '1.6', )),
|
||||||
array($modelClass => array('name' => '1.7', )),
|
array($modelClass => array('name' => '1.7', )),
|
||||||
array($modelClass => array('name' => '1.5', )),
|
array($modelClass => array('name' => '1.5', )),
|
||||||
array($modelClass => array('name' => '1.8', )),
|
array($modelClass => array('name' => '1.8', )),
|
||||||
array($modelClass => array('name' => '1.9', )),
|
array($modelClass => array('name' => '1.9', )),
|
||||||
array($modelClass => array('name' => '1.10', )));
|
array($modelClass => array('name' => '1.10', )));
|
||||||
$this->assertIdentical($result, $expected);
|
$this->assertIdentical($result, $expected);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
@ -773,16 +773,16 @@ class NumberTreeCase extends CakeTestCase {
|
||||||
$this->Tree->id = $parent[$modelClass]['id'];
|
$this->Tree->id = $parent[$modelClass]['id'];
|
||||||
$result = $this->Tree->children(null, true, array('name'));
|
$result = $this->Tree->children(null, true, array('name'));
|
||||||
$expected = array(
|
$expected = array(
|
||||||
array($modelClass => array('name' => '1.1', )),
|
array($modelClass => array('name' => '1.1', )),
|
||||||
array($modelClass => array('name' => '1.2', )),
|
array($modelClass => array('name' => '1.2', )),
|
||||||
array($modelClass => array('name' => '1.3', )),
|
array($modelClass => array('name' => '1.3', )),
|
||||||
array($modelClass => array('name' => '1.4', )),
|
array($modelClass => array('name' => '1.4', )),
|
||||||
array($modelClass => array('name' => 'renamed', )),
|
array($modelClass => array('name' => 'renamed', )),
|
||||||
array($modelClass => array('name' => '1.6', )),
|
array($modelClass => array('name' => '1.6', )),
|
||||||
array($modelClass => array('name' => '1.7', )),
|
array($modelClass => array('name' => '1.7', )),
|
||||||
array($modelClass => array('name' => '1.8', )),
|
array($modelClass => array('name' => '1.8', )),
|
||||||
array($modelClass => array('name' => '1.9', )),
|
array($modelClass => array('name' => '1.9', )),
|
||||||
array($modelClass => array('name' => '1.10', )));
|
array($modelClass => array('name' => '1.10', )));
|
||||||
$this->assertIdentical($result, $expected);
|
$this->assertIdentical($result, $expected);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
@ -806,7 +806,7 @@ class NumberTreeCase extends CakeTestCase {
|
||||||
|
|
||||||
$result = $this->Tree->find('all', array('fields' => 'name', 'order' => $modelClass . '.' . $leftField . ' ASC'));
|
$result = $this->Tree->find('all', array('fields' => 'name', 'order' => $modelClass . '.' . $leftField . ' ASC'));
|
||||||
$expected = array(array($modelClass => array('name' => '1.1')),
|
$expected = array(array($modelClass => array('name' => '1.1')),
|
||||||
array($modelClass => array('name' => '1. Root')));
|
array($modelClass => array('name' => '1. Root')));
|
||||||
$this->assertIdentical($result, $expected);
|
$this->assertIdentical($result, $expected);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
@ -864,13 +864,13 @@ class NumberTreeCase extends CakeTestCase {
|
||||||
|
|
||||||
$children = $this->Tree->children($result[$modelClass][$parentField], true, array('name'));
|
$children = $this->Tree->children($result[$modelClass][$parentField], true, array('name'));
|
||||||
$expects = array(array($modelClass => array('name' => '1.1.1')),
|
$expects = array(array($modelClass => array('name' => '1.1.1')),
|
||||||
array($modelClass => array('name' => '1.1.2')),
|
array($modelClass => array('name' => '1.1.2')),
|
||||||
array($modelClass => array('name' => '1.2')));
|
array($modelClass => array('name' => '1.2')));
|
||||||
$this->assertEqual($children, $expects);
|
$this->assertEqual($children, $expects);
|
||||||
|
|
||||||
$topNodes = $this->Tree->children(false, true,array('name'));
|
$topNodes = $this->Tree->children(false, true,array('name'));
|
||||||
$expects = array(array($modelClass => array('name' => '1. Root')),
|
$expects = array(array($modelClass => array('name' => '1. Root')),
|
||||||
array($modelClass => array('name' => '1.1')));
|
array($modelClass => array('name' => '1.1')));
|
||||||
$this->assertEqual($topNodes, $expects);
|
$this->assertEqual($topNodes, $expects);
|
||||||
|
|
||||||
$validTree = $this->Tree->verify();
|
$validTree = $this->Tree->verify();
|
||||||
|
@ -901,8 +901,8 @@ class NumberTreeCase extends CakeTestCase {
|
||||||
|
|
||||||
$topNodes = $this->Tree->children(false, true,array('name'));
|
$topNodes = $this->Tree->children(false, true,array('name'));
|
||||||
$expects = array(array($modelClass => array('name' => '1.1')),
|
$expects = array(array($modelClass => array('name' => '1.1')),
|
||||||
array($modelClass => array('name' => '1.2')),
|
array($modelClass => array('name' => '1.2')),
|
||||||
array($modelClass => array('name' => '1. Root')));
|
array($modelClass => array('name' => '1. Root')));
|
||||||
|
|
||||||
$this->assertEqual($topNodes, $expects);
|
$this->assertEqual($topNodes, $expects);
|
||||||
|
|
||||||
|
@ -964,8 +964,8 @@ class NumberTreeCase extends CakeTestCase {
|
||||||
|
|
||||||
$children = $this->Tree->children($result[$modelClass][$parentField], true, array('name'), $leftField . ' asc');
|
$children = $this->Tree->children($result[$modelClass][$parentField], true, array('name'), $leftField . ' asc');
|
||||||
$expects= array(array($modelClass => array('name' => '1.1.1')),
|
$expects= array(array($modelClass => array('name' => '1.1.1')),
|
||||||
array($modelClass => array('name' => '1.1.2')),
|
array($modelClass => array('name' => '1.1.2')),
|
||||||
array($modelClass => array('name' => '1.2')));
|
array($modelClass => array('name' => '1.2')));
|
||||||
$this->assertEqual($children, $expects);
|
$this->assertEqual($children, $expects);
|
||||||
|
|
||||||
$topNodes = $this->Tree->children(false, true,array('name'));
|
$topNodes = $this->Tree->children(false, true,array('name'));
|
||||||
|
@ -1007,7 +1007,6 @@ class NumberTreeCase extends CakeTestCase {
|
||||||
$validTree = $this->Tree->verify();
|
$validTree = $this->Tree->verify();
|
||||||
$this->assertIdentical($validTree, true);
|
$this->assertIdentical($validTree, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* testChildren method
|
* testChildren method
|
||||||
*
|
*
|
||||||
|
@ -1024,16 +1023,16 @@ class NumberTreeCase extends CakeTestCase {
|
||||||
|
|
||||||
$direct = $this->Tree->children(null, true, array('id', 'name', $parentField, $leftField, $rightField));
|
$direct = $this->Tree->children(null, true, array('id', 'name', $parentField, $leftField, $rightField));
|
||||||
$expects = array(array($modelClass => array('id' => 2, 'name' => '1.1', $parentField => 1, $leftField => 2, $rightField => 7)),
|
$expects = array(array($modelClass => array('id' => 2, 'name' => '1.1', $parentField => 1, $leftField => 2, $rightField => 7)),
|
||||||
array($modelClass => array('id' => 5, 'name' => '1.2', $parentField => 1, $leftField => 8, $rightField => 13)));
|
array($modelClass => array('id' => 5, 'name' => '1.2', $parentField => 1, $leftField => 8, $rightField => 13)));
|
||||||
$this->assertEqual($direct, $expects);
|
$this->assertEqual($direct, $expects);
|
||||||
|
|
||||||
$total = $this->Tree->children(null, null, array('id', 'name', $parentField, $leftField, $rightField));
|
$total = $this->Tree->children(null, null, array('id', 'name', $parentField, $leftField, $rightField));
|
||||||
$expects = array(array($modelClass => array('id' => 2, 'name' => '1.1', $parentField => 1, $leftField => 2, $rightField => 7)),
|
$expects = array(array($modelClass => array('id' => 2, 'name' => '1.1', $parentField => 1, $leftField => 2, $rightField => 7)),
|
||||||
array($modelClass => array('id' => 3, 'name' => '1.1.1', $parentField => 2, $leftField => 3, $rightField => 4)),
|
array($modelClass => array('id' => 3, 'name' => '1.1.1', $parentField => 2, $leftField => 3, $rightField => 4)),
|
||||||
array($modelClass => array('id' => 4, 'name' => '1.1.2', $parentField => 2, $leftField => 5, $rightField => 6)),
|
array($modelClass => array('id' => 4, 'name' => '1.1.2', $parentField => 2, $leftField => 5, $rightField => 6)),
|
||||||
array($modelClass => array('id' => 5, 'name' => '1.2', $parentField => 1, $leftField => 8, $rightField => 13)),
|
array($modelClass => array('id' => 5, 'name' => '1.2', $parentField => 1, $leftField => 8, $rightField => 13)),
|
||||||
array($modelClass => array( 'id' => 6, 'name' => '1.2.1', $parentField => 5, $leftField => 9, $rightField => 10)),
|
array($modelClass => array( 'id' => 6, 'name' => '1.2.1', $parentField => 5, $leftField => 9, $rightField => 10)),
|
||||||
array($modelClass => array('id' => 7, 'name' => '1.2.2', $parentField => 5, $leftField => 11, $rightField => 12)));
|
array($modelClass => array('id' => 7, 'name' => '1.2.2', $parentField => 5, $leftField => 11, $rightField => 12)));
|
||||||
$this->assertEqual($total, $expects);
|
$this->assertEqual($total, $expects);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
@ -1090,8 +1089,8 @@ class NumberTreeCase extends CakeTestCase {
|
||||||
|
|
||||||
$result = $this->Tree->getPath(null, array('name'));
|
$result = $this->Tree->getPath(null, array('name'));
|
||||||
$expects = array(array($modelClass => array('name' => '1. Root')),
|
$expects = array(array($modelClass => array('name' => '1. Root')),
|
||||||
array($modelClass => array('name' => '1.2')),
|
array($modelClass => array('name' => '1.2')),
|
||||||
array($modelClass => array('name' => '1.2.2')));
|
array($modelClass => array('name' => '1.2.2')));
|
||||||
$this->assertIdentical($result, $expects);
|
$this->assertIdentical($result, $expects);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
@ -1104,7 +1103,7 @@ class NumberTreeCase extends CakeTestCase {
|
||||||
extract($this->settings);
|
extract($this->settings);
|
||||||
$this->Tree =& new $modelClass();
|
$this->Tree =& new $modelClass();
|
||||||
$this->Tree->bindModel(array('belongsTo' => array('Dummy' =>
|
$this->Tree->bindModel(array('belongsTo' => array('Dummy' =>
|
||||||
array('className' => $modelClass, 'foreignKey' => $parentField, 'conditions' => array('Dummy.id' => null)))), false);
|
array('className' => $modelClass, 'foreignKey' => $parentField, 'conditions' => array('Dummy.id' => null)))), false);
|
||||||
$this->Tree->initialize(2, 2);
|
$this->Tree->initialize(2, 2);
|
||||||
|
|
||||||
$data = $this->Tree->find(array($modelClass . '.name' => '1. Root'));
|
$data = $this->Tree->find(array($modelClass . '.name' => '1. Root'));
|
||||||
|
@ -1112,7 +1111,7 @@ class NumberTreeCase extends CakeTestCase {
|
||||||
|
|
||||||
$direct = $this->Tree->children(null, true, array('id', 'name', $parentField, $leftField, $rightField), null, null, null, 1);
|
$direct = $this->Tree->children(null, true, array('id', 'name', $parentField, $leftField, $rightField), null, null, null, 1);
|
||||||
$expects = array(array($modelClass => array('id' => 2, 'name' => '1.1', $parentField => 1, $leftField => 2, $rightField => 7)),
|
$expects = array(array($modelClass => array('id' => 2, 'name' => '1.1', $parentField => 1, $leftField => 2, $rightField => 7)),
|
||||||
array($modelClass => array('id' => 5, 'name' => '1.2', $parentField => 1, $leftField => 8, $rightField => 13)));
|
array($modelClass => array('id' => 5, 'name' => '1.2', $parentField => 1, $leftField => 8, $rightField => 13)));
|
||||||
$this->assertEqual($direct, $expects);
|
$this->assertEqual($direct, $expects);
|
||||||
|
|
||||||
$total = $this->Tree->children(null, null, array('id', 'name', $parentField, $leftField, $rightField), null, null, null, 1);
|
$total = $this->Tree->children(null, null, array('id', 'name', $parentField, $leftField, $rightField), null, null, null, 1);
|
||||||
|
@ -1409,8 +1408,8 @@ class ScopedTreeCase extends NumberTreeCase {
|
||||||
$expected = array(
|
$expected = array(
|
||||||
'FlagTree' => array('id' => 2, 'parent_id' => null, 'locale' => 'eng', 'name' => 'New title', 'flag' => 0, 'lft' => 3, 'rght' => 4),
|
'FlagTree' => array('id' => 2, 'parent_id' => null, 'locale' => 'eng', 'name' => 'New title', 'flag' => 0, 'lft' => 3, 'rght' => 4),
|
||||||
'Name' => array(
|
'Name' => array(
|
||||||
array('id' => 21, 'locale' => 'eng', 'model' => 'FlagTree', 'foreign_key' => 2, 'field' => 'name', 'content' => 'New title'),
|
array('id' => 21, 'locale' => 'eng', 'model' => 'FlagTree', 'foreign_key' => 2, 'field' => 'name', 'content' => 'New title'),
|
||||||
array('id' => 22, 'locale' => 'spa', 'model' => 'FlagTree', 'foreign_key' => 2, 'field' => 'name', 'content' => 'Nuevo leyenda')
|
array('id' => 22, 'locale' => 'spa', 'model' => 'FlagTree', 'foreign_key' => 2, 'field' => 'name', 'content' => 'Nuevo leyenda')
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
$this->assertEqual($result, $expected);
|
$this->assertEqual($result, $expected);
|
||||||
|
@ -1513,5 +1512,201 @@ class UuidTreeCase extends NumberTreeCase {
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
var $fixtures = array('core.uuid_tree');
|
var $fixtures = array('core.uuid_tree');
|
||||||
|
/**
|
||||||
|
* testMovePromote method
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
function testMovePromote() {
|
||||||
|
extract($this->settings);
|
||||||
|
$this->Tree =& new $modelClass();
|
||||||
|
$this->Tree->initialize(2, 2);
|
||||||
|
$this->Tree->id = null;
|
||||||
|
|
||||||
|
$parent = $this->Tree->find(array($modelClass . '.name' => '1. Root'));
|
||||||
|
$parent_id = $parent[$modelClass]['id'];
|
||||||
|
|
||||||
|
$data = $this->Tree->find(array($modelClass . '.name' => '1.1.1'), array('id'));
|
||||||
|
$this->Tree->id= $data[$modelClass]['id'];
|
||||||
|
$this->Tree->saveField($parentField, $parent_id);
|
||||||
|
$direct = $this->Tree->children($parent_id, true, array('name', $leftField, $rightField));
|
||||||
|
$expects = array(array($modelClass => array('name' => '1.1', $leftField => 2, $rightField => 5)),
|
||||||
|
array($modelClass => array('name' => '1.2', $leftField => 6, $rightField => 11)),
|
||||||
|
array($modelClass => array('name' => '1.1.1', $leftField => 12, $rightField => 13)));
|
||||||
|
$this->assertEqual($direct, $expects);
|
||||||
|
$validTree = $this->Tree->verify();
|
||||||
|
$this->assertIdentical($validTree, true);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* testMoveWithWhitelist method
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
function testMoveWithWhitelist() {
|
||||||
|
extract($this->settings);
|
||||||
|
$this->Tree =& new $modelClass();
|
||||||
|
$this->Tree->initialize(2, 2);
|
||||||
|
$this->Tree->id = null;
|
||||||
|
|
||||||
|
$parent = $this->Tree->find(array($modelClass . '.name' => '1. Root'));
|
||||||
|
$parent_id = $parent[$modelClass]['id'];
|
||||||
|
|
||||||
|
$data = $this->Tree->find(array($modelClass . '.name' => '1.1.1'), array('id'));
|
||||||
|
$this->Tree->id = $data[$modelClass]['id'];
|
||||||
|
$this->Tree->whitelist = array($parentField, 'name', 'description');
|
||||||
|
$this->Tree->saveField($parentField, $parent_id);
|
||||||
|
|
||||||
|
$result = $this->Tree->children($parent_id, true, array('name', $leftField, $rightField));
|
||||||
|
$expected = array(array($modelClass => array('name' => '1.1', $leftField => 2, $rightField => 5)),
|
||||||
|
array($modelClass => array('name' => '1.2', $leftField => 6, $rightField => 11)),
|
||||||
|
array($modelClass => array('name' => '1.1.1', $leftField => 12, $rightField => 13)));
|
||||||
|
$this->assertEqual($result, $expected);
|
||||||
|
$this->assertTrue($this->Tree->verify());
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* testRemoveNoChildren method
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
function testRemoveNoChildren() {
|
||||||
|
extract($this->settings);
|
||||||
|
$this->Tree =& new $modelClass();
|
||||||
|
$this->Tree->initialize(2, 2);
|
||||||
|
$initialCount = $this->Tree->find('count');
|
||||||
|
|
||||||
|
$result = $this->Tree->findByName('1.1.1');
|
||||||
|
$this->Tree->removeFromTree($result[$modelClass]['id']);
|
||||||
|
|
||||||
|
$laterCount = $this->Tree->find('count');
|
||||||
|
$this->assertEqual($initialCount, $laterCount);
|
||||||
|
|
||||||
|
$nodes = $this->Tree->find('list', array('order' => $leftField));
|
||||||
|
$expects = array(
|
||||||
|
'1. Root',
|
||||||
|
'1.1',
|
||||||
|
'1.1.2',
|
||||||
|
'1.2',
|
||||||
|
'1.2.1',
|
||||||
|
'1.2.2',
|
||||||
|
'1.1.1',
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertEqual(array_values($nodes), $expects);
|
||||||
|
|
||||||
|
$validTree = $this->Tree->verify();
|
||||||
|
$this->assertIdentical($validTree, true);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* testRemoveAndDeleteNoChildren method
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
function testRemoveAndDeleteNoChildren() {
|
||||||
|
extract($this->settings);
|
||||||
|
$this->Tree =& new $modelClass();
|
||||||
|
$this->Tree->initialize(2, 2);
|
||||||
|
$initialCount = $this->Tree->find('count');
|
||||||
|
|
||||||
|
$result = $this->Tree->findByName('1.1.1');
|
||||||
|
$this->Tree->removeFromTree($result[$modelClass]['id'], true);
|
||||||
|
|
||||||
|
$laterCount = $this->Tree->find('count');
|
||||||
|
$this->assertEqual($initialCount - 1, $laterCount);
|
||||||
|
|
||||||
|
$nodes = $this->Tree->find('list', array('order' => $leftField));
|
||||||
|
$expects = array(
|
||||||
|
'1. Root',
|
||||||
|
'1.1',
|
||||||
|
'1.1.2',
|
||||||
|
'1.2',
|
||||||
|
'1.2.1',
|
||||||
|
'1.2.2',
|
||||||
|
);
|
||||||
|
$this->assertEqual(array_values($nodes), $expects);
|
||||||
|
|
||||||
|
$validTree = $this->Tree->verify();
|
||||||
|
$this->assertIdentical($validTree, true);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* testChildren method
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
function testChildren() {
|
||||||
|
extract($this->settings);
|
||||||
|
$this->Tree =& new $modelClass();
|
||||||
|
$this->Tree->initialize(2, 2);
|
||||||
|
|
||||||
|
$data = $this->Tree->find(array($modelClass . '.name' => '1. Root'));
|
||||||
|
$this->Tree->id= $data[$modelClass]['id'];
|
||||||
|
|
||||||
|
$direct = $this->Tree->children(null, true, array('name', $leftField, $rightField));
|
||||||
|
$expects = array(array($modelClass => array('name' => '1.1', $leftField => 2, $rightField => 7)),
|
||||||
|
array($modelClass => array('name' => '1.2', $leftField => 8, $rightField => 13)));
|
||||||
|
$this->assertEqual($direct, $expects);
|
||||||
|
|
||||||
|
$total = $this->Tree->children(null, null, array('name', $leftField, $rightField));
|
||||||
|
$expects = array(array($modelClass => array('name' => '1.1', $leftField => 2, $rightField => 7)),
|
||||||
|
array($modelClass => array('name' => '1.1.1', $leftField => 3, $rightField => 4)),
|
||||||
|
array($modelClass => array('name' => '1.1.2', $leftField => 5, $rightField => 6)),
|
||||||
|
array($modelClass => array('name' => '1.2', $leftField => 8, $rightField => 13)),
|
||||||
|
array($modelClass => array('name' => '1.2.1', $leftField => 9, $rightField => 10)),
|
||||||
|
array($modelClass => array('name' => '1.2.2', $leftField => 11, $rightField => 12)));
|
||||||
|
$this->assertEqual($total, $expects);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* testNoAmbiguousColumn method
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
function testNoAmbiguousColumn() {
|
||||||
|
extract($this->settings);
|
||||||
|
$this->Tree =& new $modelClass();
|
||||||
|
$this->Tree->bindModel(array('belongsTo' => array('Dummy' =>
|
||||||
|
array('className' => $modelClass, 'foreignKey' => $parentField, 'conditions' => array('Dummy.id' => null)))), false);
|
||||||
|
$this->Tree->initialize(2, 2);
|
||||||
|
|
||||||
|
$data = $this->Tree->find(array($modelClass . '.name' => '1. Root'));
|
||||||
|
$this->Tree->id= $data[$modelClass]['id'];
|
||||||
|
|
||||||
|
$direct = $this->Tree->children(null, true, array('name', $leftField, $rightField), null, null, null, 1);
|
||||||
|
$expects = array(array($modelClass => array('name' => '1.1', $leftField => 2, $rightField => 7)),
|
||||||
|
array($modelClass => array('name' => '1.2', $leftField => 8, $rightField => 13)));
|
||||||
|
$this->assertEqual($direct, $expects);
|
||||||
|
|
||||||
|
$total = $this->Tree->children(null, null, array('name', $leftField, $rightField), null, null, null, 1);
|
||||||
|
$expects = array(
|
||||||
|
array($modelClass => array('name' => '1.1', $leftField => 2, $rightField => 7)),
|
||||||
|
array($modelClass => array('name' => '1.1.1', $leftField => 3, $rightField => 4)),
|
||||||
|
array($modelClass => array('name' => '1.1.2', $leftField => 5, $rightField => 6)),
|
||||||
|
array($modelClass => array('name' => '1.2', $leftField => 8, $rightField => 13)),
|
||||||
|
array($modelClass => array('name' => '1.2.1', $leftField => 9, $rightField => 10)),
|
||||||
|
array($modelClass => array('name' => '1.2.2', $leftField => 11, $rightField => 12))
|
||||||
|
);
|
||||||
|
$this->assertEqual($total, $expects);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* testGenerateTreeListWithSelfJoin method
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
function testGenerateTreeListWithSelfJoin() {
|
||||||
|
extract($this->settings);
|
||||||
|
$this->Tree =& new $modelClass();
|
||||||
|
$this->Tree->bindModel(array('belongsTo' => array('Dummy' =>
|
||||||
|
array('className' => $modelClass, 'foreignKey' => $parentField, 'conditions' => array('Dummy.id' => null)))), false);
|
||||||
|
$this->Tree->initialize(2, 2);
|
||||||
|
|
||||||
|
$result = $this->Tree->generateTreeList();
|
||||||
|
$expected = array('1. Root', '_1.1', '__1.1.1', '__1.1.2', '_1.2', '__1.2.1', '__1.2.2');
|
||||||
|
$this->assertIdentical(array_values($result), $expected);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
Loading…
Add table
Add a link
Reference in a new issue