diff --git a/lib/Cake/Test/Case/View/Helper/JsHelperTest.php b/lib/Cake/Test/Case/View/Helper/JsHelperTest.php index 92d1038db..e1c1e5fd2 100644 --- a/lib/Cake/Test/Case/View/Helper/JsHelperTest.php +++ b/lib/Cake/Test/Case/View/Helper/JsHelperTest.php @@ -302,10 +302,20 @@ class JsHelperTest extends CakeTestCase { */ public function testWriteBufferAndXhr() { $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->TestJsEngine->expects($this->never())->method('domReady'); $result = $this->Js->writeBuffer(); + + unset($_SERVER['HTTP_X_REQUESTED_WITH']); + if ($requestWith !== null) { + $_SERVER['HTTP_X_REQUESTED_WITH'] = $requestWith; + } } /** diff --git a/lib/Cake/View/Helper/JsHelper.php b/lib/Cake/View/Helper/JsHelper.php index 92c3e3bee..c62efe75d 100644 --- a/lib/Cake/View/Helper/JsHelper.php +++ b/lib/Cake/View/Helper/JsHelper.php @@ -190,7 +190,7 @@ class JsHelper extends AppHelper { * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/js.html#JsHelper::writeBuffer */ public function writeBuffer($options = array()) { - $domReady = $this->request->is('ajax'); + $domReady = !$this->request->is('ajax'); $defaults = array( 'onDomReady' => $domReady, 'inline' => true, 'cache' => false, 'clear' => true, 'safe' => true