Fixing incorrect setting of default value for 'onDomReady' option in JsHelper::writeBuffer()

This commit is contained in:
ADmad 2011-12-08 14:03:39 +05:30
parent 73aeb6ba62
commit df097796c4
2 changed files with 12 additions and 2 deletions

View file

@ -302,10 +302,20 @@ class JsHelperTest extends CakeTestCase {
*/ */
public function testWriteBufferAndXhr() { public function testWriteBufferAndXhr() {
$this->_useMock(); $this->_useMock();
$this->Js->params['isAjax'] = true; $requestWith = null;
if (isset($_SERVER['HTTP_X_REQUESTED_WITH'])) {
$requestWith = $_SERVER['HTTP_X_REQUESTED_WITH'];
}
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest';
$this->Js->buffer('alert("test");'); $this->Js->buffer('alert("test");');
$this->Js->TestJsEngine->expects($this->never())->method('domReady'); $this->Js->TestJsEngine->expects($this->never())->method('domReady');
$result = $this->Js->writeBuffer(); $result = $this->Js->writeBuffer();
unset($_SERVER['HTTP_X_REQUESTED_WITH']);
if ($requestWith !== null) {
$_SERVER['HTTP_X_REQUESTED_WITH'] = $requestWith;
}
} }
/** /**

View file

@ -190,7 +190,7 @@ class JsHelper extends AppHelper {
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/js.html#JsHelper::writeBuffer * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/js.html#JsHelper::writeBuffer
*/ */
public function writeBuffer($options = array()) { public function writeBuffer($options = array()) {
$domReady = $this->request->is('ajax'); $domReady = !$this->request->is('ajax');
$defaults = array( $defaults = array(
'onDomReady' => $domReady, 'inline' => true, 'onDomReady' => $domReady, 'inline' => true,
'cache' => false, 'clear' => true, 'safe' => true 'cache' => false, 'clear' => true, 'safe' => true