From 70744f3cb4d6ddbe5b061a868d28c6034eff8383 Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 7 Jul 2011 21:31:28 -0400 Subject: [PATCH] Fixing failing tests for Controller. Adding a string cast for easier testing. --- lib/Cake/Controller/Controller.php | 4 ++-- lib/Cake/Network/CakeResponse.php | 14 ++++++++++++-- lib/Cake/Test/Case/Controller/ControllerTest.php | 11 +++++------ 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/lib/Cake/Controller/Controller.php b/lib/Cake/Controller/Controller.php index 319a5ac25..8f68bf91c 100644 --- a/lib/Cake/Controller/Controller.php +++ b/lib/Cake/Controller/Controller.php @@ -790,7 +790,7 @@ class Controller extends Object { * * @param string $view View to use for rendering * @param string $layout Layout to use - * @return string Full output string of view contents + * @return CakeResponse A response object containing the rendered view. * @link http://book.cakephp.org/view/980/render */ public function render($view = null, $layout = null) { @@ -880,7 +880,7 @@ class Controller extends Object { $this->set('message', $message); $this->set('pause', $pause); $this->set('page_title', $message); - $this->response->body($this->render(false, $layout)); + $this->render(false, $layout); } /** diff --git a/lib/Cake/Network/CakeResponse.php b/lib/Cake/Network/CakeResponse.php index 9b91f5315..db97d0eb3 100644 --- a/lib/Cake/Network/CakeResponse.php +++ b/lib/Cake/Network/CakeResponse.php @@ -300,7 +300,7 @@ class CakeResponse { * * @var string */ - protected $_body = null; + protected $_body = ''; /** * The charset the response body is encoded with @@ -654,4 +654,14 @@ class CakeResponse { public function download($filename) { $this->header('Content-Disposition', 'attachment; filename="' . $filename . '"'); } -} \ No newline at end of file + +/** + * String conversion. Fetches the response body as a string. + * Does *not* send headers. + * + * @return string + */ + public function __toString() { + return $this->_body; + } +} diff --git a/lib/Cake/Test/Case/Controller/ControllerTest.php b/lib/Cake/Test/Case/Controller/ControllerTest.php index 185ea5252..e7ecf224d 100644 --- a/lib/Cake/Test/Case/Controller/ControllerTest.php +++ b/lib/Cake/Test/Case/Controller/ControllerTest.php @@ -525,8 +525,7 @@ class ControllerTest extends CakeTestCase { $request->webroot = '/'; $request->base = '/'; - $Controller = new Controller($request); - $Controller->response = $this->getMock('CakeResponse', array('_sendHeader')); + $Controller = new Controller($request, $this->getMock('CakeResponse', array('_sendHeader'))); $Controller->flash('this should work', '/flash'); $result = $Controller->response->body(); @@ -622,14 +621,14 @@ class ControllerTest extends CakeTestCase { $Controller->viewPath = 'Posts'; $result = $Controller->render('index'); - $this->assertPattern('/posts index/', $result); + $this->assertPattern('/posts index/', (string)$result); $Controller->view = 'index'; $result = $Controller->render(); - $this->assertPattern('/posts index/', $result); + $this->assertPattern('/posts index/', (string)$result); $result = $Controller->render('/Elements/test_element'); - $this->assertPattern('/this is the test element/', $result); + $this->assertPattern('/this is the test element/', (string)$result); $Controller->view = null; $Controller = new TestController($request, new CakeResponse()); @@ -677,7 +676,7 @@ class ControllerTest extends CakeTestCase { $Controller->viewPath = 'Posts'; $Controller->theme = 'TestTheme'; $result = $Controller->render('index'); - $this->assertPattern('/default test_theme layout/', $result); + $this->assertPattern('/default test_theme layout/', (string)$result); App::build(); }