Don't look for pipes in the root node.
[lhc/web/wiklou.git] / tests / phpunit / includes / parser / ParserHelpers.php
1 <?php
2
3 class PHPUnitParserTest extends ParserTest {
4 function showTesting( $desc ) {
5 /* Do nothing since we don't want to show info during PHPUnit testing. */
6 }
7
8 public function showSuccess( $desc ) {
9 PHPUnit_Framework_Assert::assertTrue( true, $desc );
10 return true;
11 }
12
13 public function showFailure( $desc, $expected, $got ) {
14 PHPUnit_Framework_Assert::assertEquals( $expected, $got, $desc );
15 return false;
16 }
17
18 public function setupRecorder( $options ) {
19 $this->recorder = new PHPUnitTestRecorder( $this );
20 }
21 }
22
23 class ParserUnitTest extends MediaWikiTestCase {
24 private $test = "";
25
26 public function __construct( $suite, $test = null ) {
27 parent::__construct();
28 $this->test = $test;
29 $this->suite = $suite;
30 }
31
32 function count() { return 1; }
33
34 public function run( PHPUnit_Framework_TestResult $result = null ) {
35 PHPUnit_Framework_Assert::resetCount();
36 if ( $result === NULL ) {
37 $result = new PHPUnit_Framework_TestResult;
38 }
39
40 $this->suite->publishTestArticles(); // Add articles needed by the tests.
41 $backend = new ParserTestSuiteBackend;
42 $result->startTest( $this );
43
44 // Support the transition to PHPUnit 3.5 where PHPUnit_Util_Timer is replaced with PHP_Timer
45 if ( class_exists( 'PHP_Timer' ) ) {
46 PHP_Timer::start();
47 } else {
48 PHPUnit_Util_Timer::start();
49 }
50
51 $r = false;
52 try {
53 # Run the test.
54 # On failure, the subclassed backend will throw an exception with
55 # the details.
56 $pt = new PHPUnitParserTest;
57 $r = $pt->runTest( $this->test['test'], $this->test['input'],
58 $this->test['result'], $this->test['options'], $this->test['config']
59 );
60 }
61 catch ( PHPUnit_Framework_AssertionFailedError $e ) {
62
63 // PHPUnit_Util_Timer -> PHP_Timer support (see above)
64 if ( class_exists( 'PHP_Timer' ) ) {
65 $result->addFailure( $this, $e, PHP_Timer::stop() );
66 } else {
67 $result->addFailure( $this, $e, PHPUnit_Util_Timer::stop() );
68 }
69 }
70 catch ( Exception $e ) {
71 // PHPUnit_Util_Timer -> PHP_Timer support (see above)
72 if ( class_exists( 'PHP_Timer' ) ) {
73 $result->addFailure( $this, $e, PHP_Timer::stop() );
74 } else {
75 $result->addFailure( $this, $e, PHPUnit_Util_Timer::stop() );
76 }
77 }
78
79 // PHPUnit_Util_Timer -> PHP_Timer support (see above)
80 if ( class_exists( 'PHP_Timer' ) ) {
81 $result->endTest( $this, PHP_Timer::stop() );
82 } else {
83 $result->endTest( $this, PHPUnit_Util_Timer::stop() );
84 }
85
86 $backend->recorder->record( $this->test['test'], $r );
87 $this->addToAssertionCount( PHPUnit_Framework_Assert::getCount() );
88
89 return $result;
90 }
91
92 public function toString() {
93 return $this->test['test'];
94 }
95
96 }
97
98 class ParserTestSuiteBackend extends PHPUnit_FrameWork_TestSuite {
99 public $recorder;
100 public $term;
101 static $usePHPUnit = false;
102
103 function __construct() {
104 parent::__construct();
105 $this->setupRecorder(null);
106 self::$usePHPUnit = method_exists('PHPUnit_Framework_Assert', 'assertEquals');
107 }
108
109 function showTesting( $desc ) {
110 }
111
112 function showRunFile( $path ) {
113 }
114
115 function showTestResult( $desc, $result, $out ) {
116 if ( $result === $out ) {
117 return self::showSuccess( $desc, $result, $out );
118 } else {
119 return self::showFailure( $desc, $result, $out );
120 }
121 }
122
123 public function setupRecorder( $options ) {
124 $this->recorder = new PHPUnitTestRecorder( $this );
125 }
126 }
127
128 class PHPUnitTestRecorder extends TestRecorder {
129 function record( $test, $result ) {
130 $this->total++;
131 $this->success += $result;
132
133 }
134
135 function reportPercentage( $success, $total ) { }
136 }