* Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org) * * Licensed under The Open Group Test Suite License * Redistributions of files must retain the above copyright notice. * * @filesource * @copyright Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.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 * @version $Revision$ * @modifiedby $LastChangedBy$ * @lastmodified $Date$ * @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.cake.tests.lib */ class CakeHtmlReporter extends SimpleReporter { var $_character_set; var $_show_passes = false; var $_timeStart = 0; var $_timeEnd = 0; 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 * @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. * * @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 "

$testName

\n"; echo "\n"; echo "
"; echo $this->getTestCaseProgress() . "/" . $this->getTestCaseCount(); echo " test cases complete:\n"; echo "" . $this->getPassCount() . " passes, "; echo "" . $this->getFailCount() . " fails and "; echo "" . $this->getExceptionCount() . " exceptions."; echo "
\n"; echo '
'; echo '

Time taken by tests (in seconds): ' . $this->_timeDuration . '

'; if (function_exists('memory_get_peak_usage')) { echo '

Peak memory use: (in bytes): ' . number_format(memory_get_peak_usage()) . '

'; } echo '
'; } /** * 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 "
  • \n"; echo "Failed"; echo "
    " . $this->_htmlEntities($message) . "
    \n"; $breadcrumb = Set::filter($this->getTestList()); array_shift($breadcrumb); echo "
    " . implode(" -> ", $breadcrumb) . "
    \n"; echo "
  • \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 "
  • \n"; echo "Passed "; $breadcrumb = Set::filter($this->getTestList()); array_shift($breadcrumb); echo implode(" -> ", $breadcrumb); echo "
    " . $this->_htmlEntities($message) . "\n"; echo "
  • \n"; } } /** * Paints a PHP error. * * @param string $message Message is ignored. * @access public */ function paintError($message) { parent::paintError($message); echo "
  • \n"; echo "Error"; echo "
    " . $this->_htmlEntities($message) . "
    \n"; $breadcrumb = Set::filter($this->getTestList()); array_shift($breadcrumb); echo "
    " . implode(" -> ", $breadcrumb) . "
    \n"; echo "
  • \n"; } /** * Paints a PHP exception. * * @param Exception $exception Exception to display. * @access public */ function paintException($exception) { parent::paintException($exception); echo "
  • \n"; echo "Exception"; $message = 'Unexpected exception of type [' . get_class($exception) . '] with message ['. $exception->getMessage() . '] in ['. $exception->getFile() . ' line ' . $exception->getLine() . ']'; echo "
    " . $this->_htmlEntities($message) . "
    \n"; $breadcrumb = Set::filter($this->getTestList()); array_shift($breadcrumb); echo "
    " . implode(" -> ", $breadcrumb) . "
    \n"; echo "
  • \n"; } /** * Prints the message for skipping tests. * * @param string $message Text of skip condition. * @access public */ function paintSkip($message) { parent::paintSkip($message); echo "
  • \n"; echo "Skipped "; echo $this->_htmlEntities($message); echo "
  • \n"; } /** * Paints formatted text such as dumped variables. * * @param string $message Text to show. * @access public */ function paintFormattedMessage($message) { echo '
    ' . $this->_htmlEntities($message) . '
    '; } /** * 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); } } ?>