Permalink
Browse files

Making the set() functions use + instead of array_merge() so that num…

…eric indices are properly preserved across multiple method calls. Fixes #1105
  • Loading branch information...
1 parent d113d7d commit e91fa68f8e1ddad33e4a43157ba3cfab671f201a @markstory markstory committed Sep 18, 2010
@@ -115,10 +115,7 @@ function set($one, $two = null) {
if ($data == null) {
return false;
}
-
- foreach ($data as $name => $value) {
- $this->templateVars[$name] = $value;
- }
+ $this->templateVars = $data + $this->templateVars;
}
/**
@@ -768,7 +768,7 @@ function set($one, $two = null) {
} else {
$data = array($one => $two);
}
- $this->viewVars = array_merge($this->viewVars, $data);
+ $this->viewVars = $data + $this->viewVars;
}
/**
View
@@ -664,7 +664,7 @@ function set($one, $two = null) {
if ($data == null) {
return false;
}
- $this->viewVars = array_merge($this->viewVars, $data);
+ $this->viewVars = $data + $this->viewVars;
}
/**
@@ -93,6 +93,12 @@ function testSet() {
$this->assertEqual($this->Task->templateVars['one'], 'three');
$this->assertTrue(isset($this->Task->templateVars['four']));
$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);
}
/**
@@ -865,6 +865,13 @@ function testControllerSet() {
$expected = array('ModelName' => 'name', 'ModelName2' => 'name2');
$Controller->set(array('ModelName', 'ModelName2'), array('name', 'name2'));
$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);
+
}
/**
@@ -874,6 +874,12 @@ function testSet() {
$View->set(array('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);
}
/**

0 comments on commit e91fa68

Please sign in to comment.