PageRenderTime 48ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/cake/cake/tests/lib/cake_reporter.php

http://skygames.googlecode.com/
PHP | 207 lines | 108 code | 1 blank | 98 comment | 4 complexity | 32aab742c820aeec110765fbccb894e6 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, CC-BY-SA-3.0
  1. <?php
  2. /* SVN FILE: $Id: cake_reporter.php 7805 2008-10-30 17:30:26Z AD7six $ */
  3. /**
  4. * Short description for file.
  5. *
  6. * Long description for file
  7. *
  8. * PHP versions 4 and 5
  9. *
  10. * CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite>
  11. * Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
  12. *
  13. * Licensed under The Open Group Test Suite License
  14. * Redistributions of files must retain the above copyright notice.
  15. *
  16. * @filesource
  17. * @copyright Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
  18. * @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests
  19. * @package cake
  20. * @subpackage cake.cake.tests.libs
  21. * @since CakePHP(tm) v 1.2.0.4433
  22. * @version $Revision: 7805 $
  23. * @modifiedby $LastChangedBy: AD7six $
  24. * @lastmodified $Date: 2008-10-30 12:30:26 -0500 (Thu, 30 Oct 2008) $
  25. * @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
  26. */
  27. /**
  28. * Short description for class.
  29. *
  30. * @package cake
  31. * @subpackage cake.cake.tests.lib
  32. */
  33. class CakeHtmlReporter extends SimpleReporter {
  34. var $_character_set;
  35. var $_show_passes = false;
  36. /**
  37. * Does nothing yet. The first output will
  38. * be sent on the first test start. For use
  39. * by a web browser.
  40. * @access public
  41. */
  42. function CakeHtmlReporter($character_set = 'ISO-8859-1') {
  43. if (isset($_GET['show_passes']) && $_GET['show_passes']) {
  44. $this->_show_passes = true;
  45. }
  46. $this->SimpleReporter();
  47. $this->_character_set = $character_set;
  48. }
  49. /**
  50. * Paints the top of the web page setting the
  51. * title to the name of the starting test.
  52. * @param string $test_name Name class of test.
  53. * @access public
  54. */
  55. function paintHeader($testName) {
  56. $this->sendNoCacheHeaders();
  57. ob_start();
  58. echo "<h2>$testName</h2>\n";
  59. echo "<ul class='tests'>\n";
  60. }
  61. /**
  62. * Send the headers necessary to ensure the page is
  63. * reloaded on every request. Otherwise you could be
  64. * scratching your head over out of date test data.
  65. * @access public
  66. * @static
  67. */
  68. function sendNoCacheHeaders() {
  69. if (!headers_sent()) {
  70. header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
  71. header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
  72. header("Cache-Control: no-store, no-cache, must-revalidate");
  73. header("Cache-Control: post-check=0, pre-check=0", false);
  74. header("Pragma: no-cache");
  75. }
  76. }
  77. /**
  78. * Paints the end of the test with a summary of
  79. * the passes and failures.
  80. * @param string $test_name Name class of test.
  81. * @access public
  82. */
  83. function paintFooter($test_name) {
  84. $colour = ($this->getFailCount() + $this->getExceptionCount() > 0 ? "red" : "green");
  85. ob_start();
  86. echo "</ul>\n";
  87. echo "<div style=\"";
  88. echo "padding: 8px; margin: 1em 0; background-color: $colour; color: white;";
  89. echo "\">";
  90. echo $this->getTestCaseProgress() . "/" . $this->getTestCaseCount();
  91. echo " test cases complete:\n";
  92. echo "<strong>" . $this->getPassCount() . "</strong> passes, ";
  93. echo "<strong>" . $this->getFailCount() . "</strong> fails and ";
  94. echo "<strong>" . $this->getExceptionCount() . "</strong> exceptions.";
  95. echo "</div>\n";
  96. echo "</body>\n</html>\n";
  97. }
  98. /**
  99. * Paints the test failure with a breadcrumbs
  100. * trail of the nesting test suites below the
  101. * top level test.
  102. * @param string $message Failure message displayed in
  103. * the context of the other tests.
  104. * @access public
  105. */
  106. function paintFail($message) {
  107. ob_start();
  108. parent::paintFail($message);
  109. echo "<li class='fail'>\n";
  110. echo "<span>Failed</span>";
  111. echo "<div class='msg'>" . $this->_htmlEntities($message) . "</div>\n";
  112. $breadcrumb = Set::filter($this->getTestList());
  113. array_shift($breadcrumb);
  114. echo "<div>" . implode(" -&gt; ", $breadcrumb) . "</div>\n";
  115. echo "</li>\n";
  116. }
  117. /**
  118. * Paints the test pass with a breadcrumbs
  119. * trail of the nesting test suites below the
  120. * top level test.
  121. * @param string $message Pass message displayed in
  122. * the context of the other tests.
  123. * @access public
  124. */
  125. function paintPass($message) {
  126. ob_start();
  127. parent::paintPass($message);
  128. if ($this->_show_passes) {
  129. echo "<li class='pass'>\n";
  130. echo "<span>Passed</span> ";
  131. $breadcrumb = Set::filter($this->getTestList());
  132. array_shift($breadcrumb);
  133. echo implode(" -&gt; ", $breadcrumb);
  134. echo "<br />" . $this->_htmlEntities($message) . "\n";
  135. echo "</li>\n";
  136. }
  137. }
  138. /**
  139. * Paints a PHP error.
  140. * @param string $message Message is ignored.
  141. * @access public
  142. */
  143. function paintError($message) {
  144. ob_start();
  145. parent::paintError($message);
  146. echo "<li class='fail'>\n";
  147. echo "<span>Error</span>";
  148. echo "<div class='msg'>" . $this->_htmlEntities($message) . "</div>\n";
  149. $breadcrumb = Set::filter($this->getTestList());
  150. array_shift($breadcrumb);
  151. echo "<div>" . implode(" -&gt; ", $breadcrumb) . "</div>\n";
  152. echo "</li>\n";
  153. }
  154. /**
  155. * Paints a PHP exception.
  156. * @param Exception $exception Exception to display.
  157. * @access public
  158. */
  159. function paintException($exception) {
  160. ob_start();
  161. parent::paintException($exception);
  162. echo "<li class='fail'>\n";
  163. echo "<span>Exception</span>";
  164. $message = 'Unexpected exception of type [' . get_class($exception) .
  165. '] with message ['. $exception->getMessage() .
  166. '] in ['. $exception->getFile() .
  167. ' line ' . $exception->getLine() . ']';
  168. echo "<div class='msg'>" . $this->_htmlEntities($message) . "</div>\n";
  169. $breadcrumb = Set::filter($this->getTestList());
  170. array_shift($breadcrumb);
  171. echo "<div>" . implode(" -&gt; ", $breadcrumb) . "</div>\n";
  172. echo "</li>\n";
  173. }
  174. /**
  175. * Prints the message for skipping tests.
  176. * @param string $message Text of skip condition.
  177. * @access public
  178. */
  179. function paintSkip($message) {
  180. ob_start();
  181. parent::paintSkip($message);
  182. echo "<li class='skipped'>\n";
  183. echo "<span>Skipped</span> ";
  184. echo $this->_htmlEntities($message);
  185. echo "</li>\n";
  186. }
  187. /**
  188. * Paints formatted text such as dumped variables.
  189. * @param string $message Text to show.
  190. * @access public
  191. */
  192. function paintFormattedMessage($message) {
  193. ob_start();
  194. echo '<pre>' . $this->_htmlEntities($message) . '</pre>';
  195. }
  196. /**
  197. * Character set adjusted entity conversion.
  198. * @param string $message Plain text or Unicode message.
  199. * @return string Browser readable message.
  200. * @access protected
  201. */
  202. function _htmlEntities($message) {
  203. return htmlentities($message, ENT_COMPAT, $this->_character_set);
  204. }
  205. }
  206. ?>