Adding JavascriptHelper::object() fix for 0 being converted to null (Ticket #2296)

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@4680 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
nate 2007-03-26 17:22:02 +00:00
parent bb2a68caec
commit 8e92df3bbb
2 changed files with 10 additions and 6 deletions

View file

@ -373,7 +373,7 @@ class JavascriptHelper extends AppHelper {
if ((!count($stringKeys) && !is_numeric($val) && !is_bool($val)) || ($quoteKeys && in_array($key, $stringKeys, true)) || (!$quoteKeys && !in_array($key, $stringKeys, true))) {
$val = $q . $this->escapeString($val) . $q;
}
if ($val == null) {
if ($val === null) {
$val = 'null';
}
}

View file

@ -49,19 +49,19 @@ class JavascriptTest extends UnitTestCase {
function testLink() {
$result = $this->js->link('script.js');
$expected = '<script type="text/javascript" src="js/script.js"></script>';
$this->assertEqual($result, $expected, "Error creating link, expected '{$expected}', got '{$result}'.");
$this->assertEqual($result, $expected);
$result = $this->js->link('script');
$expected = '<script type="text/javascript" src="js/script.js"></script>';
$this->assertEqual($result, $expected, "Error creating link, expected '{$expected}', got '{$result}'.");
$this->assertEqual($result, $expected);
$result = $this->js->link('scriptaculous.js?load=effects');
$expected = '<script type="text/javascript" src="js/scriptaculous.js?load=effects"></script>';
$this->assertEqual($result, $expected, "Error creating link, expected '{$expected}', got '{$result}'.");
$this->assertEqual($result, $expected);
$result = $this->js->link('jquery-1.1.2');
$expected = '<script type="text/javascript" src="js/jquery-1.1.2.js"></script>';
$this->assertEqual($result, $expected, "Error creating link, expected '{$expected}', got '{$result}'.");
$this->assertEqual($result, $expected);
}
function testObjectGeneration() {
@ -69,7 +69,11 @@ class JavascriptTest extends UnitTestCase {
$result = $this->js->object($object);
$expected = '{"title":"New thing", "indexes":[5, 6, 7, 8]}';
$this->assertEqual($result, $expected, "Error generating JavaScript object, expected '{$expected}', got '{$result}'.");
$this->assertEqual($result, $expected);
$result = $this->js->object(array('default' => 0));
$expected = '{"default":0}';
$this->assertEqual($result, $expected);
}
function tearDown() {