Skip to content

Commit

Permalink
Fixing method dispatching errors in JsHelper with regards to Object::…
Browse files Browse the repository at this point in the history
…object, and PHP4 workarounds.
  • Loading branch information
markstory committed Aug 12, 2009
1 parent a7e300a commit 08f0c7c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
16 changes: 15 additions & 1 deletion cake/libs/view/helpers/js.php
Expand Up @@ -115,7 +115,7 @@ function __construct($settings = array()) {
* @param string $method Method to be called
* @param array $params Parameters for the method being called.
* @access public
* @return mixed
* @return mixed Depends on the return of the dispatched method, or it could be an instance of the EngineHelper
**/
function call__($method, $params) {
if (isset($this->{$this->__engineName}) && method_exists($this->{$this->__engineName}, $method)) {
Expand Down Expand Up @@ -150,6 +150,20 @@ function call__($method, $params) {
trigger_error(sprintf(__('JsHelper:: Missing Method %s is undefined', true), $method), E_USER_WARNING);
}

/**
* Workaround for Object::Object() existing. Since Object::object exists, it does not
* fall into call__ and is not passed onto the engine helper. See JsBaseEngineHelper::object() for
* more information on this method.
*
* @param mixed $data Data to convert into JSON
* @param array $options Options to use for encoding JSON. See JsBaseEngineHelper::object() for more details.
* @return string encoded JSON
* @deprecated Remove when support for PHP4 and Object::object are removed.
**/
function object($data = array(), $options = array()) {
return $this->{$this->__engineName}->object($data, $options);
}

/**
* Writes all Javascript generated so far to a code block or
* caches them to a file and returns a linked script.
Expand Down
11 changes: 11 additions & 0 deletions cake/tests/cases/libs/view/helpers/js.test.php
Expand Up @@ -415,6 +415,17 @@ function testSubmitWithMock() {
);
$this->assertTags($result, $expected);
}

/**
* Test that Object::Object() is not breaking json output in JsHelper
*
* @return void
**/
function testObjectPassThrough() {
$result = $this->Js->object(array('one' => 'first', 'two' => 'second'));
$expected = '{"one":"first","two":"second"}';
$this->assertEqual($result, $expected);
}
}


Expand Down

0 comments on commit 08f0c7c

Please sign in to comment.