Skip to content

Commit

Permalink
Making JsHelper::set() work well with setting the variables to an obj…
Browse files Browse the repository at this point in the history
…ect property.
  • Loading branch information
markstory committed Oct 17, 2009
1 parent 4be98b6 commit f07df02
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
3 changes: 2 additions & 1 deletion cake/libs/view/helpers/js.php
Expand Up @@ -237,7 +237,8 @@ function getBuffer($clear = true) {
**/
function _createVars() {
if (!empty($this->__jsVars)) {
$this->buffer('var ' . $this->setVariable . ' = ' . $this->object($this->__jsVars) . ';');
$setVar = (strpos($this->setVariable, '.')) ? $this->setVariable : 'var ' . $this->setVariable;
$this->buffer($setVar . ' = ' . $this->object($this->__jsVars) . ';');
}
}

Expand Down
11 changes: 9 additions & 2 deletions cake/tests/cases/libs/view/helpers/js.test.php
Expand Up @@ -442,13 +442,20 @@ function testSet() {
$result = $this->Js->getBuffer();
$expected = 'var app = {"loggedIn":true,"height":"tall","color":"purple"};';
$this->assertEqual($result[0], $expected);

$this->Js->set('loggedIn', true);
$this->Js->set(array('height' => 'tall', 'color' => 'purple'));
$this->Js->setVariable = 'WICKED';
$result = $this->Js->getBuffer(false);
$result = $this->Js->getBuffer();
$expected = 'var WICKED = {"loggedIn":true,"height":"tall","color":"purple"};';
$this->assertEqual($result[0], $expected);

$this->Js->set('loggedIn', true);
$this->Js->set(array('height' => 'tall', 'color' => 'purple'));
$this->Js->setVariable = 'Application.variables';
$result = $this->Js->getBuffer();
$expected = 'Application.variables = {"loggedIn":true,"height":"tall","color":"purple"};';
$this->assertEqual($result[0], $expected);
}
}

Expand Down

0 comments on commit f07df02

Please sign in to comment.