diff --git a/cake/libs/controller/components/request_handler.php b/cake/libs/controller/components/request_handler.php index 5663eedf9..c60d48b70 100644 --- a/cake/libs/controller/components/request_handler.php +++ b/cake/libs/controller/components/request_handler.php @@ -230,15 +230,17 @@ class RequestHandlerComponent extends Object { $this->__initializeTypes(); $controller->params['isAjax'] = $this->isAjax(); + $isRecognized = ( + !in_array($this->ext, array('html', 'htm')) && + in_array($this->ext, array_keys($this->__requestContent)) + ); - if (!empty($this->ext)) { - if (in_array($this->ext, array('html', 'htm'))) { - $this->respondAs('html', array('charset' => Configure::read('App.encoding'))); - } elseif (in_array($this->ext, array_keys($this->__requestContent))) { - $this->renderAs($controller, $this->ext); - } + if (!empty($this->ext) && $isRecognized) { + $this->renderAs($controller, $this->ext); } elseif ($this->isAjax()) { $this->renderAs($controller, 'ajax'); + } elseif (empty($this->ext) || in_array($this->ext, array('html', 'htm'))) { + $this->respondAs('html', array('charset' => Configure::read('App.encoding'))); } if ($this->requestedWith('xml')) { 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 ef370070f..8851dc58b 100644 --- a/cake/tests/cases/libs/controller/components/request_handler.test.php +++ b/cake/tests/cases/libs/controller/components/request_handler.test.php @@ -253,6 +253,27 @@ class RequestHandlerComponentTest extends CakeTestCase { $this->assertEqual($this->Controller->ext, '.ctp'); } + +/** + * testAutoAjaxLayout method + * + * @access public + * @return void + */ + function testAutoAjaxLayout() { + $_SERVER['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'; + $this->RequestHandler->startup($this->Controller); + $this->assertTrue($this->Controller->layout, $this->RequestHandler->ajaxLayout); + + $this->_init(); + $this->Controller->params['url']['ext'] = 'js'; + $this->RequestHandler->initialize($this->Controller); + $this->RequestHandler->startup($this->Controller); + $this->assertNotEqual($this->Controller->layout, 'ajax'); + + unset($_SERVER['HTTP_X_REQUESTED_WITH']); + } + /** * testStartupCallback method * @@ -692,7 +713,7 @@ class RequestHandlerComponentTest extends CakeTestCase { } /** - * assure that beforeRedirect with a status code will correctly set the status header + * assure that beforeRedirect with a status code will correctly set the status header * * @return void */