diff --git a/cake/libs/controller/components/request_handler.php b/cake/libs/controller/components/request_handler.php index 1748c787d..dbbdfe2c9 100644 --- a/cake/libs/controller/components/request_handler.php +++ b/cake/libs/controller/components/request_handler.php @@ -279,7 +279,7 @@ class RequestHandlerComponent extends Object { $msg = $statusCode[$code]; $controller->header("HTTP/1.1 {$code} {$msg}"); } - echo $this->requestAction($url, array('return')); + echo $this->requestAction($url, array('return', 'bare' => false)); $this->_stop(); } diff --git a/cake/tests/cases/libs/controller/components/request_handler.test.php b/cake/tests/cases/libs/controller/components/request_handler.test.php index abeaa0531..420ecd405 100644 --- a/cake/tests/cases/libs/controller/components/request_handler.test.php +++ b/cake/tests/cases/libs/controller/components/request_handler.test.php @@ -79,6 +79,18 @@ class RequestHandlerTestController extends Controller { echo "one: $one two: $two"; $this->autoRender = false; } + +/** + * test method for testing layout rendering when isAjax() + * + * @return void + */ + function ajax2_layout() { + if ($this->autoLayout) { + $this->layout = 'ajax2'; + } + $this->destination(); + } } /** @@ -593,6 +605,34 @@ class RequestHandlerComponentTest extends CakeTestCase { App::build(); } +/** + * test that ajax requests involving redirects don't force no layout + * this would cause the ajax layout to not be rendered. + * + * @return void + */ + function testAjaxRedirectAsRequestActionStillRenderingLayout() { + $_SERVER['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'; + $this->_init(); + App::build(array( + 'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS) + ), true); + + $this->Controller->RequestHandler = new NoStopRequestHandler($this); + $this->Controller->RequestHandler->expectOnce('_stop'); + + ob_start(); + $this->Controller->RequestHandler->beforeRedirect( + $this->Controller, array('controller' => 'request_handler_test', 'action' => 'ajax2_layout') + ); + $result = ob_get_clean(); + $this->assertPattern('/posts index/', $result, 'RequestAction redirect failed.'); + $this->assertPattern('/Ajax!/', $result, 'Layout was not rendered.'); + + unset($_SERVER['HTTP_X_REQUESTED_WITH']); + App::build(); + } + /** * test that the beforeRedirect callback properly converts * array urls into their correct string ones, and adds base => false so @@ -605,7 +645,7 @@ class RequestHandlerComponentTest extends CakeTestCase { $_SERVER['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'; Router::setRequestInfo(array( - array('plugin' => null, 'controller' => 'accounts', 'action' => 'index', 'pass' => array(), 'named' => array(), 'form' => array(), 'url' => array('url' => 'accounts/'), 'bare' => 0), + array('plugin' => null, 'controller' => 'accounts', 'action' => 'index', 'pass' => array(), 'named' => array(), 'form' => array(), 'url' => array('url' => 'accounts/')), array('base' => '/officespace', 'here' => '/officespace/accounts/', 'webroot' => '/officespace/') ));