fixes #4761, tree behavior parameter array merge logic incorrect

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7056 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
AD7six 2008-05-28 16:02:31 +00:00
parent a89feed085
commit 4bafc397f9
2 changed files with 16 additions and 11 deletions

View file

@ -202,7 +202,7 @@ class TreeBehavior extends ModelBehavior {
*/
function childcount(&$model, $id = null, $direct = false) {
if (is_array($id)) {
extract (array_merge($id, array('id' => null)));
extract (array_merge(array('id' => null), $id));
}
if ($id === null && $model->id) {
$id = $model->id;
@ -243,7 +243,7 @@ class TreeBehavior extends ModelBehavior {
*/
function children(&$model, $id = null, $direct = false, $fields = null, $order = null, $limit = null, $page = 1, $recursive = null) {
if (is_array($id)) {
extract (array_merge($id, array('id' => null)));
extract (array_merge(array('id' => null), $id));
}
$overrideRecursive = $recursive;
if ($id === null && $model->id) {
@ -289,9 +289,6 @@ class TreeBehavior extends ModelBehavior {
* @access public
*/
function generatetreelist(&$model, $conditions = null, $keyPath = null, $valuePath = null, $spacer = '_', $recursive = null) {
if (is_array($conditions)) {
extract (array_merge($conditions, array('conditions' => null)));
}
$overrideRecursive = $recursive;
extract($this->settings[$model->alias]);
if (!is_null($overrideRecursive)) {
@ -347,7 +344,7 @@ class TreeBehavior extends ModelBehavior {
*/
function getparentnode(&$model, $id = null, $fields = null, $recursive = null) {
if (is_array($id)) {
extract (array_merge($id, array('id' => null)));
extract (array_merge(array('id' => null), $id));
}
$overrideRecursive = $recursive;
if (empty ($id)) {
@ -380,7 +377,7 @@ class TreeBehavior extends ModelBehavior {
*/
function getpath(&$model, $id = null, $fields = null, $recursive = null) {
if (is_array($id)) {
extract (array_merge($id, array('id' => null)));
extract (array_merge(array('id' => null), $id));
}
$overrideRecursive = $recursive;
if (empty ($id)) {
@ -416,7 +413,7 @@ class TreeBehavior extends ModelBehavior {
*/
function movedown(&$model, $id = null, $number = 1) {
if (is_array($id)) {
extract (array_merge($id, array('id' => null)));
extract (array_merge(array('id' => null), $id));
}
if (!$number) {
return false;
@ -470,7 +467,7 @@ class TreeBehavior extends ModelBehavior {
*/
function moveup(&$model, $id = null, $number = 1) {
if (is_array($id)) {
extract (array_merge($id, array('id' => null)));
extract (array_merge(array('id' => null), $id));
}
if (!$number) {
return false;
@ -533,7 +530,7 @@ class TreeBehavior extends ModelBehavior {
*/
function recover(&$model, $mode = 'parent', $missingParentAction = null) {
if (is_array($mode)) {
extract (array_merge($mode, array('mode' => 'parent')));
extract (array_merge(array('mode' => 'parent'), $mode));
}
extract($this->settings[$model->alias]);
$model->recursive = $recursive;
@ -637,7 +634,7 @@ class TreeBehavior extends ModelBehavior {
*/
function removefromtree(&$model, $id = null, $delete = false) {
if (is_array($id)) {
extract (array_merge($id, array('id' => null)));
extract (array_merge(array('id' => null), $id));
}
extract($this->settings[$model->alias]);

View file

@ -958,5 +958,13 @@ class NumberTreeCase extends CakeTestCase {
$this->assertEqual(Set::extract('/Ad/id', $result), array(5, 6));
$this->assertEqual(Set::extract('/Campaign/id', $result), array(2, 2));
}
function testArraySyntax() {
$this->NumberTree =& new NumberTree();
$this->NumberTree->initialize(3, 3);
$this->assertIdentical($this->NumberTree->childcount(2), $this->NumberTree->childcount(array('id' => 2)));
$this->assertIdentical($this->NumberTree->getparentnode(2), $this->NumberTree->getparentnode(array('id' => 2)));
$this->assertIdentical($this->NumberTree->getpath(4), $this->NumberTree->getpath(array('id' => 4)));
}
}
?>