00001 <?php
00002
00003
00010 class HtmlReporter extends SimpleReporter {
00011 var $_character_set;
00012
00019 function HtmlReporter($character_set = 'ISO-8859-1') {
00020 $this->SimpleReporter();
00021 $this->_character_set = $character_set;
00022 }
00023
00030 function paintHeader($test_name) {
00031 $this->sendNoCacheHeaders();
00032 print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">";
00033 print "<html>\n<head>\n<title>$test_name</title>\n";
00034 print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=". $this->_character_set ."\">\n";
00035 print "<style type=\"text/css\">\n";
00036 print $this->_getCss() ."\n";
00037 print "</style>\n";
00038 print "</head>\n<body>\n";
00039 print "<h1>$test_name</h1>\n";
00040 flush();
00041 }
00042
00050 function sendNoCacheHeaders() {
00051 if (!headers_sent()) {
00052 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
00053 header("Last-Modified: ". gmdate("D, d M Y H:i:s") ." GMT");
00054 header("Cache-Control: no-store, no-cache, must-revalidate");
00055 header("Cache-Control: post-check=0, pre-check=0", false);
00056 header("Pragma: no-cache");
00057 }
00058 }
00059
00065 function _getCss() {
00066 return ".fail { background-color: inherit; color: red; }".".pass { background-color: inherit; color: green; }"." pre { background-color: lightgray; color: inherit; }";
00067 }
00068
00075 function paintFooter($test_name) {
00076 $colour = ($this->getFailCount() + $this->getExceptionCount() > 0 ? "red" : "green");
00077 print "<div style=\"";
00078 print "padding: 8px; margin-top: 1em; background-color: $colour; color: white;";
00079 print "\">";
00080 print $this->getTestCaseProgress() ."/". $this->getTestCaseCount();
00081 print " test cases complete:\n";
00082 print "<strong>". $this->getPassCount() ."</strong> passes, ";
00083 print "<strong>". $this->getFailCount() ."</strong> fails and ";
00084 print "<strong>". $this->getExceptionCount() ."</strong> exceptions.";
00085 print "</div>\n";
00086 print "</body>\n</html>\n";
00087 }
00088
00097 function paintFail($message) {
00098 parent::paintFail($message);
00099 print "<span class=\"fail\">Fail</span>: ";
00100 $breadcrumb = $this->getTestList();
00101 array_shift($breadcrumb);
00102 print implode(" -> ", $breadcrumb);
00103 print " -> ". $this->_htmlEntities($message) ."<br />\n";
00104 }
00105
00111 function paintError($message) {
00112 parent::paintError($message);
00113 print "<span class=\"fail\">Exception</span>: ";
00114 $breadcrumb = $this->getTestList();
00115 array_shift($breadcrumb);
00116 print implode(" -> ", $breadcrumb);
00117 print " -> <strong>". $this->_htmlEntities($message) ."</strong><br />\n";
00118 }
00119
00125 function paintException($exception) {
00126 parent::paintException($exception);
00127 print "<span class=\"fail\">Exception</span>: ";
00128 $breadcrumb = $this->getTestList();
00129 array_shift($breadcrumb);
00130 print implode(" -> ", $breadcrumb);
00131 $message = 'Unexpected exception of type [' . get_class($exception) . '] with message [' . $exception->getMessage() . '] in [' . $exception->getFile() . ' line ' . $exception->getLine() . ']';
00132 print " -> <strong>". $this->_htmlEntities($message) ."</strong><br />\n";
00133 }
00134
00140 function paintSkip($message) {
00141 parent::paintSkip($message);
00142 print "<span class=\"pass\">Skipped</span>: ";
00143 $breadcrumb = $this->getTestList();
00144 array_shift($breadcrumb);
00145 print implode(" -> ", $breadcrumb);
00146 print " -> ". $this->_htmlEntities($message) ."<br />\n";
00147 }
00148
00154 function paintFormattedMessage($message) {
00155 print '<pre>' . $this->_htmlEntities($message) . '</pre>';
00156 }
00157
00164 function _htmlEntities($message) {
00165 return htmlentities($message, ENT_COMPAT, $this->_character_set);
00166 }
00167 }
00168
00178 class TextReporter extends SimpleReporter {
00179
00185 function TextReporter() {
00186 $this->SimpleReporter();
00187 }
00188
00194 function paintHeader($test_name) {
00195 if (!SimpleReporter::inCli()) {
00196 header('Content-type: text/plain');
00197 }
00198 print "$test_name\n";
00199 flush();
00200 }
00201
00208 function paintFooter($test_name) {
00209 if ($this->getFailCount() + $this->getExceptionCount() == 0) {
00210 print "OK\n";
00211 }
00212 else {
00213 print "FAILURES!!!\n";
00214 }
00215 print "Test cases run: ". $this->getTestCaseProgress() ."/". $this->getTestCaseCount() .", Passes: ". $this->getPassCount() .", Failures: ". $this->getFailCount() .", Exceptions: ". $this->getExceptionCount() ."\n";
00216 }
00217
00224 function paintFail($message) {
00225 parent::paintFail($message);
00226 print $this->getFailCount() .") $message\n";
00227 $breadcrumb = $this->getTestList();
00228 array_shift($breadcrumb);
00229 print "\tin ". implode("\n\tin ", array_reverse($breadcrumb));
00230 print "\n";
00231 }
00232
00239 function paintError($message) {
00240 parent::paintError($message);
00241 print "Exception ". $this->getExceptionCount() ."!\n$message\n";
00242 $breadcrumb = $this->getTestList();
00243 array_shift($breadcrumb);
00244 print "\tin ". implode("\n\tin ", array_reverse($breadcrumb));
00245 print "\n";
00246 }
00247
00254 function paintException($exception) {
00255 parent::paintException($exception);
00256 $message = 'Unexpected exception of type [' . get_class($exception) . '] with message [' . $exception->getMessage() . '] in [' . $exception->getFile() . ' line ' . $exception->getLine() . ']';
00257 print "Exception ". $this->getExceptionCount() ."!\n$message\n";
00258 $breadcrumb = $this->getTestList();
00259 array_shift($breadcrumb);
00260 print "\tin ". implode("\n\tin ", array_reverse($breadcrumb));
00261 print "\n";
00262 }
00263
00269 function paintSkip($message) {
00270 parent::paintSkip($message);
00271 print "Skip: $message\n";
00272 }
00273
00279 function paintFormattedMessage($message) {
00280 print "$message\n";
00281 flush();
00282 }
00283 }