Permalink
Browse files

Fixing failing tests for Controller.

Adding a string cast for easier testing.
  • Loading branch information...
markstory committed Jul 8, 2011
1 parent b0749ac commit 70744f3cb4d6ddbe5b061a868d28c6034eff8383
@@ -790,7 +790,7 @@ public function validateErrors() {
*
* @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 @@ public function flash($message, $url, $pause = 1, $layout = 'flash') {
$this->set('message', $message);
$this->set('pause', $pause);
$this->set('page_title', $message);
- $this->response->body($this->render(false, $layout));
+ $this->render(false, $layout);
}
/**
@@ -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 @@ public function compress() {
public function download($filename) {
$this->header('Content-Disposition', 'attachment; filename="' . $filename . '"');
}
-}
+
+/**
+ * String conversion. Fetches the response body as a string.
+ * Does *not* send headers.
+ *
+ * @return string
+ */
+ public function __toString() {
+ return $this->_body;
+ }
+}
@@ -525,8 +525,7 @@ public function testFlash() {
$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 @@ public function testRender() {
$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 @@ public function testComponentBeforeRenderChangingViewClass() {
$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();
}

0 comments on commit 70744f3

Please sign in to comment.