Skip to content
Permalink
Browse files

Fixing RequestHandler::beforeRedirect() and issues with array urls, w…

…here incompatibilities between standard url arrays and requestAction url arrays caused incorrect results. Tests added. Fixes #276
  • Loading branch information...
markstory committed Feb 3, 2010
1 parent a81d57a commit 2adac05dad25062d1d6bcf5a4124a6f88dfefbcd
@@ -241,6 +241,9 @@ function beforeRedirect(&$controller, $url) {
foreach ($_POST as $key => $val) {
unset($_POST[$key]);
}
if (is_array($url)) {
$url = Router::url($url + array('base' => false));
}
echo $this->requestAction($url, array('return'));
$this->_stop();
}
@@ -69,6 +69,15 @@ function destination() {
$this->viewPath = 'posts';
$this->render('index');
}
/**
* test method for ajax redirection + parameter parsing
*
* @return void
*/
function param_method($one = null, $two = null) {
echo "one: $one two: $two";
$this->autoRender = false;
}
}
/**
@@ -576,5 +585,35 @@ function testAjaxRedirectAsRequestAction() {
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
* the correct urls are generated.
*
* @link http://cakephp.lighthouseapp.com/projects/42648-cakephp-1x/tickets/276
* @return void
*/
function testBeforeRedirectCallbackWithArrayUrl() {
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest';
App::build(array(
'views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views'. DS)
), true);
Router::setRequestInfo(array(
array('plugin' => null, 'controller' => 'accounts', 'action' => 'index', 'pass' => array(), 'named' => array(), 'form' => array(), 'url' => array('url' => 'accounts/'), 'bare' => 0),
array('base' => '/officespace', 'here' => '/officespace/accounts/', 'webroot' => '/officespace/')
));
$RequestHandler =& new NoStopRequestHandler();
ob_start();
$RequestHandler->beforeRedirect(
$this->Controller,
array('controller' => 'request_handler_test', 'action' => 'param_method', 'first', 'second')
);
$result = ob_get_clean();
$this->assertEqual($result, 'one: first two: second');
App::build();
}
}
?>

0 comments on commit 2adac05

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