2 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
3 xmlns:exsl="http://exslt.org/common"
4 xmlns:str="http://exslt.org/strings"
5 xmlns:date="http://exslt.org/dates-and-times"
6 extension-element-prefixes="exsl str date">
7 <xsl:include href="str.replace.function.xsl"/>
8 <xsl:output method="html" indent="yes" encoding="US-ASCII"
9 doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN" />
10 <xsl:decimal-format decimal-separator="." grouping-separator="," />
12 Copyright 2001-2004 The Apache Software Foundation
14 Licensed under the Apache License, Version 2.0 (the "License");
15 you may not use this file except in compliance with the License.
16 You may obtain a copy of the License at
18 http://www.apache.org/licenses/LICENSE-2.0
20 Unless required by applicable law or agreed to in writing, software
21 distributed under the License is distributed on an "AS IS" BASIS,
22 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23 See the License for the specific language governing permissions and
24 limitations under the License.
29 Sample stylesheet to be used with Phing/PHPUnit output.
30 Based on JUnit stylesheets from Apache Ant.
32 It creates a non-framed report that can be useful to send via
35 @author Michiel Rook <a href="mailto:michiel.rook@gmail.com"/>
36 @author Stephane Bailliez <a href="mailto:sbailliez@apache.org"/>
37 @author Erik Hatcher <a href="mailto:ehatcher@apache.org"/>
40 <xsl:param name="output.sorttable" select="'.'"/>
42 <xsl:template match="testsuites">
45 <title>Unit Test Results</title>
46 <xsl:if test="$output.sorttable = 1">
47 <script language="JavaScript" src="http://www.phing.info/support/sorttable.js"/>
49 <style type="text/css">
51 font-family: verdana,arial,helvetica;
55 table tr td, table tr th {
56 font-family: verdana,arial,helvetica;
60 font-family: verdana,arial,helvetica;
71 margin-top:0.5em; margin-bottom:1.0em;
76 font-family: verdana,arial,helvetica;
79 margin-top: 1em; margin-bottom: 0.5em;
80 font-family: verdana,arial,helvetica;
84 font-family: verdana,arial,helvetica;
88 font-family: verdana,arial,helvetica;
92 font-family: verdana,arial,helvetica;
96 font-family: verdana,arial,helvetica;
99 font-weight:bold; color:red;
102 font-weight:bold; color:purple;
113 <xsl:if test="$output.sorttable = 1">
122 <xsl:call-template name="pageHeader"/>
124 <!-- Summary part -->
125 <xsl:call-template name="summary"/>
126 <hr size="1" width="95%" align="left"/>
128 <!-- Package List part -->
129 <xsl:call-template name="packagelist"/>
130 <hr size="1" width="95%" align="left"/>
132 <!-- For each package create its part -->
133 <xsl:call-template name="packages"/>
134 <hr size="1" width="95%" align="left"/>
136 <!-- For each class create the part -->
137 <xsl:call-template name="classes"/>
139 <xsl:call-template name="pageFooter"/>
146 <!-- ================================================================== -->
147 <!-- Write a list of all packages with an hyperlink to the anchor of -->
148 <!-- of the package name. -->
149 <!-- ================================================================== -->
150 <xsl:template name="packagelist">
152 Note: package statistics are not computed recursively, they only sum up all of its testsuites numbers.
153 <table class="details sortable" border="0" cellpadding="5" cellspacing="2" width="95%">
154 <xsl:call-template name="testsuite.test.header"/>
155 <!-- list all packages recursively -->
156 <xsl:for-each select="./testsuite[not(./@package = preceding-sibling::testsuite/@package)]">
157 <xsl:sort select="@package"/>
158 <xsl:variable name="testsuites-in-package" select="/testsuites/testsuite[./@package = current()/@package]"/>
159 <xsl:variable name="testCount" select="sum($testsuites-in-package/@tests)"/>
160 <xsl:variable name="errorCount" select="sum($testsuites-in-package/@errors)"/>
161 <xsl:variable name="failureCount" select="sum($testsuites-in-package/@failures)"/>
162 <xsl:variable name="timeCount" select="sum($testsuites-in-package/@time)"/>
164 <!-- write a summary for the package -->
166 <!-- set a nice color depending if there is an error/failure -->
167 <xsl:attribute name="class">
169 <xsl:when test="$failureCount > 0">Failure</xsl:when>
170 <xsl:when test="$errorCount > 0">Error</xsl:when>
173 <td><a href="#{@package}"><xsl:value-of select="@package"/></a></td>
174 <td><xsl:value-of select="$testCount"/></td>
175 <td><xsl:value-of select="$errorCount"/></td>
176 <td><xsl:value-of select="$failureCount"/></td>
178 <xsl:call-template name="display-time">
179 <xsl:with-param name="value" select="$timeCount"/>
188 <!-- ================================================================== -->
189 <!-- Write a package level report -->
190 <!-- It creates a table with values from the document: -->
191 <!-- Name | Tests | Errors | Failures | Time -->
192 <!-- ================================================================== -->
193 <xsl:template name="packages">
194 <!-- create an anchor to this package name -->
195 <xsl:for-each select="/testsuites/testsuite[not(./@package = preceding-sibling::testsuite/@package)]">
196 <xsl:sort select="@package"/>
197 <a name="{@package}"></a>
198 <h3>Package <xsl:value-of select="@package"/></h3>
200 <table class="details sortable" border="0" cellpadding="5" cellspacing="2" width="95%">
201 <xsl:call-template name="testsuite.test.header"/>
203 <!-- match the testsuites of this package -->
204 <xsl:apply-templates select="/testsuites/testsuite[./@package = current()/@package]" mode="print.test"/>
206 <a href="#top">Back to top</a>
212 <xsl:template name="classes">
213 <xsl:for-each select="testsuite">
214 <xsl:sort select="@name"/>
215 <!-- create an anchor to this class name -->
216 <a name="{@name}"></a>
217 <h3>TestCase <xsl:value-of select="@name"/></h3>
219 <table class="details sortable" border="0" cellpadding="5" cellspacing="2" width="95%">
220 <xsl:call-template name="testcase.test.header"/>
222 test can even not be started at all (failure to load the class)
223 so report the error directly
225 <xsl:if test="./error">
227 <td colspan="4"><xsl:apply-templates select="./error"/></td>
230 <xsl:apply-templates select="./testcase | ./testsuite/testcase" mode="print.test"/>
234 <a href="#top">Back to top</a>
238 <xsl:template name="summary">
240 <xsl:variable name="testCount" select="sum(testsuite/@tests)"/>
241 <xsl:variable name="errorCount" select="sum(testsuite/@errors)"/>
242 <xsl:variable name="failureCount" select="sum(testsuite/@failures)"/>
243 <xsl:variable name="timeCount" select="sum(testsuite/@time)"/>
244 <xsl:variable name="successRate" select="($testCount - $failureCount - $errorCount) div $testCount"/>
245 <table class="details" border="0" cellpadding="5" cellspacing="2" width="95%">
250 <th>Success rate</th>
254 <xsl:attribute name="class">
256 <xsl:when test="$failureCount > 0">Failure</xsl:when>
257 <xsl:when test="$errorCount > 0">Error</xsl:when>
260 <td><xsl:value-of select="$testCount"/></td>
261 <td><xsl:value-of select="$failureCount"/></td>
262 <td><xsl:value-of select="$errorCount"/></td>
264 <xsl:call-template name="display-percent">
265 <xsl:with-param name="value" select="$successRate"/>
269 <xsl:call-template name="display-time">
270 <xsl:with-param name="value" select="$timeCount"/>
276 <table border="0" width="95%">
278 <td style="text-align: justify;">
279 Note: <i>failures</i> are anticipated and checked for with assertions while <i>errors</i> are unanticipated.
286 <xsl:template name="pageHeader">
287 <h1>Unit Test Results</h1>
290 <td align="left"></td>
291 <td align="right">Designed for use with <a href='http://www.phpunit.de'>PHPUnit</a> and <a href='http://www.phing.info/'>Phing</a>.</td>
298 <xsl:template name="pageFooter">
300 <tr><td><hr noshade="yes" size="1"/></td></tr>
301 <tr><td class="small">Report generated at <xsl:value-of select="date:date-time()"/></td></tr>
305 <xsl:template match="testsuite" mode="header">
307 <th width="80%">Name</th>
311 <th nowrap="nowrap">Time(s)</th>
315 <!-- class header -->
316 <xsl:template name="testsuite.test.header">
318 <th width="80%">Name</th>
322 <th nowrap="nowrap">Time(s)</th>
326 <!-- method header -->
327 <xsl:template name="testcase.test.header">
331 <th width="80%">Type</th>
332 <th nowrap="nowrap">Time(s)</th>
337 <!-- class information -->
338 <xsl:template match="testsuite" mode="print.test">
340 <!-- set a nice color depending if there is an error/failure -->
341 <xsl:attribute name="class">
343 <xsl:when test="@failures[.> 0]">Failure</xsl:when>
344 <xsl:when test="@errors[.> 0]">Error</xsl:when>
348 <!-- print testsuite information -->
349 <td><a href="#{@name}"><xsl:value-of select="@name"/></a></td>
350 <td><xsl:value-of select="@tests"/></td>
351 <td><xsl:value-of select="@errors"/></td>
352 <td><xsl:value-of select="@failures"/></td>
354 <xsl:call-template name="display-time">
355 <xsl:with-param name="value" select="@time"/>
361 <xsl:template match="testcase" mode="print.test">
363 <xsl:attribute name="class">
365 <xsl:when test="failure | error">Error</xsl:when>
368 <td><xsl:value-of select="@name"/></td>
370 <xsl:when test="failure">
372 <td><xsl:apply-templates select="failure"/></td>
374 <xsl:when test="error">
376 <td><xsl:apply-templates select="error"/></td>
384 <xsl:call-template name="display-time">
385 <xsl:with-param name="value" select="@time"/>
392 <xsl:template match="failure">
393 <xsl:call-template name="display-failures"/>
396 <xsl:template match="error">
397 <xsl:call-template name="display-failures"/>
400 <!-- Style for the error and failure in the tescase template -->
401 <xsl:template name="display-failures">
403 <xsl:when test="not(@message)">N/A</xsl:when>
405 <xsl:value-of select="@message"/>
408 <!-- display the stacktrace -->
411 <xsl:call-template name="br-replace">
412 <xsl:with-param name="word" select="."/>
418 template that will convert a carriage return into a br tag
419 @param word the text from which to convert CR to BR tag
421 <xsl:template name="br-replace">
422 <xsl:param name="word"/>
424 <xsl:when test="contains($word,'
')">
425 <xsl:value-of select="substring-before($word,'
')"/>
427 <xsl:call-template name="br-replace">
428 <xsl:with-param name="word" select="substring-after($word,'
')"/>
432 <xsl:value-of select="$word"/>
437 <xsl:template name="display-time">
438 <xsl:param name="value"/>
439 <xsl:value-of select="format-number($value,'0.000')"/>
442 <xsl:template name="display-percent">
443 <xsl:param name="value"/>
444 <xsl:value-of select="format-number($value,'0.00%')"/>