Adding test to check that postfix and prefix options don't go into inner objects. Tests added, fixes #348

This commit is contained in:
Mark Story 2010-02-17 22:21:48 -05:00
parent e09e520fd5
commit 2209f198f8
2 changed files with 11 additions and 1 deletions

View file

@ -639,7 +639,10 @@ class JavascriptHelper extends AppHelper {
foreach ($data as $key => $val) {
if (is_array($val) || is_object($val)) {
$val = $this->object($val, array_merge($options, array('block' => false)));
$val = $this->object(
$val,
array_merge($options, array('block' => false, 'prefix' => '', 'postfix' => ''))
);
} else {
$quoteStrings = (
!count($options['stringKeys']) ||

View file

@ -404,6 +404,13 @@ class JavascriptTest extends CakeTestCase {
$result = $this->Javascript->object($data);
$this->assertEqual($result, $expected);
}
$object = array('title' => 'New thing', 'indexes' => array(5, 6, 7, 8), 'object' => array('inner' => array('value' => 1)));
$result = $this->Javascript->object($object, array('prefix' => 'PREFIX', 'postfix' => 'POSTFIX'));
$this->assertPattern('/^PREFIX/', $result);
$this->assertPattern('/POSTFIX$/', $result);
$this->assertNoPattern('/.PREFIX./', $result);
$this->assertNoPattern('/.POSTFIX./', $result);
if ($this->Javascript->useNative) {
$this->Javascript->useNative = false;