diff --git a/lib/Cake/Routing/Dispatcher.php b/lib/Cake/Routing/Dispatcher.php index fd7a87258..7e482115b 100644 --- a/lib/Cake/Routing/Dispatcher.php +++ b/lib/Cake/Routing/Dispatcher.php @@ -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(); diff --git a/lib/Cake/Test/Case/Routing/DispatcherTest.php b/lib/Cake/Test/Case/Routing/DispatcherTest.php index f31259776..d24368fa9 100644 --- a/lib/Cake/Test/Case/Routing/DispatcherTest.php +++ b/lib/Cake/Test/Case/Routing/DispatcherTest.php @@ -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 *