123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446 |
- <?php
-
-
-
- require_once(dirname(__FILE__) . '/scorer.php');
-
-
-
- class HtmlReporter extends SimpleReporter {
- private $character_set;
-
-
-
- function __construct($character_set = 'ISO-8859-1') {
- parent::__construct();
- $this->character_set = $character_set;
- }
-
-
-
- function paintHeader($test_name) {
- $this->sendNoCacheHeaders();
- print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">";
- print "<html>\n<head>\n<title>$test_name</title>\n";
- print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=" .
- $this->character_set . "\">\n";
- print "<style type=\"text/css\">\n";
- print $this->getCss() . "\n";
- print "</style>\n";
- print "</head>\n<body>\n";
- print "<h1>$test_name</h1>\n";
- flush();
- }
-
-
-
- static function sendNoCacheHeaders() {
- if (! headers_sent()) {
- header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
- header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
- header("Cache-Control: no-store, no-cache, must-revalidate");
- header("Cache-Control: post-check=0, pre-check=0", false);
- header("Pragma: no-cache");
- }
- }
-
-
-
- protected function getCss() {
- return ".fail { background-color: inherit; color: red; }" .
- ".pass { background-color: inherit; color: green; }" .
- " pre { background-color: lightgray; color: inherit; }";
- }
-
-
-
- function paintFooter($test_name) {
- $colour = ($this->getFailCount() + $this->getExceptionCount() > 0 ? "red" : "green");
- print "<div style=\"";
- print "padding: 8px; margin-top: 1em; background-color: $colour; color: white;";
- print "\">";
- print $this->getTestCaseProgress() . "/" . $this->getTestCaseCount();
- print " test cases complete:\n";
- print "<strong>" . $this->getPassCount() . "</strong> passes, ";
- print "<strong>" . $this->getFailCount() . "</strong> fails and ";
- print "<strong>" . $this->getExceptionCount() . "</strong> exceptions.";
- print "</div>\n";
- print "</body>\n</html>\n";
- }
-
-
-
- function paintFail($message) {
- parent::paintFail($message);
- print "<span class=\"fail\">Fail</span>: ";
- $breadcrumb = $this->getTestList();
- array_shift($breadcrumb);
- print implode(" -> ", $breadcrumb);
- print " -> " . $this->htmlEntities($message) . "<br />\n";
- }
-
-
-
- function paintError($message) {
- parent::paintError($message);
- print "<span class=\"fail\">Exception</span>: ";
- $breadcrumb = $this->getTestList();
- array_shift($breadcrumb);
- print implode(" -> ", $breadcrumb);
- print " -> <strong>" . $this->htmlEntities($message) . "</strong><br />\n";
- }
-
-
-
- function paintException($exception) {
- parent::paintException($exception);
- print "<span class=\"fail\">Exception</span>: ";
- $breadcrumb = $this->getTestList();
- array_shift($breadcrumb);
- print implode(" -> ", $breadcrumb);
- $message = 'Unexpected exception of type [' . get_class($exception) .
- '] with message ['. $exception->getMessage() .
- '] in ['. $exception->getFile() .
- ' line ' . $exception->getLine() . ']';
- print " -> <strong>" . $this->htmlEntities($message) . "</strong><br />\n";
- }
-
-
-
- function paintSkip($message) {
- parent::paintSkip($message);
- print "<span class=\"pass\">Skipped</span>: ";
- $breadcrumb = $this->getTestList();
- array_shift($breadcrumb);
- print implode(" -> ", $breadcrumb);
- print " -> " . $this->htmlEntities($message) . "<br />\n";
- }
-
-
-
- function paintFormattedMessage($message) {
- print '<pre>' . $this->htmlEntities($message) . '</pre>';
- }
-
-
-
- protected function htmlEntities($message) {
- return htmlentities($message, ENT_COMPAT, $this->character_set);
- }
- }
-
-
- class TextReporter extends SimpleReporter {
-
-
-
- function __construct() {
- parent::__construct();
- }
-
-
-
- function paintHeader($test_name) {
- if (! SimpleReporter::inCli()) {
- header('Content-type: text/plain');
- }
- print "$test_name\n";
- flush();
- }
-
-
-
- function paintFooter($test_name) {
- if ($this->getFailCount() + $this->getExceptionCount() == 0) {
- print "OK\n";
- } else {
- print "FAILURES!!!\n";
- }
- print "Test cases run: " . $this->getTestCaseProgress() .
- "/" . $this->getTestCaseCount() .
- ", Passes: " . $this->getPassCount() .
- ", Failures: " . $this->getFailCount() .
- ", Exceptions: " . $this->getExceptionCount() . "\n";
- }
-
-
-
- function paintFail($message) {
- parent::paintFail($message);
- print $this->getFailCount() . ") $message\n";
- $breadcrumb = $this->getTestList();
- array_shift($breadcrumb);
- print "\tin " . implode("\n\tin ", array_reverse($breadcrumb));
- print "\n";
- }
-
-
-
- function paintError($message) {
- parent::paintError($message);
- print "Exception " . $this->getExceptionCount() . "!\n$message\n";
- $breadcrumb = $this->getTestList();
- array_shift($breadcrumb);
- print "\tin " . implode("\n\tin ", array_reverse($breadcrumb));
- print "\n";
- }
-
-
-
- function paintException($exception) {
- parent::paintException($exception);
- $message = 'Unexpected exception of type [' . get_class($exception) .
- '] with message ['. $exception->getMessage() .
- '] in ['. $exception->getFile() .
- ' line ' . $exception->getLine() . ']';
- print "Exception " . $this->getExceptionCount() . "!\n$message\n";
- $breadcrumb = $this->getTestList();
- array_shift($breadcrumb);
- print "\tin " . implode("\n\tin ", array_reverse($breadcrumb));
- print "\n";
- }
-
-
-
- function paintSkip($message) {
- parent::paintSkip($message);
- print "Skip: $message\n";
- }
-
-
-
- function paintFormattedMessage($message) {
- print "$message\n";
- flush();
- }
- }
-
-
- class SelectiveReporter extends SimpleReporterDecorator {
- private $just_this_case = false;
- private $just_this_test = false;
- private $on;
-
-
-
- function __construct($reporter, $just_this_case = false, $just_this_test = false) {
- if (isset($just_this_case) && $just_this_case) {
- $this->just_this_case = strtolower($just_this_case);
- $this->off();
- } else {
- $this->on();
- }
- if (isset($just_this_test) && $just_this_test) {
- $this->just_this_test = strtolower($just_this_test);
- }
- parent::__construct($reporter);
- }
-
-
-
- protected function matchesTestCase($test_case) {
- return $this->just_this_case == strtolower($test_case);
- }
-
-
-
- protected function shouldRunTest($test_case, $method) {
- if ($this->isOn() || $this->matchesTestCase($test_case)) {
- if ($this->just_this_test) {
- return $this->just_this_test == strtolower($method);
- } else {
- return true;
- }
- }
- return false;
- }
-
-
-
- protected function on() {
- $this->on = true;
- }
-
-
-
- protected function off() {
- $this->on = false;
- }
-
-
-
- protected function isOn() {
- return $this->on;
- }
-
-
-
- function shouldInvoke($test_case, $method) {
- if ($this->shouldRunTest($test_case, $method)) {
- return $this->reporter->shouldInvoke($test_case, $method);
- }
- return false;
- }
-
-
-
- function paintGroupStart($test_case, $size) {
- if ($this->just_this_case && $this->matchesTestCase($test_case)) {
- $this->on();
- }
- $this->reporter->paintGroupStart($test_case, $size);
- }
-
-
-
- function paintGroupEnd($test_case) {
- $this->reporter->paintGroupEnd($test_case);
- if ($this->just_this_case && $this->matchesTestCase($test_case)) {
- $this->off();
- }
- }
- }
-
-
- class NoSkipsReporter extends SimpleReporterDecorator {
-
-
-
- function paintSkip($message) { }
- }
- ?>
|