[ Index ]
 

Code source de PRADO 3.0.6

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/tests/test_tools/simpletest/ -> reporter.php (source)

   1  <?php
   2      /**
   3       *    base include file for SimpleTest
   4       *    @package    SimpleTest
   5       *    @subpackage    UnitTester
   6       *    @version    $Id: reporter.php 1526 2006-11-28 23:34:00Z wei $
   7       */
   8  
   9      /**#@+
  10       *    include other SimpleTest class files
  11       */
  12      require_once(dirname(__FILE__) . '/scorer.php');
  13      /**#@-*/
  14  
  15      /**
  16       *    Sample minimal test displayer. Generates only
  17       *    failure messages and a pass count.
  18       *      @package SimpleTest
  19       *      @subpackage UnitTester
  20       */
  21      class HtmlReporter extends SimpleReporter {
  22          protected $_character_set;
  23  
  24          /**
  25           *    Does nothing yet. The first output will
  26           *    be sent on the first test start. For use
  27           *    by a web browser.
  28           *    @access public
  29           */
  30          function HtmlReporter($character_set = 'ISO-8859-1') {
  31              $this->SimpleReporter();
  32              $this->_character_set = $character_set;
  33          }
  34  
  35          /**
  36           *    Paints the top of the web page setting the
  37           *    title to the name of the starting test.
  38           *    @param string $test_name      Name class of test.
  39           *    @access public
  40           */
  41          function paintHeader($test_name) {
  42              $this->sendNoCacheHeaders();
  43              print "<html>\n<head>\n<title>$test_name</title>\n";
  44              print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=" .
  45                      $this->_character_set . "\">\n";
  46              print "<style type=\"text/css\">\n";
  47              print $this->_getCss() . "\n";
  48              print "</style>\n";
  49              print "</head>\n<body>\n";
  50              print "<h1>$test_name</h1>\n";
  51              flush();
  52          }
  53  
  54          /**
  55           *    Send the headers necessary to ensure the page is
  56           *    reloaded on every request. Otherwise you could be
  57           *    scratching your head over out of date test data.
  58           *    @access public
  59           *    @static
  60           */
  61          static function sendNoCacheHeaders() {
  62              if (! headers_sent()) {
  63                  header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
  64                  header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
  65                  header("Cache-Control: no-store, no-cache, must-revalidate");
  66                  header("Cache-Control: post-check=0, pre-check=0", false);
  67                  header("Pragma: no-cache");
  68              }
  69          }
  70  
  71          /**
  72           *    Paints the CSS. Add additional styles here.
  73           *    @return string            CSS code as text.
  74           *    @access protected
  75           */
  76          function _getCss() {
  77              return ".fail { color: red; } pre { background-color: lightgray; }";
  78          }
  79  
  80          /**
  81           *    Paints the end of the test with a summary of
  82           *    the passes and failures.
  83           *    @param string $test_name        Name class of test.
  84           *    @access public
  85           */
  86          function paintFooter($test_name) {
  87              $colour = ($this->getFailCount() + $this->getExceptionCount() > 0 ? "red" : "green");
  88              print "<div style=\"";
  89              print "padding: 8px; margin-top: 1em; background-color: $colour; color: white;";
  90              print "\">";
  91              print $this->getTestCaseProgress() . "/" . $this->getTestCaseCount();
  92              print " test cases complete:\n";
  93              print "<strong>" . $this->getPassCount() . "</strong> passes, ";
  94              print "<strong>" . $this->getFailCount() . "</strong> fails and ";
  95              print "<strong>" . $this->getExceptionCount() . "</strong> exceptions.";
  96              print "</div>\n";
  97              print "</body>\n</html>\n";
  98          }
  99  
 100          /**
 101           *    Paints the test failure with a breadcrumbs
 102           *    trail of the nesting test suites below the
 103           *    top level test.
 104           *    @param string $message    Failure message displayed in
 105           *                              the context of the other tests.
 106           *    @access public
 107           */
 108          function paintFail($message) {
 109              parent::paintFail($message);
 110              print "<span class=\"fail\">Fail</span>: ";
 111              $breadcrumb = $this->getTestList();
 112              array_shift($breadcrumb);
 113              print implode(" -&gt; ", $breadcrumb);
 114              print " -&gt; " . $this->_htmlEntities($message) . "<br />\n";
 115          }
 116  
 117          /**
 118           *    Paints a PHP error or exception.
 119           *    @param string $message        Message is ignored.
 120           *    @access public
 121           *    @abstract
 122           */
 123          function paintError($message) {
 124              parent::paintError($message);
 125              print "<span class=\"fail\">Exception</span>: ";
 126              $breadcrumb = $this->getTestList();
 127              array_shift($breadcrumb);
 128              print implode(" -&gt; ", $breadcrumb);
 129              print " -&gt; <strong>" . $this->_htmlEntities($message) . "</strong><br />\n";
 130          }
 131  
 132          /**
 133           *    Paints formatted text such as dumped variables.
 134           *    @param string $message        Text to show.
 135           *    @access public
 136           */
 137          function paintFormattedMessage($message) {
 138              print '<pre>' . $this->_htmlEntities($message) . '</pre>';
 139          }
 140  
 141          /**
 142           *    Character set adjusted entity conversion.
 143           *    @param string $message    Plain text or Unicode message.
 144           *    @return string            Browser readable message.
 145           *    @access protected
 146           */
 147          function _htmlEntities($message) {
 148              return htmlentities($message, ENT_COMPAT, $this->_character_set);
 149          }
 150      }
 151  
 152      /**
 153       *    Sample minimal test displayer. Generates only
 154       *    failure messages and a pass count. For command
 155       *    line use. I've tried to make it look like JUnit,
 156       *    but I wanted to output the errors as they arrived
 157       *    which meant dropping the dots.
 158       *      @package SimpleTest
 159       *      @subpackage UnitTester
 160       */
 161      class TextReporter extends SimpleReporter {
 162  
 163          /**
 164           *    Does nothing yet. The first output will
 165           *    be sent on the first test start.
 166           *    @access public
 167           */
 168          function TextReporter() {
 169              $this->SimpleReporter();
 170          }
 171  
 172          /**
 173           *    Paints the title only.
 174           *    @param string $test_name        Name class of test.
 175           *    @access public
 176           */
 177          function paintHeader($test_name) {
 178              if (! SimpleReporter::inCli()) {
 179                  header('Content-type: text/plain');
 180              }
 181              print "$test_name\n";
 182              flush();
 183          }
 184  
 185          /**
 186           *    Paints the end of the test with a summary of
 187           *    the passes and failures.
 188           *    @param string $test_name        Name class of test.
 189           *    @access public
 190           */
 191          function paintFooter($test_name) {
 192              if ($this->getFailCount() + $this->getExceptionCount() == 0) {
 193                  print "OK\n";
 194              } else {
 195                  print "FAILURES!!!\n";
 196              }
 197              print "Test cases run: " . $this->getTestCaseProgress() .
 198                      "/" . $this->getTestCaseCount() .
 199                      ", Passes: " . $this->getPassCount() .
 200                      ", Failures: " . $this->getFailCount() .
 201                      ", Exceptions: " . $this->getExceptionCount() . "\n";
 202          }
 203  
 204          /**
 205           *    Paints the test failure as a stack trace.
 206           *    @param string $message    Failure message displayed in
 207           *                              the context of the other tests.
 208           *    @access public
 209           */
 210          function paintFail($message) {
 211              parent::paintFail($message);
 212              print $this->getFailCount() . ") $message\n";
 213              $breadcrumb = $this->getTestList();
 214              array_shift($breadcrumb);
 215              print "\tin " . implode("\n\tin ", array_reverse($breadcrumb));
 216              print "\n";
 217          }
 218  
 219          /**
 220           *    Paints a PHP error or exception.
 221           *    @param string $message        Message is ignored.
 222           *    @access public
 223           *    @abstract
 224           */
 225          function paintError($message) {
 226              parent::paintError($message);
 227              print "Exception " . $this->getExceptionCount() . "!\n$message\n";
 228          }
 229  
 230          /**
 231           *    Paints formatted text such as dumped variables.
 232           *    @param string $message        Text to show.
 233           *    @access public
 234           */
 235          function paintFormattedMessage($message) {
 236              print "$message\n";
 237              flush();
 238          }
 239      }
 240  
 241      /**
 242       *    Runs just a single test group, a single case or
 243       *    even a single test within that case.
 244       *      @package SimpleTest
 245       *      @subpackage UnitTester
 246       */
 247      class SelectiveReporter extends SimpleReporterDecorator {
 248          protected $_just_this_case =false;
 249          protected $_just_this_test = false;
 250          protected $_within_test_case = true;
 251  
 252          /**
 253           *    Selects the test case or group to be run,
 254           *    and optionally a specific test.
 255           *    @param SimpleScorer $reporter    Reporter to receive events.
 256           *    @param string $just_this_case    Only this case or group will run.
 257           *    @param string $just_this_test    Only this test method will run.
 258           */
 259          function SelectiveReporter($reporter, $just_this_case = false, $just_this_test = false) {
 260              if (isset($just_this_case) && $just_this_case) {
 261                  $this->_just_this_case = strtolower($just_this_case);
 262                  $this->_within_test_case = false;
 263              }
 264              if (isset($just_this_test) && $just_this_test) {
 265                  $this->_just_this_test = strtolower($just_this_test);
 266              }
 267              $this->SimpleReporterDecorator($reporter);
 268          }
 269  
 270          /**
 271           *    Compares criteria to actual the case/group name.
 272           *    @param string $test_case    The incoming test.
 273           *    @return boolean             True if matched.
 274           *    @access protected
 275           */
 276          function _isCaseMatch($test_case) {
 277              if ($this->_just_this_case) {
 278                  return $this->_just_this_case == strtolower($test_case);
 279              }
 280              return false;
 281          }
 282  
 283          /**
 284           *    Compares criteria to actual the test name.
 285           *    @param string $method       The incoming test method.
 286           *    @return boolean             True if matched.
 287           *    @access protected
 288           */
 289          function _isTestMatch($method) {
 290              if ($this->_just_this_test) {
 291                  return $this->_just_this_test == strtolower($method);
 292              }
 293              return true;
 294          }
 295  
 296          /**
 297           *    Veto everything that doesn't match the method wanted.
 298           *    @param string $test_case       Name of test case.
 299           *    @param string $method          Name of test method.
 300           *    @return boolean                True if test should be run.
 301           *    @access public
 302           */
 303          function shouldInvoke($test_case, $method) {
 304              if ($this->_within_test_case && $this->_isTestMatch($method)) {
 305                  return $this->_reporter->shouldInvoke($test_case, $method);
 306              }
 307              return false;
 308          }
 309  
 310          /**
 311           *    Paints the start of a group test.
 312           *    @param string $test_case     Name of test or other label.
 313           *    @param integer $size         Number of test cases starting.
 314           *    @access public
 315           */
 316          function paintGroupStart($test_case, $size) {
 317              if ($this->_isCaseMatch($test_case)) {
 318                  $this->_within_test_case = true;
 319              }
 320              if ($this->_within_test_case) {
 321                  $this->_reporter->paintGroupStart($test_case, $size);
 322              }
 323          }
 324  
 325          /**
 326           *    Paints the end of a group test.
 327           *    @param string $test_case     Name of test or other label.
 328           *    @access public
 329           */
 330          function paintGroupEnd($test_case) {
 331              if ($this->_within_test_case) {
 332                  $this->_reporter->paintGroupEnd($test_case);
 333              }
 334              if ($this->_isCaseMatch($test_case)) {
 335                  $this->_within_test_case = false;
 336              }
 337          }
 338  
 339          /**
 340           *    Paints the start of a test case.
 341           *    @param string $test_case     Name of test or other label.
 342           *    @access public
 343           */
 344          function paintCaseStart($test_case) {
 345              if ($this->_isCaseMatch($test_case)) {
 346                  $this->_within_test_case = true;
 347              }
 348              if ($this->_within_test_case) {
 349                  $this->_reporter->paintCaseStart($test_case);
 350              }
 351          }
 352  
 353          /**
 354           *    Paints the end of a test case.
 355           *    @param string $test_case     Name of test or other label.
 356           *    @access public
 357           */
 358          function paintCaseEnd($test_case) {
 359              if ($this->_within_test_case) {
 360                  $this->_reporter->paintCaseEnd($test_case);
 361              }
 362              if ($this->_isCaseMatch($test_case)) {
 363                  $this->_within_test_case = false;
 364              }
 365          }
 366      }
 367  ?>


Généré le : Sun Feb 25 21:07:04 2007 par Balluche grâce à PHPXref 0.7