mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Improving code coverage for PHP-native JSON generation in JavascriptHelper, fixing object output bug
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6814 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
ccd28c0139
commit
b7a5a28fbb
2 changed files with 7 additions and 11 deletions
|
@ -508,7 +508,7 @@ class JavascriptHelper extends AppHelper {
|
|||
|
||||
foreach ($data as $key => $val) {
|
||||
if (is_array($val) || is_object($val)) {
|
||||
$val = $this->object($val, $options);
|
||||
$val = $this->object($val, am($options, array('block' => false)));
|
||||
} else {
|
||||
$val = $this->value($val, (!count($options['stringKeys']) || ($options['quoteKeys'] && in_array($key, $options['stringKeys'], true)) || (!$options['quoteKeys'] && !in_array($key, $options['stringKeys'], true))));
|
||||
}
|
||||
|
|
|
@ -244,16 +244,6 @@ class JavascriptTest extends UnitTestCase {
|
|||
$expected = '{"Object":{"1":true,"2":false,"3":' . sprintf("%.11f", -3.141592653589) . ',"4":-10}}';
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
if (function_exists('json_encode')) {
|
||||
$old = $this->Javascript->useNative;
|
||||
$this->Javascript->useNative = true;
|
||||
$object = array('title' => 'New thing', 'indexes' => array(5, 6, 7, 8));
|
||||
$result = $this->Javascript->object($object);
|
||||
$expected = '{"title":"New thing","indexes":[5,6,7,8]}';
|
||||
$this->assertEqual($result, $expected);
|
||||
$this->Javascript->useNative = $old;
|
||||
}
|
||||
|
||||
$result = $this->Javascript->object(new TestJavascriptObject());
|
||||
$expected = '{"property1":"value1","property2":2}';
|
||||
$this->assertEqual($result, $expected);
|
||||
|
@ -270,6 +260,12 @@ class JavascriptTest extends UnitTestCase {
|
|||
$result = $this->Javascript->object($object);
|
||||
$expected = '{"title":"New thing","indexes":[5,6,7,8],"object":{"inner":{"value":1}}}';
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
if ($this->Javascript->useNative) {
|
||||
$this->Javascript->useNative = false;
|
||||
$this->testObjectGeneration();
|
||||
$this->Javascript->useNative = true;
|
||||
}
|
||||
}
|
||||
|
||||
function testScriptBlock() {
|
||||
|
|
Loading…
Reference in a new issue