Skip to content
Permalink
Browse files

Prevent response object being set as response body

  • Loading branch information...
ADmad committed Feb 15, 2013
1 parent 89b1f32 commit 484801ecf415820308f588e4212bcf61ce42e3a9
Showing with 47 additions and 1 deletion.
  1. +3 −1 lib/Cake/Routing/Dispatcher.php
  2. +44 −0 lib/Cake/Test/Case/Routing/DispatcherTest.php
@@ -192,7 +192,9 @@ protected function _invoke(Controller $controller, CakeRequest $request, CakeRes
if ($render && $controller->autoRender) {
$response = $controller->render();
} elseif ($response->body() === null) {
} elseif (!($result instanceof CakeResponse) &&
$response->body() === null
) {
$response->body($result);
}
$controller->shutdownProcess();
@@ -208,6 +208,16 @@ public function responseGenerator() {
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 @@ public function testDispatchActionReturnsResponse() {
$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
*

0 comments on commit 484801e

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