Fixing regression cased by commit d5ffdc288d causing ajax layout to be not auto set for ajax request for html pages. Refs #1099

This commit is contained in:
ADmad 2010-09-21 00:21:17 +05:30
parent b648b61422
commit b9a7b27ba1
2 changed files with 30 additions and 7 deletions

View file

@ -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')) {

View file

@ -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
*/