diff --git a/cake/libs/view/helpers/js.php b/cake/libs/view/helpers/js.php index a44f2bb1d26..3073e728721 100644 --- a/cake/libs/view/helpers/js.php +++ b/cake/libs/view/helpers/js.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. diff --git a/cake/tests/cases/libs/view/helpers/js.test.php b/cake/tests/cases/libs/view/helpers/js.test.php index ee87727bf22..6dd5bce1592 100644 --- a/cake/tests/cases/libs/view/helpers/js.test.php +++ b/cake/tests/cases/libs/view/helpers/js.test.php @@ -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); + } }