Skip to content
Permalink
Browse files

Fixing method dispatching errors in JsHelper with regards to Object::…

…object, and PHP4 workarounds.
  • Loading branch information...
markstory committed Aug 10, 2009
1 parent 4e6aa35 commit 856392e916474c11f439964b500ed67cea81b2f8
Showing with 26 additions and 1 deletion.
  1. +15 −1 cake/libs/view/helpers/js.php
  2. +11 −0 cake/tests/cases/libs/view/helpers/js.test.php
@@ -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)) {
@@ -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.
@@ -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);
}
}

0 comments on commit 856392e

Please sign in to comment.
You can’t perform that action at this time.