Permalink
Browse files

Fixing incorrect setting of default value for 'onDomReady' option in …

…JsHelper::writeBuffer()
  • Loading branch information...
1 parent 73aeb6b commit df097796c477382c1ac5c410842553e0e1d07186 @ADmad ADmad committed Dec 8, 2011
Showing with 12 additions and 2 deletions.
  1. +11 −1 lib/Cake/Test/Case/View/Helper/JsHelperTest.php
  2. +1 −1 lib/Cake/View/Helper/JsHelper.php
@@ -302,10 +302,20 @@ public function testWriteBufferNotInline() {
*/
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;
+ }
}
/**
@@ -190,7 +190,7 @@ public function value($val = array(), $quoteString = null, $key = 'value') {
* @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

0 comments on commit df09779

Please sign in to comment.