Skip to content

Commit

Permalink
Making requestAction() calls that requesthandler creates not remove a…
Browse files Browse the repository at this point in the history
…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 a88b8dd
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cake/libs/controller/components/request_handler.php
Expand Up @@ -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();
}

Expand Down
Expand Up @@ -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();
}
}

/**
Expand Down Expand Up @@ -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
Expand All @@ -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/')
));

Expand Down

0 comments on commit a88b8dd

Please sign in to comment.