Index: trunk/phase3/tests/phpunit/includes/parser/PreprocessorTest.php |
— | — | @@ -105,10 +105,39 @@ |
106 | 106 | } |
107 | 107 | |
108 | 108 | /** |
| 109 | + * Get XML preprocessor tree from the preprocessor (which may not be the |
| 110 | + * native XML-based one). |
| 111 | + * |
| 112 | + * @param string $wikiText |
| 113 | + * @return string |
| 114 | + */ |
| 115 | + function preprocessToXml( $wikiText ) { |
| 116 | + $dom = $this->mPreprocessor->preprocessToObj( $wikiText ); |
| 117 | + if ( is_callable( array( $dom, 'saveXML' ) ) ) { |
| 118 | + return $dom->saveXML(); |
| 119 | + } else { |
| 120 | + return $this->normalizeXml( $dom->__toString() ); |
| 121 | + } |
| 122 | + } |
| 123 | + |
| 124 | + /** |
| 125 | + * Normalize XML string to the form that a DOMDocument saves out. |
| 126 | + * |
| 127 | + * @param string $xml |
| 128 | + * @return string |
| 129 | + */ |
| 130 | + function normalizeXml( $xml ) { |
| 131 | + $dom = new DOMDocument(); |
| 132 | + // 1 << 19 == XML_PARSE_HUGE, needed so newer versions of libxml2 don't barf when the XML is >256 levels deep |
| 133 | + $dom->loadXML( $xml, 1 << 19 ); |
| 134 | + return $dom->saveXML(); |
| 135 | + } |
| 136 | + |
| 137 | + /** |
109 | 138 | * @dataProvider provideCases |
110 | 139 | */ |
111 | 140 | function testPreprocessorOutput( $wikiText, $expectedXml ) { |
112 | | - $this->assertEquals( $expectedXml, $this->mPreprocessor->preprocessToXml( $wikiText ) ); |
| 141 | + $this->assertEquals( $this->normalizeXml( $expectedXml ), $this->preprocessToXml( $wikiText ) ); |
113 | 142 | } |
114 | 143 | |
115 | 144 | /** |
— | — | @@ -129,11 +158,12 @@ |
130 | 159 | function testPreprocessorOutputFiles( $filename ) { |
131 | 160 | $folder = dirname( __FILE__ ) . "/../../../parser/preprocess"; |
132 | 161 | $wikiText = file_get_contents( "$folder/$filename.txt" ); |
133 | | - $output = $this->mPreprocessor->preprocessToXml( $wikiText ); |
| 162 | + $output = $this->preprocessToXml( $wikiText ); |
134 | 163 | |
135 | 164 | $expectedFilename = "$folder/$filename.expected"; |
136 | 165 | if ( file_exists( $expectedFilename ) ) { |
137 | | - $this->assertStringEqualsFile( $expectedFilename, $output ); |
| 166 | + $expectedXml = $this->normalizeXml( file_get_contents( $expectedFilename ) ); |
| 167 | + $this->assertEquals( $expectedXml, $output ); |
138 | 168 | } else { |
139 | 169 | $tempFilename = tempnam( $folder, "$filename." ); |
140 | 170 | file_put_contents( $tempFilename, $output ); |
— | — | @@ -188,7 +218,7 @@ |
189 | 219 | * @dataProvider provideHeadings |
190 | 220 | */ |
191 | 221 | function testHeadings( $wikiText, $expectedXml ) { |
192 | | - $this->assertEquals( $expectedXml, $this->mPreprocessor->preprocessToXml( $wikiText ) ); |
| 222 | + $this->assertEquals( $this->normalizeXml( $expectedXml ), $this->preprocessToXml( $wikiText ) ); |
193 | 223 | } |
194 | 224 | } |
195 | 225 | |