[ Index ]
 

Code source de LifeType 1.2.4

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/class/test/helpers/ -> htmlreporter.class.php (source)

   1  <?php
   2  
   3      lt_include( PLOG_CLASS_PATH."class/test/PHPUnit/TestResult.php" );
   4  
   5      /**
   6       * \ingroup Test
   7       *
   8       * A nicer test reporter that generates readable HTML output out of the results
   9       * of running a test suite, see runtests.php and the TestRunner class for more
  10       * information.
  11       */
  12      class HTMLReporter
  13      {
  14          var $_result;
  15          
  16  		function HTMLReporter( $result )
  17          {
  18              $this->_result = $result;
  19          }
  20          
  21  		function _getHeader()
  22          {
  23              return('
  24                      <h1>Test Report</h1>
  25                      <table cols="4" border="1" width="100%">
  26                      <thead style="text-align:left">
  27                       <th width="20%">Group</th>
  28                       <th width="20%">Test</th>
  29                       <th width="10%">Status</th>
  30                       <th width="50%">Message</th>
  31                      </thead>
  32                      <tbody>
  33                    ');
  34          }
  35          
  36  		function _getFooter()
  37          {
  38              return( '</tbody>
  39                       </table>
  40                      <a href="javascript:history.go(0)">Run Again</a>&nbsp;
  41                      <a href="?suite=">Back to List</a>
  42                      '.$this->_getStats().'
  43                    ');
  44          }
  45          
  46  		function _cleanGroupName( $group )
  47          {
  48              $group = strtolower( $group );
  49              $group = str_replace( "_test", "", $group );
  50              return( $group );
  51          }
  52          
  53  		function _getPassed( $test, $group = "" )
  54          {
  55              return( '<tr>
  56                        <td><b>'.$this->_cleanGroupName($group).'</b></td>            
  57                        <td>'.$test->getName().'</td>
  58                        <td style="background-color:green">PASSED</td>
  59                        <td></td>
  60                       ');
  61          }
  62          
  63  		function _getFailed( $test, $group = "" )
  64          {
  65              return( '<tr>
  66                        <td><b>'.$this->_cleanGroupName($group).'</b></td>
  67                        <td>'.$test->_failedTest->getName().'</td>
  68                        <td style="background-color:red">FAILED</td>
  69                        <td>'.$test->_thrownException.'</td>
  70                       ');            
  71          }
  72          
  73  		function _getStats()
  74          {
  75              return( '<h1>Test Stats</h1>
  76                       <b>Number of tests: </b>'.$this->_result->runCount().'<br/>
  77                       <b>Number of tests passed: </b>'.($this->_result->runCount() - $this->_result->failureCount()).'<br/>
  78                       <b>Number of tests failed: </b>'.$this->_result->failureCount().'<br/>
  79                     ');
  80          }
  81          
  82  		function generate()
  83          {
  84              $groups = $this->_prepare();
  85              
  86              $result = $this->_getHeader();
  87      
  88              foreach( $groups as $group => $tests ) {
  89                  $i=0;
  90                  foreach( $tests as $test ) {
  91                      $i++;
  92                      $i == 1 ? $groupName = $group : $groupName = "";
  93                      if( isset( $test->_failedTest )) {
  94                          $result .= $this->_getFailed( $test, $groupName );
  95                      }
  96                      else {
  97                          $result .= $this->_getPassed( $test, $groupName );
  98                      }
  99                  }
 100              }
 101  
 102              $result .= $this->_getFooter();
 103              return( $result );
 104          }
 105          
 106  		function _prepare()
 107          {
 108              $groups = Array();
 109              foreach ($this->_result->_passedTests as $passedTest) {
 110                  $groups[get_class($passedTest)][] = $passedTest;
 111              }                
 112              foreach ($this->_result->_failures as $failedTest) {
 113                  $groups[get_class($failedTest->_failedTest)][] = $failedTest;
 114              }
 115      
 116              return( $groups );
 117          }
 118      }
 119  ?>


Généré le : Mon Nov 26 21:04:15 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics