Merge pull request #1139 from ADmad/2.3-dispatcher

Prevent response object being set as response body
This commit is contained in:
Mark Story 2013-02-24 09:07:15 -08:00
commit 51d2cb60fa
2 changed files with 47 additions and 1 deletions

View file

@ -192,7 +192,9 @@ class Dispatcher implements CakeEventListener {
if ($render && $controller->autoRender) {
$response = $controller->render();
} elseif ($response->body() === null) {
} elseif (!($result instanceof CakeResponse) &&
$response->body() === null
) {
$response->body($result);
}
$controller->shutdownProcess();

View file

@ -208,6 +208,16 @@ class SomePagesController extends AppController {
return new CakeResponse(array('body' => 'new response'));
}
/**
* Test file sending
*
* @return CakeResponse
*/
public function sendfile() {
$this->response->file(CAKE . 'Test' . DS . 'test_app' . DS . 'Vendor' . DS . 'css' . DS . 'test_asset.css');
return $this->response;
}
}
/**
@ -866,6 +876,40 @@ class DispatcherTest extends CakeTestCase {
$this->assertEquals('new response', $result);
}
/**
* testDispatchActionSendsFile
*
* @return void
*/
public function testDispatchActionSendsFile() {
Router::connect('/:controller/:action');
$Dispatcher = new Dispatcher();
$request = new CakeRequest('some_pages/sendfile');
$response = $this->getMock('CakeResponse', array(
'header',
'type',
'download',
'_sendHeader',
'_setContentType',
'_isActive',
'_clearBuffer',
'_flushBuffer'
));
$response->expects($this->never())
->method('body');
$response->expects($this->exactly(1))
->method('_isActive')
->will($this->returnValue(true));
ob_start();
$Dispatcher->dispatch($request, $response);
$result = ob_get_clean();
$this->assertEquals("/* this is the test asset css file */\n", $result);
}
/**
* testAdminDispatch method
*