From c34845e2e2753a14d2cc6290e94c36d56d8c9a7a Mon Sep 17 00:00:00 2001 From: sam_marshall Date: Thu, 27 Nov 2008 13:41:08 +0000 Subject: [PATCH] MDL-17425: Unit test system - improved reporting of moodle_exception --- admin/report/unittest/ex_reporter.php | 32 +++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/admin/report/unittest/ex_reporter.php b/admin/report/unittest/ex_reporter.php index 741ed9b08e..1b0cb231b9 100644 --- a/admin/report/unittest/ex_reporter.php +++ b/admin/report/unittest/ex_reporter.php @@ -81,7 +81,7 @@ class ExHtmlReporter extends HtmlReporter { /** * Private method. Used by printPass/Fail/Error. */ - function _paintPassFail($passorfail, $message) { + function _paintPassFail($passorfail, $message, $rawmessage=false) { global $FULLME, $CFG; print_simple_box_start('', '100%', '', 5, $passorfail . ' generalbox'); @@ -99,7 +99,7 @@ class ExHtmlReporter extends HtmlReporter { } echo "strrunonlyfile\">$file"; echo $this->strseparator, implode($this->strseparator, $breadcrumb); - echo $this->strseparator, '
', $this->_htmlEntities($message), "\n\n"; + echo '
', ($rawmessage ? $message : $this->_htmlEntities($message)), "\n\n"; print_simple_box_end(); flush(); } @@ -128,6 +128,34 @@ class ExHtmlReporter extends HtmlReporter { } } + function paintException($exception) { + SimpleReporter::paintException($exception); + + $message = 'Unexpected exception of type [' . s(get_class($exception)) . + '] with message ['. s($exception->getMessage()) . + '] in ['. s($exception->getFile()) . + ' line ' . s($exception->getLine()) . ']'; + + if(is_a($exception,'moodle_exception')) { + $message.='

Error string: '.s($exception->errorcode). + ' from '.s($exception->module).''; + if($exception->a!==null) { + $message.='('.s($exception->a).')'; + } + $message.=' – '.get_string($exception->errorcode, + $exception->module,$exception->a).''; + if($exception->link) { + $message.='
Link: '.s($exception->link).''; + } + if($exception->debuginfo) { + // Note debug info is not escaped so may contain formatting + $message.='
'.$exception->debuginfo.'
'; + } + } + + $this->_paintPassFail('exception', $message,true); + } + /** * Output anything that should appear above all the test output. */ -- 2.39.5