Adding native-type-generation fixes for JavascriptHelper::object()

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8095 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
nate 2009-03-13 14:49:00 +00:00
parent 2009f4b896
commit 36d3540c19
2 changed files with 13 additions and 1 deletions

View file

@ -525,6 +525,13 @@ class JavascriptHelper extends AppHelper {
if ($this->useNative) { if ($this->useNative) {
$rt = json_encode($data); $rt = json_encode($data);
} else { } else {
if (is_null($data)) {
return 'null';
}
if (is_bool($data)) {
return $data ? 'true' : 'false';
}
if (is_array($data)) { if (is_array($data)) {
$keys = array_keys($data); $keys = array_keys($data);
} }

View file

@ -366,13 +366,18 @@ class JavascriptTest extends CakeTestCase {
$expected = '{"title":"New thing","indexes":[5,6,7,8],"object":{"inner":{"value":1}}}'; $expected = '{"title":"New thing","indexes":[5,6,7,8],"object":{"inner":{"value":1}}}';
$this->assertEqual($result, $expected); $this->assertEqual($result, $expected);
foreach (array('true' => true, 'false' => false, 'null' => null) as $expected => $data) {
$result = $this->Javascript->object($data);
$this->assertEqual($result, $expected);
}
if ($this->Javascript->useNative) { if ($this->Javascript->useNative) {
$this->Javascript->useNative = false; $this->Javascript->useNative = false;
$this->testObjectGeneration(); $this->testObjectGeneration();
$this->Javascript->useNative = true; $this->Javascript->useNative = true;
} }
} }
/** /**
* testObjectNonNative method * testObjectNonNative method
* *
* @access public * @access public