[ Index ]
 

Code source de PRADO 3.0.6

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

title

Body

[fermer]

/tests/test_tools/selenium/php/ -> results.php (source)

   1  <?php
   2  
   3  class SeleniumTestCaseResult
   4  {
   5      public $name;
   6      public $commands = array();
   7      public $result = 'passed';
   8      public $failures = array();
   9  }
  10  
  11  class SeleniumTestResult
  12  {
  13      public $result = 'passed';
  14      public $totalTime = 0;
  15      public $numTestPasses = 0;
  16      public $numTestFailures = 0;
  17      public $numCommandPasses = 0;
  18      public $numCommandFailures = 0;
  19      public $numCommandErrors = 0;
  20      public $suites = array();
  21      public $browser = '';
  22      public $date;
  23  
  24  	public function __construct()
  25      {
  26          $this->parse_data();
  27          $this->browser = $_SERVER['HTTP_USER_AGENT'];
  28          $this->date = time();
  29      }
  30  
  31  	protected function parse_data()
  32      {
  33          $this->result = $_POST['result']; // failed || passed
  34          $this->totalTime = $_POST['totalTime'];
  35          $this->numTestPasses = $_POST['numTestPasses'];
  36          $this->numTestFailures = $_POST['numTestFailures'];
  37          $this->numCommandPasses = $_POST['numCommandPasses'];
  38          $this->numCommandFailures = $_POST['numCommandFailures'];
  39          $this->numCommandErrors = $_POST['numCommandErrors'];
  40  
  41          foreach($_POST['tests'] as $test)
  42          {
  43              $case = new SeleniumTestCaseResult();
  44              $case->name = $test['testcase'];
  45              $case->commands = $test['commands'];
  46              for($i = 0; $i < count($case->commands); $i++)
  47              {
  48                  //$trace = $case->commands[$i]['trace'];
  49                  //$trace = html_entity_decode($trace);
  50                  //$case->commands[$i]['trace'] = @unserialize($trace);
  51                  if($case->commands[$i]['result'] == 'failed')
  52                  {
  53                      $case->result = 'failed';
  54                      array_push($case->failures, $case->commands[$i]);
  55                  }
  56              }
  57  
  58              $this->suites[$case->name] = $case;
  59          }
  60  
  61      }
  62  }
  63  
  64  class SeleniumHtmlReporter
  65  {
  66      protected $test;
  67  
  68  	public function __construct($result)
  69      {
  70          $this->test = $result;
  71      }
  72  
  73  	protected function renderHeader()
  74      {
  75          $contents = <<<EOD
  76  <html>
  77  <head>
  78  <title>Functional Test Results</title>
  79  <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
  80  <style type="text/css">
  81  body {font-family:"Verdana";font-weight:normal;color:black;background-color:white;}
  82  .failed { background-color: red; } .error0 { background-color: lightgray; }
  83  .info { padding: 0.5em; margin-top: 1em; color: white; }
  84  .passed { background-color: green; }
  85  .error_case div { padding: 0.3em 0.2em; margin: 0.5em 0; }
  86  .error_msg { padding: 0.5em; border-bottom:1px solid #ccc; }
  87  .msg { color:#c00; }
  88  .function { font-family:"Lucida Console";color: gray;}
  89  .file { border-bottom: 1px dashed gray; }
  90  .env { color: gray; font-size:10pt; padding: 0.5em; }
  91  .odd { background-color: #fee; }
  92  </style>
  93  </head>
  94  <body>
  95  EOD;
  96          return $contents;
  97      }
  98  
  99  	public function render()
 100      {
 101          echo $this->renderHeader();
 102          echo $this->renderBody();
 103          echo $this->renderFooter();
 104      }
 105  
 106  	protected function renderBody()
 107      {
 108          /* SeleniumTestResult */
 109          $test = $this->test;
 110          $total = count($test->suites);
 111          $date = @strftime('%Y-%m-%d %H:%M',$test->date);
 112  $contents = <<<EOD
 113  <h1 class="suite">Functional Test Results</h1>
 114  <div class="info {$test->result}">
 115      <strong>{$total}</strong> test cases completed,
 116      <strong>{$test->numTestPasses}</strong> passes 
 117      ({$test->numCommandPasses} commands), and
 118      <strong>{$test->numTestFailures}</strong> fails
 119      ({$test->numCommandErrors} commands).
 120  </div>
 121  <div class="env">
 122      {$date}, {$test->browser}
 123  </div>
 124  EOD;
 125          $count = 1;
 126          foreach($test->suites as $suite)
 127          {
 128              foreach($suite->failures as $error)
 129                  $contents .= $this->getErrorMsg($suite, $error, $count++);
 130          }
 131  
 132          return $contents;
 133      }
 134  
 135  
 136  	protected function getErrorMsg($suite, $info, $count)
 137      {
 138          $parity = $count%2==0 ? 'even' : 'odd';
 139          $command = explode("|",$info['command']);
 140  $msg = <<<EOD
 141      <div class="error_msg {$parity}">
 142          <strong>#{$count}.</strong>
 143          &quot;<span class="msg">{$info['msg']}</span>&quot; in
 144          <span class="function">
 145              {$suite->name}::{$command[1]}('{$command[2]}');
 146          </span>
 147      </div>
 148  EOD;
 149  
 150          return $msg;
 151      }
 152  
 153  	protected function renderFooter()
 154      {
 155          return "</body></html>";
 156      }
 157  }
 158  
 159  
 160  ?>


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