mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 02:56:15 +00:00
Making requestAction() calls that requesthandler creates not remove autoLayout. This fixes issues where ajax layout files would not be rendered.
Tests added. Fixes #722
This commit is contained in:
parent
a9fa7ac240
commit
a88b8dd5b9
2 changed files with 42 additions and 2 deletions
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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/')
|
||||
));
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue