From 8e92df3bbb0077f64495e0e763d602f068e149ce Mon Sep 17 00:00:00 2001 From: nate Date: Mon, 26 Mar 2007 17:22:02 +0000 Subject: [PATCH] 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 --- cake/libs/view/helpers/javascript.php | 2 +- .../cases/libs/view/helpers/javascript.test.php | 14 +++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/cake/libs/view/helpers/javascript.php b/cake/libs/view/helpers/javascript.php index c8c055f16..5b9603af9 100644 --- a/cake/libs/view/helpers/javascript.php +++ b/cake/libs/view/helpers/javascript.php @@ -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'; } } diff --git a/cake/tests/cases/libs/view/helpers/javascript.test.php b/cake/tests/cases/libs/view/helpers/javascript.test.php index 81effda0b..909d24df2 100644 --- a/cake/tests/cases/libs/view/helpers/javascript.test.php +++ b/cake/tests/cases/libs/view/helpers/javascript.test.php @@ -49,19 +49,19 @@ class JavascriptTest extends UnitTestCase { function testLink() { $result = $this->js->link('script.js'); $expected = ''; - $this->assertEqual($result, $expected, "Error creating link, expected '{$expected}', got '{$result}'."); + $this->assertEqual($result, $expected); $result = $this->js->link('script'); $expected = ''; - $this->assertEqual($result, $expected, "Error creating link, expected '{$expected}', got '{$result}'."); + $this->assertEqual($result, $expected); $result = $this->js->link('scriptaculous.js?load=effects'); $expected = ''; - $this->assertEqual($result, $expected, "Error creating link, expected '{$expected}', got '{$result}'."); + $this->assertEqual($result, $expected); $result = $this->js->link('jquery-1.1.2'); $expected = ''; - $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() {