PageRenderTime 55ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 0ms

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

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