mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Returning response objects from controllers wasn't working correctly.
This commit is contained in:
parent
177cd39abb
commit
c25394278b
2 changed files with 29 additions and 1 deletions
|
@ -110,12 +110,14 @@ class Dispatcher {
|
|||
$controller->constructClasses();
|
||||
$controller->startupProcess();
|
||||
|
||||
$render = true;
|
||||
$result = $controller->invokeAction($request);
|
||||
if ($result instanceof CakeResponse) {
|
||||
$render = false;
|
||||
$response = $result;
|
||||
}
|
||||
|
||||
if ($controller->autoRender) {
|
||||
if ($render && $controller->autoRender) {
|
||||
$response = $controller->render();
|
||||
} elseif ($response->body() === null) {
|
||||
$response->body($result);
|
||||
|
|
|
@ -167,6 +167,15 @@ class SomePagesController extends AppController {
|
|||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for returning responses.
|
||||
*
|
||||
* @return CakeResponse
|
||||
*/
|
||||
public function responseGenerator() {
|
||||
return new CakeResponse(array('body' => 'new response'));
|
||||
}
|
||||
|
||||
/**
|
||||
* redirect method overriding
|
||||
*
|
||||
|
@ -806,6 +815,23 @@ class DispatcherTest extends CakeTestCase {
|
|||
$this->assertEqual($controller->params['pass'][0], 'something. .', 'Period was chopped off. %s');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that Dispatcher handles actions that return response objects.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDispatchActionReturnsResponse() {
|
||||
$Dispatcher = new Dispatcher();
|
||||
$request = new CakeRequest('some_pages/responseGenerator');
|
||||
$response = $this->getMock('CakeResponse', array('_sendHeader'));
|
||||
|
||||
ob_start();
|
||||
$Dispatcher->dispatch($request, $response);
|
||||
$result = ob_get_clean();
|
||||
|
||||
$this->assertEquals('new response', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* testAdminDispatch method
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue