Permalink
Browse files

Adding test to check that postfix and prefix options don't go into in…

…ner objects. Tests added, fixes #348
  • Loading branch information...
1 parent e09e520 commit 2209f198f88197e0600d5c0ca375e78e572c2e11 @markstory markstory committed Feb 18, 2010
Showing with 11 additions and 1 deletion.
  1. +4 −1 cake/libs/view/helpers/javascript.php
  2. +7 −0 cake/tests/cases/libs/view/helpers/javascript.test.php
@@ -639,7 +639,10 @@ function object($data = array(), $options = array()) {
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']) ||
@@ -404,6 +404,13 @@ function testObjectGeneration() {
$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;

0 comments on commit 2209f19

Please sign in to comment.