Making the set() functions use + instead of array_merge() so that numeric indices are properly preserved across multiple method calls. Fixes #1105

This commit is contained in:
mark_story 2010-09-18 00:13:03 -04:00
parent d113d7d612
commit e91fa68f8e
6 changed files with 22 additions and 6 deletions

View file

@ -115,10 +115,7 @@ class TemplateTask extends Shell {
if ($data == null) { if ($data == null) {
return false; return false;
} }
$this->templateVars = $data + $this->templateVars;
foreach ($data as $name => $value) {
$this->templateVars[$name] = $value;
}
} }
/** /**

View file

@ -768,7 +768,7 @@ class Controller extends Object {
} else { } else {
$data = array($one => $two); $data = array($one => $two);
} }
$this->viewVars = array_merge($this->viewVars, $data); $this->viewVars = $data + $this->viewVars;
} }
/** /**

View file

@ -664,7 +664,7 @@ class View extends Object {
if ($data == null) { if ($data == null) {
return false; return false;
} }
$this->viewVars = array_merge($this->viewVars, $data); $this->viewVars = $data + $this->viewVars;
} }
/** /**

View file

@ -93,6 +93,12 @@ class TemplateTaskTest extends CakeTestCase {
$this->assertEqual($this->Task->templateVars['one'], 'three'); $this->assertEqual($this->Task->templateVars['one'], 'three');
$this->assertTrue(isset($this->Task->templateVars['four'])); $this->assertTrue(isset($this->Task->templateVars['four']));
$this->assertEqual($this->Task->templateVars['four'], 'five'); $this->assertEqual($this->Task->templateVars['four'], 'five');
$this->Task->templateVars = array();
$this->Task->set(array(3 => 'three', 4 => 'four'));
$this->Task->set(array(1 => 'one', 2 => 'two'));
$expected = array(3 => 'three', 4 => 'four', 1 => 'one', 2 => 'two');
$this->assertEqual($this->Task->templateVars, $expected);
} }
/** /**

View file

@ -865,6 +865,13 @@ class ControllerTest extends CakeTestCase {
$expected = array('ModelName' => 'name', 'ModelName2' => 'name2'); $expected = array('ModelName' => 'name', 'ModelName2' => 'name2');
$Controller->set(array('ModelName', 'ModelName2'), array('name', 'name2')); $Controller->set(array('ModelName', 'ModelName2'), array('name', 'name2'));
$this->assertIdentical($Controller->viewVars, $expected); $this->assertIdentical($Controller->viewVars, $expected);
$Controller->viewVars = array();
$Controller->set(array(3 => 'three', 4 => 'four'));
$Controller->set(array(1 => 'one', 2 => 'two'));
$expected = array(3 => 'three', 4 => 'four', 1 => 'one', 2 => 'two');
$this->assertEqual($Controller->viewVars, $expected);
} }
/** /**

View file

@ -874,6 +874,12 @@ class ViewTest extends CakeTestCase {
$View->set(array('key3' => 'value3')); $View->set(array('key3' => 'value3'));
$this->assertIdentical($View->getVar('key3'), 'value3'); $this->assertIdentical($View->getVar('key3'), 'value3');
$View->viewVars = array();
$View->set(array(3 => 'three', 4 => 'four'));
$View->set(array(1 => 'one', 2 => 'two'));
$expected = array(3 => 'three', 4 => 'four', 1 => 'one', 2 => 'two');
$this->assertEqual($View->viewVars, $expected);
} }
/** /**