public function __toString() { try { return $this->render(); } catch (Exception $e) { // php doesn't allow exceptions to be thrown inside __toString() so we need an extra try/catch block here if ($this->response == null) { return "WikiaView: response object was null rendering {$this->templatePath}"; } if ($this->response->getException() == null) { $this->response->setException($e); } return F::app()->getView('WikiaError', 'error', array('response' => $this->response, 'devel' => F::app()->wg->DevelEnvironment))->render(); } }
/** * * @dataProvider formatDataProvider */ public function testView($format) { $this->object->setFormat($format); $this->object->getView()->setTemplatePath(dirname(__FILE__) . '/_fixtures/TestTemplate.php'); $this->object->setVal(self::TEST_VAL_NAME, self::TEST_VAL_VALUE); if ($format == 'json') { $this->object->setException(new WikiaException('TestException')); } $this->object->sendHeaders(); ob_start(); print $this->object; $buffer = ob_get_contents(); ob_end_clean(); if ($format == 'html') { $this->assertEquals(self::TEST_VAL_VALUE, $buffer); } }