Skip to content
Permalink
Browse files

Making requestAction() calls that requesthandler creates not remove a…

…utoLayout. This fixes issues where ajax layout files would not be rendered.

Tests added.  Fixes #722
  • Loading branch information...
markstory committed Jun 8, 2010
1 parent a9fa7ac commit a88b8dd5b940abf8bc1aaa6a21b04171fc7b5296
@@ -279,7 +279,7 @@ function beforeRedirect(&$controller, $url, $status = null) {
$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 @@ function param_method($one = null, $two = null) {
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 @@ function testAjaxRedirectAsRequestAction() {
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 @@ function testBeforeRedirectCallbackWithArrayUrl() {
$_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/')
));

0 comments on commit a88b8dd

Please sign in to comment.
You can’t perform that action at this time.