diff --git a/control/Controller.php b/control/Controller.php index e722090a8..136217ead 100644 --- a/control/Controller.php +++ b/control/Controller.php @@ -157,9 +157,9 @@ class Controller extends RequestHandler implements TemplateGlobalProvider { . "returning it without modification."); } $this->response = $body; - + } else { - if(is_object($body)) { + if($body instanceof Object && $body->hasMethod('getViewer')) { if(isset($_REQUEST['debug_request'])) { Debug::message("Request handler $body->class object to $this->class controller;" . "rendering with template returned by $body->class::getViewer()"); diff --git a/control/HTTPResponse.php b/control/HTTPResponse.php index a7661e7b3..5489a8949 100644 --- a/control/HTTPResponse.php +++ b/control/HTTPResponse.php @@ -159,7 +159,7 @@ class SS_HTTPResponse { * @return SS_HTTPRequest $this */ public function setBody($body) { - $this->body = $body; + $this->body = $body ? (string)$body : $body; // Don't type-cast false-ish values, eg null is null not '' } /** diff --git a/control/PjaxResponseNegotiator.php b/control/PjaxResponseNegotiator.php index 3d6b499f0..b22779eee 100644 --- a/control/PjaxResponseNegotiator.php +++ b/control/PjaxResponseNegotiator.php @@ -79,7 +79,8 @@ class PjaxResponseNegotiator { // Execute the fragment callbacks and build the response. foreach($fragments as $fragment) { if(isset($callbacks[$fragment])) { - $responseParts[$fragment] = call_user_func($callbacks[$fragment]); + $res = call_user_func($callbacks[$fragment]); + $responseParts[$fragment] = $res ? (string)$res : $res; } else { throw new SS_HTTPResponse_Exception("X-Pjax = '$fragment' not supported for this URL.", 400); } diff --git a/dev/SapphireTest.php b/dev/SapphireTest.php index 464431335..260c785ac 100644 --- a/dev/SapphireTest.php +++ b/dev/SapphireTest.php @@ -510,6 +510,17 @@ class SapphireTest extends PHPUnit_Framework_TestCase { $controller->response->removeHeader('Location'); } } + + public static function assertContains($needle, $haystack, $message = '', $ignoreCase = FALSE, $checkForObjectIdentity = TRUE) { + if ($haystack instanceof DBField) $haystack = (string)$haystack; + parent::assertContains($needle, $haystack, $message, $ignoreCase, $checkForObjectIdentity); + } + + public static function assertNotContains($needle, $haystack, $message = '', $ignoreCase = FALSE, $checkForObjectIdentity = TRUE) { + if ($haystack instanceof DBField) $haystack = (string)$haystack; + parent::assertNotContains($needle, $haystack, $message, $ignoreCase, $checkForObjectIdentity); + } + /** * Clear the log of emails sent */ diff --git a/model/fieldtypes/DBField.php b/model/fieldtypes/DBField.php index e535f69b2..d883cb16e 100644 --- a/model/fieldtypes/DBField.php +++ b/model/fieldtypes/DBField.php @@ -295,5 +295,8 @@ abstract class DBField extends ViewableData { DBG; } - + + public function __toString() { + return $this->forTemplate(); + } } diff --git a/view/SSViewer.php b/view/SSViewer.php index 701fd50d4..ae9b6a3a6 100644 --- a/view/SSViewer.php +++ b/view/SSViewer.php @@ -866,7 +866,7 @@ class SSViewer { * @param ViewableData $item * @param SS_Cache $cache Optional cache backend. * - * @return String Parsed template output. + * @return HTMLText Parsed template output. */ public function process($item, $arguments = null) { SSViewer::$topLevel[] = $item; @@ -909,12 +909,7 @@ class SSViewer { $subtemplateViewer->includeRequirements(false); $subtemplateViewer->setPartialCacheStore($this->getPartialCacheStore()); - $underlay[$subtemplate] = DBField::create_field( - 'HTMLText', - $subtemplateViewer->process($item, $arguments), - $subtemplate, - array('shortcodes' => false) - ); + $underlay[$subtemplate] = $subtemplateViewer->process($item, $arguments); } } @@ -939,7 +934,7 @@ class SSViewer { } } - return $output; + return DBField::create_field('HTMLText', $output, null, array('shortcodes' => false)); } /** diff --git a/view/ViewableData.php b/view/ViewableData.php index 548f2ad14..bed2084f9 100644 --- a/view/ViewableData.php +++ b/view/ViewableData.php @@ -318,7 +318,7 @@ class ViewableData extends Object implements IteratorAggregate { * * @param string|array|SSViewer $template the template to render into * @param array $customFields fields to customise() the object with before rendering - * @return string + * @return HTMLText */ public function renderWith($template, $customFields = null) { if(!is_object($template)) {