Subversion-Projekte lars-tiefland.cakephp

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
/* SVN FILE: $Id: cake_reporter.php 8004 2009-01-16 20:15:21Z 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. (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: 8004 $
23
 * @modifiedby    $LastChangedBy: gwoo $
24
 * @lastmodified  $Date: 2009-01-16 12:15:21 -0800 (Fri, 16 Jan 2009) $
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
 
125
		if ($this->_show_passes) {
126
			echo "<li class='pass'>\n";
127
			echo "<span>Passed</span> ";
128
			$breadcrumb = Set::filter($this->getTestList());
129
			array_shift($breadcrumb);
130
			echo implode(" -&gt; ", $breadcrumb);
131
			echo "<br />" . $this->_htmlEntities($message) . "\n";
132
			echo "</li>\n";
133
		}
134
	}
135
/**
136
 * Paints a PHP error.
137
 * @param string $message Message is ignored.
138
 * @access public
139
 */
140
	function paintError($message) {
141
		parent::paintError($message);
142
		echo "<li class='error'>\n";
143
		echo "<span>Error</span>";
144
		echo "<div class='msg'>" . $this->_htmlEntities($message) . "</div>\n";
145
		$breadcrumb = Set::filter($this->getTestList());
146
		array_shift($breadcrumb);
147
		echo "<div>" . implode(" -&gt; ", $breadcrumb) . "</div>\n";
148
		echo "</li>\n";
149
	}
150
/**
151
 * Paints a PHP exception.
152
 * @param Exception $exception Exception to display.
153
 * @access public
154
 */
155
	function paintException($exception) {
156
		parent::paintException($exception);
157
		echo "<li class='fail'>\n";
158
		echo "<span>Exception</span>";
159
		$message = 'Unexpected exception of type [' . get_class($exception) .
160
			'] with message ['. $exception->getMessage() .
161
			'] in ['. $exception->getFile() .
162
			' line ' . $exception->getLine() . ']';
163
		echo "<div class='msg'>" . $this->_htmlEntities($message) . "</div>\n";
164
		$breadcrumb = Set::filter($this->getTestList());
165
		array_shift($breadcrumb);
166
		echo "<div>" . implode(" -&gt; ", $breadcrumb) . "</div>\n";
167
		echo "</li>\n";
168
	}
169
/**
170
 * Prints the message for skipping tests.
171
 * @param string $message    Text of skip condition.
172
 * @access public
173
 */
174
	function paintSkip($message) {
175
		parent::paintSkip($message);
176
		echo "<li class='skipped'>\n";
177
		echo "<span>Skipped</span> ";
178
		echo $this->_htmlEntities($message);
179
		echo "</li>\n";
180
	}
181
/**
182
 * Paints formatted text such as dumped variables.
183
 * @param string $message Text to show.
184
 * @access public
185
 */
186
	function paintFormattedMessage($message) {
187
		echo '<pre>' . $this->_htmlEntities($message) . '</pre>';
188
	}
189
/**
190
 * Character set adjusted entity conversion.
191
 * @param string $message Plain text or Unicode message.
192
 * @return string Browser readable message.
193
 * @access protected
194
 */
195
	function _htmlEntities($message) {
196
		return htmlentities($message, ENT_COMPAT, $this->_character_set);
197
	}
198
}
199
?>