2008-05-30 11:40:08 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2010-01-06 01:44:15 +00:00
|
|
|
* CakeHtmlReporter
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
|
|
|
* PHP versions 4 and 5
|
|
|
|
*
|
|
|
|
* CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite>
|
2009-11-06 06:46:59 +00:00
|
|
|
* Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
|
|
|
* Licensed under The Open Group Test Suite License
|
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
2009-11-06 06:46:59 +00:00
|
|
|
* @copyright Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2010-01-06 01:44:15 +00:00
|
|
|
* @link http://cakephp.org
|
2008-10-30 17:30:26 +00:00
|
|
|
* @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
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-01-06 01:29:08 +00:00
|
|
|
include_once dirname(__FILE__) . DS . 'cake_base_reporter.php';
|
2010-01-06 01:44:15 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2009-09-13 17:11:37 +00:00
|
|
|
* CakeHtmlReporter Reports Results of TestSuites and Test Cases
|
|
|
|
* in an HTML format / context.
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2009-09-13 17:11:37 +00:00
|
|
|
* @package cake
|
2010-01-03 05:33:17 +00:00
|
|
|
* @subpackage cake.tests.lib
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
|
|
|
class CakeHtmlReporter extends SimpleReporter {
|
2010-01-03 05:33:17 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Character set for the output of test reporting.
|
|
|
|
*
|
|
|
|
* @var string
|
2010-01-06 01:52:22 +00:00
|
|
|
* @access protected
|
2010-01-03 05:33:17 +00:00
|
|
|
*/
|
2008-06-10 22:38:05 +00:00
|
|
|
var $_character_set;
|
2010-01-03 05:33:17 +00:00
|
|
|
/**
|
|
|
|
* Toggle to show passes in output.
|
|
|
|
*
|
|
|
|
* @var boolean
|
|
|
|
* @access protected
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
var $_show_passes = false;
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2010-01-03 05:33:17 +00:00
|
|
|
/**
|
|
|
|
* Time the test runs started.
|
|
|
|
*
|
|
|
|
* @var integer
|
|
|
|
* @access protected
|
|
|
|
*/
|
2009-09-13 17:29:44 +00:00
|
|
|
var $_timeStart = 0;
|
2010-01-03 05:33:17 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Time the test runs ended
|
|
|
|
*
|
|
|
|
* @var integer
|
|
|
|
* @access protected
|
|
|
|
*/
|
2009-09-13 17:29:44 +00:00
|
|
|
var $_timeEnd = 0;
|
2010-01-03 05:33:17 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Duration of all test methods.
|
|
|
|
*
|
|
|
|
* @var integer
|
|
|
|
* @access protected
|
|
|
|
*/
|
2009-09-13 17:29:44 +00:00
|
|
|
var $_timeDuration = 0;
|
|
|
|
|
2008-06-10 22:38:05 +00:00
|
|
|
/**
|
2009-09-13 17:11:37 +00:00
|
|
|
* Does nothing yet. The first output will
|
|
|
|
* be sent on the first test start. For use
|
|
|
|
* by a web browser.
|
|
|
|
*
|
|
|
|
* @access public
|
2008-06-10 22:38:05 +00:00
|
|
|
*/
|
|
|
|
function CakeHtmlReporter($character_set = 'ISO-8859-1') {
|
2008-05-30 11:40:08 +00:00
|
|
|
if (isset($_GET['show_passes']) && $_GET['show_passes']) {
|
|
|
|
$this->_show_passes = true;
|
|
|
|
}
|
2008-06-10 22:38:05 +00:00
|
|
|
$this->SimpleReporter();
|
|
|
|
$this->_character_set = $character_set;
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-10 22:38:05 +00:00
|
|
|
/**
|
|
|
|
* Paints the top of the web page setting the
|
|
|
|
* title to the name of the starting test.
|
2009-09-13 17:11:37 +00:00
|
|
|
*
|
|
|
|
* @param string $test_name Name class of test.
|
2010-01-06 01:56:25 +00:00
|
|
|
* @return void
|
2008-06-10 22:38:05 +00:00
|
|
|
* @access public
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function paintHeader($testName) {
|
|
|
|
$this->sendNoCacheHeaders();
|
2008-06-10 22:38:05 +00:00
|
|
|
echo "<h2>$testName</h2>\n";
|
|
|
|
echo "<ul class='tests'>\n";
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-10 22:38:05 +00:00
|
|
|
/**
|
|
|
|
* 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.
|
2009-09-13 17:11:37 +00:00
|
|
|
*
|
2010-01-06 01:56:25 +00:00
|
|
|
* @return void
|
2008-06-10 22:38:05 +00:00
|
|
|
* @access public
|
|
|
|
*/
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-10 22:38:05 +00:00
|
|
|
/**
|
|
|
|
* Paints the end of the test with a summary of
|
|
|
|
* the passes and failures.
|
2009-09-13 17:11:37 +00:00
|
|
|
*
|
|
|
|
* @param string $test_name Name class of test.
|
2010-01-06 01:56:25 +00:00
|
|
|
* @return void
|
2008-06-10 22:38:05 +00:00
|
|
|
* @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";
|
2009-09-13 17:29:44 +00:00
|
|
|
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>';
|
2008-06-10 22:38:05 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-10 22:38:05 +00:00
|
|
|
/**
|
|
|
|
* Paints the test failure with a breadcrumbs
|
|
|
|
* trail of the nesting test suites below the
|
|
|
|
* top level test.
|
2009-09-13 17:11:37 +00:00
|
|
|
*
|
2008-06-10 22:38:05 +00:00
|
|
|
* @param string $message Failure message displayed in
|
2009-09-13 17:11:37 +00:00
|
|
|
* the context of the other tests.
|
2010-01-06 01:56:25 +00:00
|
|
|
* @return void
|
2008-06-10 22:38:05 +00:00
|
|
|
* @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";
|
2010-01-06 01:52:22 +00:00
|
|
|
$breadcrumb = $this->getTestList();
|
2008-05-30 11:40:08 +00:00
|
|
|
array_shift($breadcrumb);
|
2008-06-10 22:38:05 +00:00
|
|
|
echo "<div>" . implode(" -> ", $breadcrumb) . "</div>\n";
|
|
|
|
echo "</li>\n";
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-10 22:38:05 +00:00
|
|
|
/**
|
|
|
|
* Paints the test pass with a breadcrumbs
|
|
|
|
* trail of the nesting test suites below the
|
|
|
|
* top level test.
|
2009-09-13 17:11:37 +00:00
|
|
|
*
|
|
|
|
* @param string $message Pass message displayed in the context of the other tests.
|
2010-01-06 01:56:25 +00:00
|
|
|
* @return void
|
2008-06-10 22:38:05 +00:00
|
|
|
* @access public
|
|
|
|
*/
|
|
|
|
function paintPass($message) {
|
|
|
|
parent::paintPass($message);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
if ($this->_show_passes) {
|
2008-06-10 22:38:05 +00:00
|
|
|
echo "<li class='pass'>\n";
|
|
|
|
echo "<span>Passed</span> ";
|
2010-01-06 01:52:22 +00:00
|
|
|
$breadcrumb = $this->getTestList();
|
2008-05-30 11:40:08 +00:00
|
|
|
array_shift($breadcrumb);
|
2008-06-10 22:38:05 +00:00
|
|
|
echo implode(" -> ", $breadcrumb);
|
|
|
|
echo "<br />" . $this->_htmlEntities($message) . "\n";
|
|
|
|
echo "</li>\n";
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2008-06-10 22:38:05 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-10 22:38:05 +00:00
|
|
|
/**
|
|
|
|
* Paints a PHP error.
|
2009-09-13 17:11:37 +00:00
|
|
|
*
|
2008-06-10 22:38:05 +00:00
|
|
|
* @param string $message Message is ignored.
|
2010-01-06 01:56:25 +00:00
|
|
|
* @return void
|
2008-06-10 22:38:05 +00:00
|
|
|
* @access public
|
|
|
|
*/
|
|
|
|
function paintError($message) {
|
|
|
|
parent::paintError($message);
|
2008-12-13 23:40:36 +00:00
|
|
|
echo "<li class='error'>\n";
|
2008-06-10 22:38:05 +00:00
|
|
|
echo "<span>Error</span>";
|
|
|
|
echo "<div class='msg'>" . $this->_htmlEntities($message) . "</div>\n";
|
2010-01-06 01:52:22 +00:00
|
|
|
$breadcrumb = $this->getTestList();
|
2008-05-30 11:40:08 +00:00
|
|
|
array_shift($breadcrumb);
|
2008-06-10 22:38:05 +00:00
|
|
|
echo "<div>" . implode(" -> ", $breadcrumb) . "</div>\n";
|
|
|
|
echo "</li>\n";
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-10 22:38:05 +00:00
|
|
|
/**
|
|
|
|
* Paints a PHP exception.
|
2009-09-13 17:11:37 +00:00
|
|
|
*
|
2008-06-10 22:38:05 +00:00
|
|
|
* @param Exception $exception Exception to display.
|
2010-01-06 01:56:25 +00:00
|
|
|
* @return void
|
2008-06-10 22:38:05 +00:00
|
|
|
* @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";
|
2010-01-06 01:52:22 +00:00
|
|
|
$breadcrumb = $this->getTestList();
|
2008-05-30 11:40:08 +00:00
|
|
|
array_shift($breadcrumb);
|
2008-06-10 22:38:05 +00:00
|
|
|
echo "<div>" . implode(" -> ", $breadcrumb) . "</div>\n";
|
|
|
|
echo "</li>\n";
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-10 22:38:05 +00:00
|
|
|
/**
|
|
|
|
* Prints the message for skipping tests.
|
2009-09-13 17:11:37 +00:00
|
|
|
*
|
2010-01-06 01:56:25 +00:00
|
|
|
* @param string $message Text of skip condition.
|
|
|
|
* @return void
|
2008-06-10 22:38:05 +00:00
|
|
|
* @access public
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
function paintSkip($message) {
|
2008-06-10 22:38:05 +00:00
|
|
|
parent::paintSkip($message);
|
|
|
|
echo "<li class='skipped'>\n";
|
|
|
|
echo "<span>Skipped</span> ";
|
|
|
|
echo $this->_htmlEntities($message);
|
|
|
|
echo "</li>\n";
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-10 22:38:05 +00:00
|
|
|
/**
|
|
|
|
* Paints formatted text such as dumped variables.
|
2009-09-13 17:11:37 +00:00
|
|
|
*
|
2008-06-10 22:38:05 +00:00
|
|
|
* @param string $message Text to show.
|
2010-01-06 01:56:25 +00:00
|
|
|
* @return void
|
2008-06-10 22:38:05 +00:00
|
|
|
* @access public
|
|
|
|
*/
|
|
|
|
function paintFormattedMessage($message) {
|
|
|
|
echo '<pre>' . $this->_htmlEntities($message) . '</pre>';
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-10 22:38:05 +00:00
|
|
|
/**
|
|
|
|
* Character set adjusted entity conversion.
|
2009-09-13 17:11:37 +00:00
|
|
|
*
|
2008-06-10 22:38:05 +00:00
|
|
|
* @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);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|