mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-03-15 05:59:50 +00:00
Fixing RequestHandler::beforeRedirect() and issues with array urls, where incompatibilities between standard url arrays and requestAction url arrays caused incorrect results. Tests added. Fixes #276
This commit is contained in:
parent
7daad4acaf
commit
4b269e3170
2 changed files with 42 additions and 0 deletions
|
@ -230,6 +230,9 @@ class RequestHandlerComponent extends Object {
|
|||
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();
|
||||
}
|
||||
|
|
|
@ -70,6 +70,15 @@ class RequestHandlerTestController extends Controller {
|
|||
$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;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* RequestHandlerTestDisabledController class
|
||||
|
@ -541,5 +550,35 @@ class RequestHandlerComponentTest extends CakeTestCase {
|
|||
Configure::write('viewPaths', $_paths);
|
||||
unset($_SERVER['HTTP_X_REQUESTED_WITH']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
}
|
||||
?>
|
Loading…
Add table
Reference in a new issue