ISSO is no longer a product regularly released so we'll remove the issoversion tag...
[isso.git] / UnitTestReport.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Blue Static Unit Test Result Printer for SimpleTest
5 || # Copyright ©2002-[#]year[#] Iris Studios, Inc.
6 || #
7 || # This program is free software; you can redistribute it and/or modify
8 || # it under the terms of the GNU General Public License as published by
9 || # the Free Software Foundation; version [#]gpl[#] of the License.
10 || #
11 || # This program is distributed in the hope that it will be useful, but
12 || # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 || # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 || # more details.
15 || #
16 || # You should have received a copy of the GNU General Public License along
17 || # with this program; if not, write to the Free Software Foundation, Inc.,
18 || # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 || ###################################################################
20 \*=====================================================================*/
21
22 /**
23 * Unit Test Result HTML Printer
24 *
25 * @package SimpleTest
26 */
27
28 require_once('simpletest/reporter.php');
29
30 /**
31 * Unit Test Result Printer
32 *
33 * This is a SimpleTest result printer module that is used for all Blue Static
34 * unit testing output.
35 *
36 * @author Blue Static
37 * @copyright Copyright ©2002 - [#]year[#], Blue Static
38 * @version $Revision$
39 * @package SimpleTest
40 *
41 */
42 class CustomHtmlReporter extends HtmlReporter
43 {
44 private $html;
45
46 private $block;
47
48 private $suite;
49
50 private $method;
51
52 private $pass = 0;
53
54 private $fail = 0;
55
56 private $errors = array();
57
58 private $status = true;
59
60 public function paintHeader($test)
61 {
62 echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
63 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
64 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
65 <head>
66 <meta http-equiv="content-type" content="text/html; charset=utf-8" />
67 <title>Unit Test Results</title>
68
69 <style type="text/css">
70 <!--
71
72 body
73 {
74 font-size: 12px;
75 font-family: "Trebuchet MS", Verdana, Helvetica, sans-serif;
76 }
77
78 .suite
79 {
80 background-color: rgb(255, 255, 255);
81
82 border-color: rgb(222, 222, 222);
83 border-style: solid;
84 border-width: 1px;
85 }
86
87 .suiteHead
88 {
89 background-color: rgb(222, 222, 222);
90
91 font-weight: bold;
92
93 margin: 2px;
94 padding: 3px;
95 }
96
97 .testGroup
98 {
99 padding: 4px;
100 }
101
102 .testIncomplete
103 {
104 border-color: rgb(222, 230, 255);
105 border-style: dashed;
106 border-width: 1px;
107
108 margin-bottom: 5px;
109 }
110
111 .testIncompleteHead
112 {
113 background-color: rgb(222, 230, 255);
114
115 margin: 1px;
116 padding: 2px;
117 }
118
119 .blueText
120 {
121 color: rgb(111, 133, 255);
122 }
123
124 .testSuccess
125 {
126 border-color: rgb(216, 255, 216);
127 border-style: dashed;
128 border-width: 1px;
129
130 margin-bottom: 5px;
131 }
132
133 .testSuccessHead
134 {
135 background-color: rgb(216, 255, 216);
136
137 margin: 1px;
138 padding: 2px;
139 }
140
141 .greenText
142 {
143 color: rgb(76, 168, 78);
144 }
145
146 .testFail
147 {
148 border-color: rgb(255, 226, 229);
149 border-style: dashed;
150 border-width: 1px;
151
152 margin-bottom: 5px;
153 }
154
155 .testFailHead
156 {
157 background-color: rgb(255, 226, 229);
158
159 margin: 1px;
160 padding: 2px;
161 }
162
163 .redText
164 {
165 color: rgb(168, 65, 63);
166 }
167
168 .textPadding
169 {
170 padding: 3px;
171 }
172
173 .message
174 {
175 margin-bottom: 4px;
176 }
177
178 .messageLast
179 {
180 margin-bottom: 0px;
181 }
182
183 .location
184 {
185 margin-left: 20px;
186
187 font-style: italic;
188 }
189
190 //-->
191 </style>
192 </head>
193 <body>
194
195 <h1>Unit Test Results: ' . $test . '</h1>';
196 }
197
198 public function paintCaseStart($suite)
199 {
200 $this->suite = $case;
201 $this->block = '';
202 $this->pass = 0;
203 $this->fail = 0;
204 $this->total = 0;
205 }
206
207 public function paintMethodStart($method)
208 {
209 $this->method = $method;
210 $this->errors = array();
211 $this->status = true;
212 }
213
214 public function paintError($error)
215 {
216 $this->errors[] = $error;
217 }
218
219 public function paintFail($message)
220 {
221 $this->status = false;
222 $this->errors[] = $message;
223 }
224
225 public function paintPass($message)
226 {
227 }
228
229 public function paintMethodEnd($method)
230 {
231 if ($this->status)
232 {
233 $this->pass++;
234 $this->_passes++;
235 }
236 else
237 {
238 $this->fail++;
239 $this->_fails++;
240 }
241
242 $this->block .= "\n\t\t" . '<div class="test' . ($this->status ? 'Success' : 'Fail') . ' ' . ($this->status ? 'green' : 'red') . 'Text' . (sizeof($this->errors) > 0 ? ' negateMargin' : '') . '">';
243 $this->block .= "\n\t\t\t" . '<div class="test' . ($this->status ? 'Success' : 'Fail') . 'Head">' . $method . '</div>';
244
245 if (sizeof($this->errors) > 0)
246 {
247 $this->block .= "\n\t\t\t" . '<div class="textPadding">';
248 $this->block .= $this->formatInfo($this->errors);
249 $this->block .= "\n\t\t\t" . '</div class="textPadding">';
250 }
251
252 $this->block .= "\n\t\t" . '</div>';
253 }
254
255 private function formatInfo($list)
256 {
257 $output = '';
258 $count = sizeof($list);
259 foreach ($list AS $err)
260 {
261 $i++;
262 $output .= "\n\t\t\t\t" . '<div class="message' . ($count == $i ? ' messageLast' : '') . '">';
263 $output .= "\n\t\t\t\t\t" . '<div>&bull; ' . htmlspecialchars($err) . '</div>';
264 $output .= "\n\t\t\t\t" . '</div>';
265 }
266
267 return $output;
268 }
269
270 public function paintCaseEnd($case)
271 {
272 $total = $this->pass + $this->fail;
273 $successPercent = round(100 * (($total - $this->fail) / $total), 1);
274
275 $this->html .= '<div class="suite">';
276 $this->html .= "\n\t" . '<div class="suiteHead">';
277 $this->html .= "\n\t\t" . '<span style="float: right">' . $total . ' Tests, ' . $successPercent . '% Success' . '</span>';
278 $this->html .= "\n\t\t" . $case;
279 $this->html .= "\n\t" . '</div>';
280 $this->html .= "\n\t" . '<div class="testGroup">';
281 $this->html .= $this->block;
282 $this->html .= "\n\t" . '</div>';
283 $this->html .= "\n" . '</div>';
284 $this->html .= "\n\n" . '<br />' . "\n\n";
285 }
286
287 public function paintFooter($test)
288 {
289 $total = $this->getPassCount() + $this->getFailCount();
290 echo '
291 <div>
292 <div>The following is a report of how each unit test performed. If any errors or exceptions were thrown, they have been recorded below. Tests have been broken down into their test suite groups. Your overall statistics are here:</div>
293
294 <br />
295
296 <div>Total Tests: <strong>' . $total . '</strong></div>
297 <div>Number Success: <strong class="greenText">' . $this->getPassCount() . '</strong></div>
298 <div>Number Fail: <strong class="redText">' . $this->getFailCount() . '</strong></div>
299
300 <br />
301
302 <div><em>Total Success Rate: <strong class="' . ($this->getPassCount() == $total ? 'green' : 'red') . 'Text">' . round(100 * ($this->getPassCount() / $total), 1) . '%</strong></em></div>
303 </div>
304
305 <br />';
306
307 echo $this->html;
308
309 echo '
310 </body>
311 </html>';
312 }
313 }
314
315 /*=====================================================================*\
316 || ###################################################################
317 || # $HeadURL$
318 || # $Id$
319 || ###################################################################
320 \*=====================================================================*/
321 ?>