00001 <?php 00002 00003 include_once('UnitTestSkin.class.php'); 00004 00012 class standard extends unitTestSkin 00013 { 00017 public function standard() 00018 { 00019 $this->_testCount = 0; 00020 $this->_reportedCompareCount = 0; 00021 } 00022 00034 public function begin() 00035 { 00036 echo('<html>'); 00037 $this->_writeHtmlHead(); 00038 echo('<body>'); 00039 00040 echo('<div class="bodyarea">'); 00041 echo('<h1>FareOffice Unit Tester</h1>'); 00042 00043 echo('<div class="toolbar">'); 00044 $this->_writeToolBar(); 00045 echo('</div>'); 00046 00047 echo('<div class="contentarea">'); 00048 } 00049 00055 public function end() 00056 { 00057 if ($this->_testCount) 00058 { 00059 echo('<br/><b>Finish</b><br/>'); 00060 } 00061 else 00062 { 00063 echo('You must choose a test case to run.'); 00064 } 00065 echo('</div>'); 00066 00067 echo('<div class="filebrowser">'); 00068 $this->_writeFileBrowser(); 00069 echo('</div>'); 00070 00071 echo('<div class="status">'); 00072 $this->_writeStatus(); 00073 echo('</div>'); 00074 00075 echo('</div>'); 00076 echo('</body>'); 00077 echo('</html>'); 00078 } 00079 00083 private function _writeHtmlHead() 00084 { 00085 echo('<head>'); 00086 echo('<title>'); 00087 echo('FareOffice Unit Tester '); 00088 echo('</title>'); 00089 00090 echo('<meta name="author" content="Daniel Lindh, aka Arlukin, aka Master Po" />'); 00091 echo('<meta name="robots" content="noindex,nofollow" />'); 00092 echo('<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-15" />'); 00093 00094 $this->_writeCSSStyle(); 00095 echo('</head>'); 00096 } 00097 00101 private function _writeCSSStyle() 00102 { 00103 ?> 00104 <style> 00105 <!-- 00106 body 00107 { 00108 font-family: Courier New; 00109 font-size: 10pt; 00110 } 00111 00112 h1 00113 { 00114 text-align:center; 00115 } 00116 00117 h2 00118 { 00119 margin-bottom: 0px; 00120 } 00121 00122 .contentarea, .filebrowser, .status, .bodyarea 00123 { 00124 margin: 5px; 00125 padding: 5px; 00126 width: auto; 00127 float: left; 00128 border: 1px solid #0000ff; 00129 } 00130 00131 .toolbar 00132 { 00133 margin: 5px; 00134 padding: 5px; 00135 width: auto; 00136 border: 1px solid #0000ff; 00137 float: top; 00138 } 00139 00140 .bodyarea 00141 { 00142 border: 0px 00143 } 00144 00145 a:link, a:visited 00146 { 00147 color:"#003399"; 00148 text-decoration: none; 00149 } 00150 00151 a:hover 00152 { 00153 color: #FF00FF 00154 } 00155 00156 td 00157 { 00158 font-size: 10pt; 00159 padding: 1px; 00160 vertical-align: top; 00161 } 00162 00163 --> 00164 </style> 00165 <?php 00166 } 00167 00171 private function _writeToolBar() 00172 { 00173 $this->_writeStatusChanger(); 00174 $this->_writeRunAllTests(); 00175 $this->_writeTestCaseNavigator(); 00176 } 00177 00181 private function _writeStatusChanger() 00182 { 00183 if ($this->getParent()->getOnlyReportFailes()) 00184 { 00185 echo('<b><a href="' . $this->_getUrlArgument(false, -1) . '">'); 00186 echo('[Only Report Fails]'); 00187 echo('</a></b>'); 00188 } 00189 else 00190 { 00191 echo('<a href="' . $this->_getUrlArgument(true, -1) . '">'); 00192 echo('[Only Report Fails]'); 00193 echo('</a>'); 00194 } 00195 00196 echo(' '); 00197 00198 if ($this->getParent()->getReportFailDetails()) 00199 { 00200 echo('<b><a href="'.$this->_getUrlArgument(-1, false).'">'); 00201 echo('[Details About Fails]'); 00202 echo('</a></b>'); 00203 } 00204 else 00205 { 00206 echo('<a href="'.$this->_getUrlArgument(-1, true).'">'); 00207 echo('[Details About Fails]'); 00208 echo('</a>'); 00209 } 00210 00211 echo(' '); 00212 } 00213 00217 private function _writeRunAllTests() 00218 { 00219 echo('<a href="'.$this->_getUrlArgument(-1, -1, -1, true).'">[RUN ALL TESTS]</a> '); 00220 } 00221 00225 private function _writeTestCaseNavigator() 00226 { 00227 $currentTestCase = $this->getParent()->getCurrentTestCase(); 00228 $total = $this->getParent()->getNumOfTestCases(); 00229 00230 if ($currentTestCase > 1) 00231 { 00232 echo('<b><a href="' . $this->_getUrlArgument(-1, -1, $currentTestCase-1) . '">[Back]</a></b>'); 00233 } 00234 else 00235 { 00236 echo('[Back]'); 00237 } 00238 00239 echo(' ' . $currentTestCase . '/' . $total . ' '); 00240 00241 if ($currentTestCase < $total ) 00242 { 00243 echo('<b><a href="' . $this->_getUrlArgument(-1, -1, $currentTestCase+1) . '">[Next]</a></b>'); 00244 } 00245 else 00246 { 00247 echo('[Next]'); 00248 } 00249 } 00250 00256 private function _writeFileBrowser() 00257 { 00258 foreach($this->getParent()->getTestCaseFiles() as $key => $row) 00259 { 00260 if ($row['package'] != $oldPackage) 00261 { 00262 echo('<B>'.$row['package'].'</B><br/>'); 00263 $oldPackage = $row['package']; 00264 } 00265 00266 if ($key == $this->getParent()->getCurrentTestCase()) 00267 { 00268 echo('<b> <a href="' . $this->_getUrlArgument(-1, -1, $key) . '">'.$row['class_name'] . '</a></b><br/>'); 00269 } 00270 else 00271 { 00272 echo(' <a href="' . $this->_getUrlArgument(-1, -1, $key) . '">'.$row['class_name'] . '</a><br/>'); 00273 } 00274 } 00275 } 00276 00280 private function _writeStatus() 00281 { 00282 echo('Reported tests: ' . $this->_reportedCompareCount . '<br/>'); 00283 echo('Executed tests: ' . $this->_testCount . '<br/>'); 00284 } 00285 00290 private function _getUrlArgument 00291 ( 00292 $onlyReportFailes_ = -1, 00293 $echoDetails_ = -1, 00294 $currentTestCase_ = -1, 00295 $runAllTests_ = -1 00296 ) 00297 { 00298 if ((int)$onlyReportFailes_ == -1) 00299 { 00300 $onlyReportFailes_ = $this->getParent()->getOnlyReportFailes(); 00301 } 00302 00303 if ((int)$echoDetails_ == -1) 00304 { 00305 $echoDetails_ = $this->getParent()->getReportFailDetails(); 00306 } 00307 00308 if ((int)$currentTestCase_ == -1) 00309 { 00310 $currentTestCase_ = $this->getParent()->getCurrentTestCase(); 00311 } 00312 00313 if ((int)$runAllTests_ == -1) 00314 { 00315 $runAllTests_ = 0; 00316 } 00317 00318 $str = '?formOnlyReportFailes=' . $onlyReportFailes_; 00319 $str .= '&formEchoDetails=' . $echoDetails_; 00320 $str .= '&formTestCase=' . $currentTestCase_; 00321 $str .= '&formRunAllTests=' . $runAllTests_; 00322 00323 return $str; 00324 } 00325 00331 public function writeGuiResult($testResult) 00332 { 00333 foreach($testResult as $_testCount => $row) 00334 { 00335 $this->_testCount++; 00336 $this->_writeTestCaseName($row['status'], $row['class_name']); 00337 $this->_writeSectionLabel($row['status'], $row['section_label'], $row['section_text']); 00338 00339 if ($row['status'] == true) 00340 { 00341 $this->_writeSuccededTest($row['type'], $row['code']); 00342 } 00343 else 00344 { 00345 $this->_writeFailedTest($row['type'], $row['code'], $row['file']); 00346 $this->_writeFailDetails($row['return'], $row['expected_return'], $row['fail_comment']); 00347 } 00348 } 00349 } 00350 00354 private function _getTestCount() 00355 { 00356 return str_pad($this->_testCount, 4, '0', STR_PAD_LEFT); 00357 } 00358 00364 private function _writeTestCaseName($status_, $className_) 00365 { 00366 if 00367 ( 00368 $className_ != $this->_oldClassName && 00369 ( 00370 $status_ == false || 00371 !$this->getParent()->getOnlyReportFailes() 00372 ) 00373 ) 00374 { 00375 echo('<h2>' . $className_ . '</h2>'); 00376 00377 $this->_oldClassName = $className_; 00378 } 00379 } 00380 00384 private function _writeSectionLabel($status_, $sectionLabel_, $sectionTextArr_) 00385 { 00386 if 00387 ( 00388 $sectionLabel_ != $this->_oldSectionLabel && 00389 ( 00390 $status_ == false || 00391 !$this->getParent()->getOnlyReportFailes() 00392 ) 00393 ) 00394 { 00395 echo('<br/>'); 00396 echo('<b>' . $sectionLabel_ . '</b><br/>'); 00397 00398 foreach($sectionTextArr_ as $text) 00399 { 00400 echo($text . '<br/>'); 00401 } 00402 00403 $this->_oldSectionLabel = $sectionLabel_; 00404 } 00405 } 00406 00412 private function _writeSuccededTest($type_, $code_) 00413 { 00414 if (!$this->getParent()->getOnlyReportFailes()) 00415 { 00416 $this->_reportedCompareCount++; 00417 echo($this->_getTestCount() . ' OK - ' . $type_ . ' - ' . $code_ . '<br/>'); 00418 } 00419 } 00420 00424 private function _writeFailedTest($type_, $code_, $file_) 00425 { 00426 $this->_reportedCompareCount++; 00427 echo($this->_getTestCount() . ' <font color="red">ERROR - ' . $type_ . ' - ' . $code_ . '</font><br/>'); 00428 echo('File: <font color="red">' . $file_ . '</font><br/>'); 00429 } 00430 00434 private function _writeFailDetails($value1_, $value2_, $comment_) 00435 { 00436 if ($this->getParent()->getReportFailDetails()) 00437 { 00438 $this->_writeFailComment($comment_); 00439 $this->_writeReturnVariable($value1_, $value2_); 00440 $this->_writeExpectedReturnVariable($value1_, $value2_); 00441 echo('<br/>'); 00442 } 00443 } 00444 00448 private function _writeFailComment($comment_) 00449 { 00450 if (!empty($comment_)) 00451 { 00452 echo($comment_); 00453 echo('<br/>'); 00454 } 00455 } 00456 00482 private function _writeReturnVariable($value1_, $value2_) 00483 { 00484 echo('<i><b>Return:</b></i><br/>'); 00485 00486 if (is_array($value1_)) 00487 { 00488 $search = array("'", '"', '<br/>', "\t", ' '); 00489 $replace = array("\'", '\"', '', '', ''); 00490 echo('<pre>' . getHtmlArrayPhp($value1_) . '</pre>'); 00491 echo('Copy:<br/>\'' . str_replace($search, $replace, getHtmlArrayPhp($value1_)) . '\'<br/>'); 00492 echo('<br/>'); 00493 echo('Difference:' . getHtmlArray(array_diff_assoc_recursive($value1_, $value2_))); 00494 } 00495 else 00496 { 00497 $search = array("'", '"'); 00498 $replace = array("\'", '\"'); 00499 echo($this->getVariableInfo($value1_).'<br/>'); 00500 echo('Copy:<br/>\'"' . htmlentities(str_replace($search, $replace, $value1_)).'"\'<br/>'); 00501 } 00502 } 00503 00529 private function _writeExpectedReturnVariable($value1_, $value2_) 00530 { 00531 echo('<i><b>Expected return:</b></i><br/>'); 00532 if (is_array($value2_)) 00533 { 00534 echo('<pre>'.getHtmlArrayPhp($value2_).'</pre>'); 00535 echo('<br/>'); 00536 echo('Difference:' . getHtmlArray(array_diff_assoc_recursive($value2_, $value1_))); 00537 } 00538 else 00539 { 00540 echo($this->getVariableInfo($value2_).'<br/>'); 00541 } 00542 } 00543 00549 function getVariableInfo($value) 00550 { 00551 if (is_bool($value) ) 00552 { 00553 if ($value) 00554 { 00555 $humanReadableValue = 'true'; 00556 } 00557 else 00558 { 00559 $humanReadableValue = 'false'; 00560 } 00561 } 00562 else 00563 { 00564 $humanReadableValue = $value; 00565 } 00566 00567 return gettype($value).'('.strlen($value).') "'.$humanReadableValue.'"'; 00568 } 00569 00573 private $_reportedCompareCount; 00574 00578 private $_testCount; 00579 00584 private $_oldClassName; 00585 } 00586 00587 ?>