Automatic installer.php lang files by installer_builder (20070726)
[moodle-linuxchix.git] / admin / report / simpletest / ex_reporter.php
blobeb23fc902f67f8fdb3331c09f79f4cc18fec678f
1 <?php
2 /**
3 * A SimpleTest report format for Moodle.
5 * @copyright &copy; 2006 The Open University
6 * @author N.D.Freear@open.ac.uk, T.J.Hunt@open.ac.uk
7 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
8 * @version $Id$
9 * @package SimpleTestEx
12 if (!defined('MOODLE_INTERNAL')) {
13 die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
16 require_once($CFG->libdir . '/simpletestlib/reporter.php');
18 /**
19 * Extended in-browser test displayer. HtmlReporter generates
20 * only failure messages and a pass count. ExHtmlReporter also
21 * generates pass messages and a time-stamp.
23 * @package SimpleTestEx
25 class ExHtmlReporter extends HtmlReporter {
27 // Options set when the class is created.
28 var $showpasses;
30 // Lang strings. Set in the constructor.
31 var $strrunonlyfolder;
32 var $strrunonlyfile;
34 var $strseparator;
36 /**
37 * Constructor.
39 * @param bool $showpasses Whether this reporter should output anything for passes.
41 function ExHtmlReporter($showpasses) {
42 global $CFG, $THEME;
44 $this->HtmlReporter();
45 $this->showpasses = $showpasses;
47 $this->strrunonlyfolder = $this->get_string('runonlyfolder');
48 $this->strrunonlyfile = $this->get_string('runonlyfile');
49 $this->strseparator = get_separator();
52 /**
53 * Called when a pass needs to be output.
55 function paintPass($message) {
56 //(Implicitly call grandparent, as parent not implemented.)
57 parent::paintPass($message);
58 if ($this->showpasses) {
59 $this->_paintPassFail('pass', $message);
63 /**
64 * Called when a fail needs to be output.
66 function paintFail($message) {
67 // Explicitly call grandparent, not parent::paintFail.
68 SimpleScorer::paintFail($message);
69 $this->_paintPassFail('fail', $message);
72 /**
73 * Called when an error (uncaught exception or PHP error) needs to be output.
75 function paintError($message) {
76 // Explicitly call grandparent, not parent::paintFail.
77 SimpleScorer::paintError($message);
78 $this->_paintPassFail('exception', $message);
81 /**
82 * Private method. Used by printPass/Fail/Error.
84 function _paintPassFail($passorfail, $message) {
85 global $FULLME, $CFG;
87 print_simple_box_start('', '100%', '', 5, $passorfail . ' generalbox');
88 $url = $this->_htmlEntities($this->_stripParameterFromUrl($FULLME, 'path'));
89 echo '<b class="', $passorfail, '">', $this->get_string($passorfail), '</b>: ';
90 $breadcrumb = $this->getTestList();
91 array_shift($breadcrumb);
92 $file = array_shift($breadcrumb);
93 $pathbits = preg_split('/\/|\\\\/', substr($file, strlen($CFG->dirroot) + 1));
94 $file = array_pop($pathbits);
95 $folder = '';
96 foreach ($pathbits as $pathbit) {
97 $folder .= $pathbit . '/';
98 echo "<a href=\"{$url}path=$folder\" title=\"$this->strrunonlyfolder\">$pathbit</a>/";
100 echo "<a href=\"{$url}path=$folder$file\" title=\"$this->strrunonlyfile\">$file</a>";
101 echo $this->strseparator, implode($this->strseparator, $breadcrumb);
102 echo $this->strseparator, '<br />', $this->_htmlEntities($message), "\n\n";
103 print_simple_box_end();
104 flush();
108 * Called when a notice needs to be output.
110 function paintNotice($message) {
111 $this->paintMessage($this->_htmlEntities($message));
115 * Paints a simple supplementary message.
116 * @param string $message Text to display.
118 function paintMessage($message) {
119 if ($this->showpasses) {
120 print_simple_box_start('', '100%');
121 echo '<span class="notice">', $this->get_string('notice'), '</span>: ';
122 $breadcrumb = $this->getTestList();
123 array_shift($breadcrumb);
124 echo implode($this->strseparator, $breadcrumb);
125 echo $this->strseparator, '<br />', $message, "\n";
126 print_simple_box_end();
127 flush();
132 * Output anything that should appear above all the test output.
134 function paintHeader($test_name) {
135 // We do this the moodle way instead.
139 * Output anything that should appear below all the test output, e.g. summary information.
141 function paintFooter($test_name) {
142 $summarydata = new stdClass;
143 $summarydata->run = $this->getTestCaseProgress();
144 $summarydata->total = $this->getTestCaseCount();
145 $summarydata->passes = $this->getPassCount();
146 $summarydata->fails = $this->getFailCount();
147 $summarydata->exceptions = $this->getExceptionCount();
149 if ($summarydata->fails == 0 && $summarydata->exceptions == 0) {
150 $status = "pass";
151 } else {
152 $status = "fail";
154 echo '<div class="unittestsummary ', $status, '">';
155 echo $this->get_string('summary', $summarydata);
156 echo '</div>';
158 echo '<div class="performanceinfo">',
159 $this->get_string('runat', date('<b>d-m-Y H:i T</b>')),
160 $this->get_string('version', SimpleTestOptions::getVersion()),
161 '</div>';
165 * Strip a specified parameter from the query string of a URL, if present.
166 * Adds a separator to the end of the URL, so that a new parameter
167 * can easily be appended. For example (assuming $param = 'frog'):
169 * http://example.com/index.php -> http://example.com/index.php?
170 * http://example.com/index.php?frog=1 -> http://example.com/index.php?
171 * http://example.com/index.php?toad=1 -> http://example.com/index.php?toad=1&
172 * http://example.com/index.php?frog=1&toad=1 -> http://example.com/index.php?toad=1&
174 * @param string $url the URL to modify.
175 * @param string $param the parameter to strip from the URL, if present.
177 * @return string The modified URL.
179 function _stripParameterFromUrl($url, $param) {
180 $url = preg_replace('/(\?|&)' . $param . '=[^&]*&?/', '$1', $url);
181 if (strpos($url, '?') === false) {
182 $url = $url . '?';
183 } else {
184 $url = $url . '&';
186 return $url;
190 * Look up a lang string in the appropriate file.
192 function get_string($identifier, $a = NULL) {
193 return get_string($identifier, 'simpletest', $a);