mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-09-02 09:32:43 +00:00
Fix Controller::beforeRedirect() and array return.
Array return values from Controller::beforeRedirect() would be incorrectly handled causing wrong URL's to be generated. Fixes #2973
This commit is contained in:
parent
35e0984bec
commit
3e28326d9c
2 changed files with 30 additions and 1 deletions
|
@ -797,7 +797,7 @@ class Controller extends Object implements CakeEventListener {
|
|||
* @return array Array with keys url, status and exit
|
||||
*/
|
||||
protected function _parseBeforeRedirect($response, $url, $status, $exit) {
|
||||
if (is_array($response)) {
|
||||
if (is_array($response) && isset($response[0])) {
|
||||
foreach ($response as $resp) {
|
||||
if (is_array($resp) && isset($resp['url'])) {
|
||||
extract($resp, EXTR_OVERWRITE);
|
||||
|
@ -805,6 +805,8 @@ class Controller extends Object implements CakeEventListener {
|
|||
$url = $resp;
|
||||
}
|
||||
}
|
||||
} elseif (is_array($response)) {
|
||||
extract($response, EXTR_OVERWRITE);
|
||||
}
|
||||
return compact('url', 'status', 'exit');
|
||||
}
|
||||
|
|
|
@ -874,6 +874,33 @@ class ControllerTest extends CakeTestCase {
|
|||
$Controller->redirect('http://cakephp.org');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that beforeRedirect works with returning an array from the controller method.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testRedirectBeforeRedirectInControllerWithArray() {
|
||||
$Controller = $this->getMock('Controller', array('_stop', 'beforeRedirect'));
|
||||
$Controller->response = $this->getMock('CakeResponse', array('header'));
|
||||
$Controller->Components = $this->getMock('ComponentCollection', array('trigger'));
|
||||
|
||||
$Controller->expects($this->once())
|
||||
->method('beforeRedirect')
|
||||
->with('http://cakephp.org', null, true)
|
||||
->will($this->returnValue(array(
|
||||
'url' => 'http://example.org',
|
||||
'status' => 302,
|
||||
'exit' => true
|
||||
)));
|
||||
|
||||
$Controller->response->expects($this->at(0))
|
||||
->method('header')
|
||||
->with('Location', 'http://example.org');
|
||||
|
||||
$Controller->expects($this->once())->method('_stop');
|
||||
$Controller->redirect('http://cakephp.org');
|
||||
}
|
||||
|
||||
/**
|
||||
* testMergeVars method
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue