mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
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:
parent
d113d7d612
commit
e91fa68f8e
6 changed files with 22 additions and 6 deletions
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -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);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue