|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00012 if (!defined("SIMPLE_TEST")) { 00013 define("SIMPLE_TEST", "simpletest/"); 00014 } 00015 require_once(SIMPLE_TEST . 'runner.php'); 00016 require_once(SIMPLE_TEST . 'reporter.php'); 00028 define('SIMPLETEST_WEBUNIT_HEAD', <<<EOS 00029 <html> 00030 <head> 00031 <title>%s</title> 00032 <script type="text/javascript" src="%sx.js"></script> 00033 <script type="text/javascript" src="%swebunit.js"></script> 00034 <link rel="stylesheet" type="text/css" href="%swebunit.css" title="Default"></link> 00035 <style type="text/css"> 00036 %s 00037 </style> 00038 </head> 00039 <body> 00040 <div id="wait"> 00041 <h1> Running %s </h1> 00042 Please wait...<br /> 00043 <img src="%swait.gif" border="0"><br /> 00044 </div> 00045 <script type="text/javascript"> 00046 wait_start(); 00047 </script> 00048 <div id="webunit"> 00049 <div id="run"></div><br /> 00050 <div id="tabs"> 00051 <div id="visible_tab">visible tab content</div> 00052 <span id="failtab" class="activetab"> <a href="javascript:activate_tab('fail');">Fail</a> </span> 00053 <span id="treetab" class="inactivetab"> <a href="javascript:activate_tab('tree');">Tree</a> </span> 00054 </div> 00055 <div id="msg">Click on a failed test case method in the tree tab to view output here.</div> 00056 </div> 00057 <div id="fail"></div> 00058 <div id="tree"></div> 00059 <!-- open a new script to capture js vars as the tests run --> 00060 <script type="text/javascript"> 00061 layout(); 00062 00063 EOS 00064 ); 00065 00070 define('SIMPLETEST_WEBUNIT_CSS', '/* this space reseved for future use */'); 00071 00078 class WebUnitReporter extends SimpleReporter { 00084 var $path; 00085 00092 function WebUnitReporter($path='../ui/') { 00093 $this->SimpleReporter(); 00094 $this->path = $path; 00095 } 00096 00103 function paintHeader($test_name) { 00104 $this->sendNoCacheHeaders(); 00105 echo sprintf( 00106 SIMPLETEST_WEBUNIT_HEAD 00107 ,$test_name 00108 ,$this->path.'js/' 00109 ,$this->path.'js/' 00110 ,$this->path.'css/' 00111 ,$this->_getCss() 00112 ,$test_name 00113 ,$this->path.'img/' 00114 ); 00115 flush(); 00116 } 00117 00125 function sendNoCacheHeaders() { 00126 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); 00127 header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); 00128 header("Cache-Control: no-store, no-cache, must-revalidate"); 00129 header("Cache-Control: post-check=0, pre-check=0", false); 00130 header("Pragma: no-cache"); 00131 } 00132 00138 function _getCss() { 00139 return SIMPLETEST_WEBUNIT_CSS; 00140 } 00141 00148 function paintFooter($test_name) { 00149 echo 'make_tree();</script>'.$this->outputScript("xHide('wait');"); 00150 $colour = ($this->getFailCount() + $this->getExceptionCount() > 0 ? "red" : "green"); 00151 $content = "<h1>$test_name</h1>\n"; 00152 $content .= "<div style=\""; 00153 $content .= "padding: 8px; margin-top: 1em; background-color: $colour; color: white;"; 00154 $content .= "\">"; 00155 $content .= $this->getTestCaseProgress() . "/" . $this->getTestCaseCount(); 00156 $content .= " test cases complete:\n"; 00157 $content .= "<strong>" . $this->getPassCount() . "</strong> passes, "; 00158 $content .= "<strong>" . $this->getFailCount() . "</strong> fails and "; 00159 $content .= "<strong>" . $this->getExceptionCount() . "</strong> exceptions."; 00160 $content .= "</div>\n"; 00161 00162 echo $this->outputScript('foo = "'.$this->toJsString($content).'";'."\nset_div_content('run', foo);"); 00163 echo "\n</body>\n</html>\n"; 00164 } 00165 00166 00172 function paintFormattedMessage($message) { 00173 echo "add_log(\"".$this->toJsString("<pre>$message</pre>", true)."\");\n"; 00174 } 00175 00185 function paintGroupStart($test_name, $size) { 00186 Parent::paintGroupStart($test_name, $size); 00187 echo "add_group('$test_name');\n"; 00188 } 00189 00198 function paintCaseStart($test_name) { 00199 Parent::paintCaseStart($test_name); 00200 echo "add_case('$test_name');\n"; 00201 } 00202 00203 00209 function paintMethodStart($test_name) { 00210 Parent::paintMethodStart($test_name); 00211 echo "add_method('$test_name');\n"; 00212 } 00213 00219 function paintMethodEnd($test_name) { 00220 Parent::paintMethodEnd($test_name); 00221 } 00222 00231 function paintFail($message) { 00232 parent::paintFail($message); 00233 $msg = "<span class=\"fail\">Fail</span>: "; 00234 $breadcrumb = $this->getTestList(); 00235 array_shift($breadcrumb); 00236 $msg .= implode("->", $breadcrumb); 00237 $msg .= "->" . htmlentities($message) . "<br />"; 00238 echo "add_fail('$msg');\n"; 00239 } 00240 00247 function paintException($message) { 00248 parent::paintException($message); 00249 $msg = "<span class=\"fail\">Exception</span>: "; 00250 $breadcrumb = $this->getTestList(); 00251 array_shift($breadcrumb); 00252 $msg .= implode("->", $breadcrumb); 00253 $msg .= "-><strong>" . htmlentities($message) . "</strong><br />"; 00254 echo "add_fail('$msg');\n"; 00255 } 00256 00263 function outputScript($script) 00264 { 00265 return "<script type=\"text/javascript\">\n".$script."\n</script>\n"; 00266 } 00267 00268 00274 function toJsString($str, $preserveCr=false) { 00275 $cr = ($preserveCr) ? '\\n' : ''; 00276 return str_replace( 00277 array('"' 00278 ,"\n") 00279 ,array('\"' 00280 ,"$cr\"\n\t+\"") 00281 ,$str 00282 ); 00283 } 00284 } 00285 00286 ?>