PageRenderTime 43ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/cake/tests/lib/cake_reporter.php

https://github.com/hardsshah/bookmarks
PHP | 199 lines | 100 code | 1 blank | 98 comment | 4 complexity | c6d248ecd6b3393b0f3fb311ddc328da MD5 | raw file
  1. <?php
  2. /* SVN FILE: $Id$ */
  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$
  23. * @modifiedby $LastChangedBy$
  24. * @lastmodified $Date$
  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. echo "<h2>$testName</h2>\n";
  58. echo "<ul class='tests'>\n";
  59. }
  60. /**
  61. * Send the headers necessary to ensure the page is
  62. * reloaded on every request. Otherwise you could be
  63. * scratching your head over out of date test data.
  64. * @access public
  65. * @static
  66. */
  67. function sendNoCacheHeaders() {
  68. if (!headers_sent()) {
  69. header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
  70. header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
  71. header("Cache-Control: no-store, no-cache, must-revalidate");
  72. header("Cache-Control: post-check=0, pre-check=0", false);
  73. header("Pragma: no-cache");
  74. }
  75. }
  76. /**
  77. * Paints the end of the test with a summary of
  78. * the passes and failures.
  79. * @param string $test_name Name class of test.
  80. * @access public
  81. */
  82. function paintFooter($test_name) {
  83. $colour = ($this->getFailCount() + $this->getExceptionCount() > 0 ? "red" : "green");
  84. echo "</ul>\n";
  85. echo "<div style=\"";
  86. echo "padding: 8px; margin: 1em 0; background-color: $colour; color: white;";
  87. echo "\">";
  88. echo $this->getTestCaseProgress() . "/" . $this->getTestCaseCount();
  89. echo " test cases complete:\n";
  90. echo "<strong>" . $this->getPassCount() . "</strong> passes, ";
  91. echo "<strong>" . $this->getFailCount() . "</strong> fails and ";
  92. echo "<strong>" . $this->getExceptionCount() . "</strong> exceptions.";
  93. echo "</div>\n";
  94. echo "</body>\n</html>\n";
  95. }
  96. /**
  97. * Paints the test failure with a breadcrumbs
  98. * trail of the nesting test suites below the
  99. * top level test.
  100. * @param string $message Failure message displayed in
  101. * the context of the other tests.
  102. * @access public
  103. */
  104. function paintFail($message) {
  105. parent::paintFail($message);
  106. echo "<li class='fail'>\n";
  107. echo "<span>Failed</span>";
  108. echo "<div class='msg'>" . $this->_htmlEntities($message) . "</div>\n";
  109. $breadcrumb = Set::filter($this->getTestList());
  110. array_shift($breadcrumb);
  111. echo "<div>" . implode(" -&gt; ", $breadcrumb) . "</div>\n";
  112. echo "</li>\n";
  113. }
  114. /**
  115. * Paints the test pass with a breadcrumbs
  116. * trail of the nesting test suites below the
  117. * top level test.
  118. * @param string $message Pass message displayed in
  119. * the context of the other tests.
  120. * @access public
  121. */
  122. function paintPass($message) {
  123. parent::paintPass($message);
  124. if ($this->_show_passes) {
  125. echo "<li class='pass'>\n";
  126. echo "<span>Passed</span> ";
  127. $breadcrumb = Set::filter($this->getTestList());
  128. array_shift($breadcrumb);
  129. echo implode(" -&gt; ", $breadcrumb);
  130. echo "<br />" . $this->_htmlEntities($message) . "\n";
  131. echo "</li>\n";
  132. }
  133. }
  134. /**
  135. * Paints a PHP error.
  136. * @param string $message Message is ignored.
  137. * @access public
  138. */
  139. function paintError($message) {
  140. parent::paintError($message);
  141. echo "<li class='error'>\n";
  142. echo "<span>Error</span>";
  143. echo "<div class='msg'>" . $this->_htmlEntities($message) . "</div>\n";
  144. $breadcrumb = Set::filter($this->getTestList());
  145. array_shift($breadcrumb);
  146. echo "<div>" . implode(" -&gt; ", $breadcrumb) . "</div>\n";
  147. echo "</li>\n";
  148. }
  149. /**
  150. * Paints a PHP exception.
  151. * @param Exception $exception Exception to display.
  152. * @access public
  153. */
  154. function paintException($exception) {
  155. parent::paintException($exception);
  156. echo "<li class='fail'>\n";
  157. echo "<span>Exception</span>";
  158. $message = 'Unexpected exception of type [' . get_class($exception) .
  159. '] with message ['. $exception->getMessage() .
  160. '] in ['. $exception->getFile() .
  161. ' line ' . $exception->getLine() . ']';
  162. echo "<div class='msg'>" . $this->_htmlEntities($message) . "</div>\n";
  163. $breadcrumb = Set::filter($this->getTestList());
  164. array_shift($breadcrumb);
  165. echo "<div>" . implode(" -&gt; ", $breadcrumb) . "</div>\n";
  166. echo "</li>\n";
  167. }
  168. /**
  169. * Prints the message for skipping tests.
  170. * @param string $message Text of skip condition.
  171. * @access public
  172. */
  173. function paintSkip($message) {
  174. parent::paintSkip($message);
  175. echo "<li class='skipped'>\n";
  176. echo "<span>Skipped</span> ";
  177. echo $this->_htmlEntities($message);
  178. echo "</li>\n";
  179. }
  180. /**
  181. * Paints formatted text such as dumped variables.
  182. * @param string $message Text to show.
  183. * @access public
  184. */
  185. function paintFormattedMessage($message) {
  186. echo '<pre>' . $this->_htmlEntities($message) . '</pre>';
  187. }
  188. /**
  189. * Character set adjusted entity conversion.
  190. * @param string $message Plain text or Unicode message.
  191. * @return string Browser readable message.
  192. * @access protected
  193. */
  194. function _htmlEntities($message) {
  195. return htmlentities($message, ENT_COMPAT, $this->_character_set);
  196. }
  197. }
  198. ?>