Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 295 lines (275 sloc) 7.976 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295
<?php
/**
* Short description for file.
*
* PHP versions 4 and 5
*
* CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite>
* Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The Open Group Test Suite License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests
* @package cake
* @subpackage cake.cake.tests.libs
* @since CakePHP(tm) v 1.2.0.4433
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
*/

/**
* CakeHtmlReporter Reports Results of TestSuites and Test Cases
* in an HTML format / context.
*
* @package cake
* @subpackage cake.tests.lib
*/
class CakeHtmlReporter extends SimpleReporter {

/**
* Character set for the output of test reporting.
*
* @var string
*/
var $_character_set;
/**
* Toggle to show passes in output.
*
* @var boolean
* @access protected
*/
var $_show_passes = false;

/**
* Time the test runs started.
*
* @var integer
* @access protected
*/
var $_timeStart = 0;

/**
* Time the test runs ended
*
* @var integer
* @access protected
*/
var $_timeEnd = 0;

/**
* Duration of all test methods.
*
* @var integer
* @access protected
*/
var $_timeDuration = 0;

/**
* Does nothing yet. The first output will
* be sent on the first test start. For use
* by a web browser.
*
* @access public
*/
function CakeHtmlReporter($character_set = 'ISO-8859-1') {
if (isset($_GET['show_passes']) && $_GET['show_passes']) {
$this->_show_passes = true;
}
$this->SimpleReporter();
$this->_character_set = $character_set;
}

/**
* Signals / Paints the beginning of a TestSuite executing.
* Starts the timer for the TestSuite execution time.
*
* @param string $test_name Name of the test that is being run.
* @param integer $size
* @return void
*/
function paintGroupStart($test_name, $size) {
if (empty($this->_timeStart)) {
$this->_timeStart = $this->_getTime();
}
parent::paintGroupStart($test_name, $size);
}

/**
* Signals/Paints the end of a TestSuite. All test cases have run
* and timers are stopped.
*
* @param string $test_name Name of the test that is being run.
* @return void
*/
function paintGroupEnd($test_name) {
$this->_timeEnd = $this->_getTime();
$this->_timeDuration = $this->_timeEnd - $this->_timeStart;
parent::paintGroupEnd($test_name);
}

/**
* Get the current time in microseconds. Similar to getMicrotime in basics.php
* but in a separate function to reduce dependancies.
*
* @return float Time in microseconds
*/
function _getTime() {
list($usec, $sec) = explode(' ', microtime());
return ((float)$sec + (float)$usec);
}

/**
* Paints the top of the web page setting the
* title to the name of the starting test.
*
* @param string $test_name Name class of test.
* @access public
*/
function paintHeader($testName) {
$this->sendNoCacheHeaders();
echo "<h2>$testName</h2>\n";
echo "<ul class='tests'>\n";
}

/**
* Send the headers necessary to ensure the page is
* reloaded on every request. Otherwise you could be
* scratching your head over out of date test data.
*
* @access public
* @static
*/
function sendNoCacheHeaders() {
if (!headers_sent()) {
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
}
}

/**
* Paints the end of the test with a summary of
* the passes and failures.
*
* @param string $test_name Name class of test.
* @access public
*/
function paintFooter($test_name) {
$colour = ($this->getFailCount() + $this->getExceptionCount() > 0 ? "red" : "green");
echo "</ul>\n";
echo "<div style=\"";
echo "padding: 8px; margin: 1em 0; background-color: $colour; color: white;";
echo "\">";
echo $this->getTestCaseProgress() . "/" . $this->getTestCaseCount();
echo " test cases complete:\n";
echo "<strong>" . $this->getPassCount() . "</strong> passes, ";
echo "<strong>" . $this->getFailCount() . "</strong> fails and ";
echo "<strong>" . $this->getExceptionCount() . "</strong> exceptions.";
echo "</div>\n";
echo '<div style="padding:0 0 5px;">';
echo '<p><strong>Time taken by tests (in seconds):</strong> ' . $this->_timeDuration . '</p>';
if (function_exists('memory_get_peak_usage')) {
echo '<p><strong>Peak memory use: (in bytes):</strong> ' . number_format(memory_get_peak_usage()) . '</p>';
}
echo '</div>';
}

/**
* Paints the test failure with a breadcrumbs
* trail of the nesting test suites below the
* top level test.
*
* @param string $message Failure message displayed in
* the context of the other tests.
* @access public
*/
function paintFail($message) {
parent::paintFail($message);
echo "<li class='fail'>\n";
echo "<span>Failed</span>";
echo "<div class='msg'>" . $this->_htmlEntities($message) . "</div>\n";
$breadcrumb = Set::filter($this->getTestList());
array_shift($breadcrumb);
echo "<div>" . implode(" -&gt; ", $breadcrumb) . "</div>\n";
echo "</li>\n";
}

/**
* Paints the test pass with a breadcrumbs
* trail of the nesting test suites below the
* top level test.
*
* @param string $message Pass message displayed in the context of the other tests.
* @access public
*/
function paintPass($message) {
parent::paintPass($message);

if ($this->_show_passes) {
echo "<li class='pass'>\n";
echo "<span>Passed</span> ";
$breadcrumb = Set::filter($this->getTestList());
array_shift($breadcrumb);
echo implode(" -&gt; ", $breadcrumb);
echo "<br />" . $this->_htmlEntities($message) . "\n";
echo "</li>\n";
}
}

/**
* Paints a PHP error.
*
* @param string $message Message is ignored.
* @access public
*/
function paintError($message) {
parent::paintError($message);
echo "<li class='error'>\n";
echo "<span>Error</span>";
echo "<div class='msg'>" . $this->_htmlEntities($message) . "</div>\n";
$breadcrumb = Set::filter($this->getTestList());
array_shift($breadcrumb);
echo "<div>" . implode(" -&gt; ", $breadcrumb) . "</div>\n";
echo "</li>\n";
}

/**
* Paints a PHP exception.
*
* @param Exception $exception Exception to display.
* @access public
*/
function paintException($exception) {
parent::paintException($exception);
echo "<li class='fail'>\n";
echo "<span>Exception</span>";
$message = 'Unexpected exception of type [' . get_class($exception) .
'] with message ['. $exception->getMessage() .
'] in ['. $exception->getFile() .
' line ' . $exception->getLine() . ']';
echo "<div class='msg'>" . $this->_htmlEntities($message) . "</div>\n";
$breadcrumb = Set::filter($this->getTestList());
array_shift($breadcrumb);
echo "<div>" . implode(" -&gt; ", $breadcrumb) . "</div>\n";
echo "</li>\n";
}

/**
* Prints the message for skipping tests.
*
* @param string $message Text of skip condition.
* @access public
*/
function paintSkip($message) {
parent::paintSkip($message);
echo "<li class='skipped'>\n";
echo "<span>Skipped</span> ";
echo $this->_htmlEntities($message);
echo "</li>\n";
}

/**
* Paints formatted text such as dumped variables.
*
* @param string $message Text to show.
* @access public
*/
function paintFormattedMessage($message) {
echo '<pre>' . $this->_htmlEntities($message) . '</pre>';
}

/**
* Character set adjusted entity conversion.
*
* @param string $message Plain text or Unicode message.
* @return string Browser readable message.
* @access protected
*/
function _htmlEntities($message) {
return htmlentities($message, ENT_COMPAT, $this->_character_set);
}
}
?>
Something went wrong with that request. Please try again.