Merge commit 'catalyst/MOODLE_19_STABLE' into mdl19-linuxchix
[moodle-linuxchix.git] / lib / simpletestlib / ui / colortext_reporter.php
blob5f0696ab5a64e8eca1a22926c8ea5bcc92618946
1 <?php
2 /**
3 * Base include file for SimpleTest
4 * @package SimpleTest
5 * @subpackage UnitTester
6 * @version $Id$
7 */
9 /**
10 * include base reporter
12 require_once(dirname(__FILE__) . '/../reporter.php');
15 /**
16 * Provides an ANSI-colored {@link TextReporter} for viewing test results.
18 * This code is made available under the same terms as SimpleTest. It is based
19 * off of code that Jason Sweat originally published on the SimpleTest mailing
20 * list.
22 * @author Jason Sweat (original code)
23 * @author Travis Swicegood <development@domain51.com>
24 * @package SimpleTest
25 * @subpackage UnitTester
27 class ColorTextReporter extends TextReporter {
28 var $_failColor = 41;
29 var $_passColor = 42;
31 /**
32 * Handle initialization
34 * @param {@link TextReporter}
36 function ColorTextReporter() {
37 parent::TextReporter();
40 /**
41 * Capture the attempt to display the final test results and insert the
42 * ANSI-color codes in place.
44 * @param string
45 * @see TextReporter
46 * @access public
48 function paintFooter($test_name) {
49 ob_start();
50 parent::paintFooter($test_name);
51 $output = trim(ob_get_clean());
52 if ($output) {
53 if (($this->getFailCount() + $this->getExceptionCount()) == 0) {
54 $color = $this->_passColor;
55 } else {
56 $color = $this->_failColor;
59 $this->_setColor($color);
60 echo $output;
61 $this->_resetColor();
66 /**
67 * Sets the terminal to an ANSI-standard $color
69 * @param int
70 * @access protected
72 function _setColor($color) {
73 printf("%s[%sm\n", chr(27), $color);
77 /**
78 * Resets the color back to normal.
80 * @access protected
82 function _resetColor() {
83 $this->_setColor(0);