diff --git a/cake/libs/view/helpers/js.php b/cake/libs/view/helpers/js.php index ccd955fc125..5feecf8c915 100644 --- a/cake/libs/view/helpers/js.php +++ b/cake/libs/view/helpers/js.php @@ -162,6 +162,19 @@ function object($data = array(), $options = array()) { return $this->{$this->__engineName}->object($data, $options); } +/** + * Overwrite inherited Helper::value() + * See JsBaseEngineHelper::value() for more information on this method. + * + * @param mixed $val A PHP variable to be converted to JSON + * @param boolean $quoteStrings If false, leaves string values unquoted + * @return string a JavaScript-safe/JSON representation of $val + * @access public + **/ + function value($val, $quoteString = true) { + return $this->{$this->__engineName}->value($val, $quoteString); + } + /** * 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 6a79960bdac..015199b931f 100644 --- a/cake/tests/cases/libs/view/helpers/js.test.php +++ b/cake/tests/cases/libs/view/helpers/js.test.php @@ -310,7 +310,7 @@ function testLinkWithMock() { $options = array('id' => 'something', 'htmlAttributes' => array('arbitrary' => 'value', 'batman' => 'robin')); $result = $this->Js->link('test link', '/posts/view/1', $options); $expected = array( - 'a' => array('id' => $options['id'], 'href' => '/posts/view/1', 'arbitrary' => 'value', + 'a' => array('id' => $options['id'], 'href' => '/posts/view/1', 'arbitrary' => 'value', 'batman' => 'robin'), 'test link', '/a' @@ -373,7 +373,7 @@ function testSubmitWithMock() { $this->Js->TestJsEngine->expectAt(2, 'dispatchMethod', array('request', '*')); $params = array( - 'update' => $options['update'], 'data' => 'serialize-code', + 'update' => $options['update'], 'data' => 'serialize-code', 'method' => 'post', 'dataExpression' => true ); $this->Js->TestJsEngine->expectAt(3, 'dispatchMethod', array( @@ -402,13 +402,13 @@ function testSubmitWithMock() { $this->Js->TestJsEngine->expectAt(6, 'dispatchMethod', array('request', $requestParams)); $params = array( - 'update' => '#content', 'data' => 'serialize-code', + 'update' => '#content', 'data' => 'serialize-code', 'method' => 'post', 'dataExpression' => true ); $this->Js->TestJsEngine->expectAt(7, 'dispatchMethod', array( 'event', array('click', "ajax-code", $params) )); - + $options = array('update' => '#content', 'id' => 'test-submit', 'url' => '/custom/url'); $result = $this->Js->submit('Save', $options); $expected = array( @@ -430,6 +430,18 @@ function testObjectPassThrough() { $this->assertEqual($result, $expected); } +/** + * Test that inherited Helper::value() is overwritten in JsHelper::value() + * and calls JsBaseEngineHelper::value(). + * + * @return void + */ + function testValuePassThrough() { + $result = $this->Js->value('string "quote"', true); + $expected = '"string \"quote\""'; + $this->assertEqual($result, $expected); + } + /** * test set()'ing variables to the Javascript buffer and controlling the output var name. * @@ -448,7 +460,7 @@ function testSet() { $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';