From d9022f63880ce039446fba8364f68e656b7bf4cb Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Thu, 3 May 2012 13:01:35 +0200 Subject: Update to MediaWiki 1.19.0 --- tests/phpunit/includes/parser/PreprocessorTest.php | 102 ++++++++++++++------- 1 file changed, 70 insertions(+), 32 deletions(-) (limited to 'tests/phpunit/includes/parser/PreprocessorTest.php') diff --git a/tests/phpunit/includes/parser/PreprocessorTest.php b/tests/phpunit/includes/parser/PreprocessorTest.php index 7a5948d4..9d3499a0 100644 --- a/tests/phpunit/includes/parser/PreprocessorTest.php +++ b/tests/phpunit/includes/parser/PreprocessorTest.php @@ -49,43 +49,45 @@ class PreprocessorTest extends MediaWikiTestCase { array( "== Foo ==\n== Bar == \n", "== Foo ==\n== Bar == \n" ), array( "===========", "===========" ), array( "Foo\n=\n==\n=\n", "Foo\n=\n==\n=\n" ), - array( "{{Foo}}", "" ), + array( "{{Foo}}", "" ), array( "\n{{Foo}}", "\n" ), - array( "{{Foo|bar}}", "" ), - array( "{{Foo|bar}}a", "a" ), - array( "{{Foo|bar|baz}}", "" ), - array( "{{Foo|1=bar}}", "" ), - array( "{{Foo|=bar}}", "" ), - array( "{{Foo|bar=baz}}", "" ), - array( "{{Foo|1=bar|baz}}", "" ), - array( "{{Foo|1=bar|2=baz}}", "" ), - array( "{{Foo|bar|foo=baz}}", "" ), - array( "{{{1}}}", "1" ), - array( "{{{1|}}}", "1" ), - array( "{{{Foo}}}", "Foo" ), - array( "{{{Foo|}}}", "Foo" ), - array( "{{{Foo|bar|baz}}}", "Foobarbaz" ), + array( "{{Foo|bar}}", "" ), + array( "{{Foo|bar}}a", "a" ), + array( "{{Foo|bar|baz}}", "" ), + array( "{{Foo|1=bar}}", "" ), + array( "{{Foo|=bar}}", "" ), + array( "{{Foo|bar=baz}}", "" ), + array( "{{Foo|{{bar}}=baz}}", "" ), + array( "{{Foo|1=bar|baz}}", "" ), + array( "{{Foo|1=bar|2=baz}}", "" ), + array( "{{Foo|bar|foo=baz}}", "" ), + array( "{{{1}}}", "1" ), + array( "{{{1|}}}", "1" ), + array( "{{{Foo}}}", "Foo" ), + array( "{{{Foo|}}}", "Foo" ), + array( "{{{Foo|bar|baz}}}", "Foobarbaz" ), array( "{{Foo}}", "{<!-- -->{Foo}}" ), array( "{{{{Foobar}}}}", "{Foobar}" ), - array( "{{{ {{Foo}} }}}", " <template><title>Foo " ), - array( "{{ {{{Foo}}} }}", "" ), - array( "{{{{{Foo}}}}}", "" ), - array( "{{{{{Foo}} }}}", "<template><title>Foo " ), - array( "{{{{{{Foo}}}}}}", "<tplarg><title>Foo" ), + array( "{{{ {{Foo}} }}}", " <template><title>Foo " ), + array( "{{ {{{Foo}}} }}", "" ), + array( "{{{{{Foo}}}}}", "" ), + array( "{{{{{Foo}} }}}", "<template><title>Foo " ), + array( "{{{{{{Foo}}}}}}", "<tplarg><title>Foo" ), array( "{{{{{{Foo}}}}}", "{" ), array( "[[[Foo]]", "[[[Foo]]" ), - array( "{{Foo|[[[[bar]]|baz]]}}", "" ), // This test is important, since it means the difference between having the [[ rule stacked or not + array( "{{Foo|[[[[bar]]|baz]]}}", "" ), // This test is important, since it means the difference between having the [[ rule stacked or not array( "{{Foo|[[[[bar]|baz]]}}", "{{Foo|[[[[bar]|baz]]}}" ), array( "{{Foo|Foo [[[[bar]|baz]]}}", "{{Foo|Foo [[[[bar]|baz]]}}" ), array( "Foo BarBaz", "Foo display mapBar</display map >Baz" ), array( "Foo BarBaz", "Foo display map fooBar</display map >Baz" ), array( "Foo ", "Foo gallery bar="baz" " ), + array( "Foo ", "Foo gallery bar="1" baz=2 " ), array( "Foo", "/fooFoo<//foo>" ), # Worth blacklisting IMHO - array( "{{#ifexpr: ({{{1|1}}} = 2) | Foo | Bar }}", ""), - array( "{{#if: {{{1|}}} | Foo | {{Bar}} }}", ""), - array( "{{#if: {{{1|}}} | Foo | [[Bar]] }}", ""), - array( "{{#if: {{{1|}}} | [[Foo]] | Bar }}", ""), - array( "{{#if: {{{1|}}} | 1 | {{#if: {{{1|}}} | 2 | 3 }} }}", ""), + array( "{{#ifexpr: ({{{1|1}}} = 2) | Foo | Bar }}", ""), + array( "{{#if: {{{1|}}} | Foo | {{Bar}} }}", ""), + array( "{{#if: {{{1|}}} | Foo | [[Bar]] }}", ""), + array( "{{#if: {{{1|}}} | [[Foo]] | Bar }}", ""), + array( "{{#if: {{{1|}}} | 1 | {{#if: {{{1|}}} | 2 | 3 }} }}", ""), array( "{{ {{Foo}}", "{{ "), array( "{{Foobar {{Foo}} {{Bar}} {{Baz}} ", "{{Foobar "), array( "[[Foo]] |", "[[Foo]] |"), @@ -97,19 +99,54 @@ class PreprocessorTest extends MediaWikiTestCase { array( "{{Foo|bar=[[baz]}}", "{{Foo|bar=[[baz]}}"), array( "{{foo|", "{{foo|"), array( "{{foo|}", "{{foo|}"), - array( "{{foo|} }}", ""), + array( "{{foo|} }}", ""), array( "{{foo|bar=|}", "{{foo|bar=|}"), array( "{{Foo|} Bar=", "{{Foo|} Bar="), - array( "{{Foo|} Bar=}}", ""), + array( "{{Foo|} Bar=}}", ""), /* array( file_get_contents( dirname( __FILE__ ) . '/QuoteQuran.txt' ), file_get_contents( dirname( __FILE__ ) . '/QuoteQuranExpanded.txt' ) ), */ ); } + /** + * Get XML preprocessor tree from the preprocessor (which may not be the + * native XML-based one). + * + * @param string $wikiText + * @return string + */ + function preprocessToXml( $wikiText ) { + if ( method_exists( $this->mPreprocessor, 'preprocessToXml' ) ) { + return $this->normalizeXml( $this->mPreprocessor->preprocessToXml( $wikiText ) ); + } + + $dom = $this->mPreprocessor->preprocessToObj( $wikiText ); + if ( is_callable( array( $dom, 'saveXML' ) ) ) { + return $dom->saveXML(); + } else { + return $this->normalizeXml( $dom->__toString() ); + } + } + + /** + * Normalize XML string to the form that a DOMDocument saves out. + * + * @param string $xml + * @return string + */ + function normalizeXml( $xml ) { + return preg_replace( '!<([a-z]+)/>!', '<$1>', str_replace( ' />', '/>', $xml ) ); + + $dom = new DOMDocument(); + // 1 << 19 == XML_PARSE_HUGE, needed so newer versions of libxml2 don't barf when the XML is >256 levels deep + $dom->loadXML( $xml, 1 << 19 ); + return $dom->saveXML(); + } + /** * @dataProvider provideCases */ function testPreprocessorOutput( $wikiText, $expectedXml ) { - $this->assertEquals( $expectedXml, $this->mPreprocessor->preprocessToXml( $wikiText ) ); + $this->assertEquals( $this->normalizeXml( $expectedXml ), $this->preprocessToXml( $wikiText ) ); } /** @@ -130,11 +167,12 @@ class PreprocessorTest extends MediaWikiTestCase { function testPreprocessorOutputFiles( $filename ) { $folder = dirname( __FILE__ ) . "/../../../parser/preprocess"; $wikiText = file_get_contents( "$folder/$filename.txt" ); - $output = $this->mPreprocessor->preprocessToXml( $wikiText ); + $output = $this->preprocessToXml( $wikiText ); $expectedFilename = "$folder/$filename.expected"; if ( file_exists( $expectedFilename ) ) { - $this->assertStringEqualsFile( $expectedFilename, $output ); + $expectedXml = $this->normalizeXml( file_get_contents( $expectedFilename ) ); + $this->assertEquals( $expectedXml, $output ); } else { $tempFilename = tempnam( $folder, "$filename." ); file_put_contents( $tempFilename, $output ); @@ -189,7 +227,7 @@ class PreprocessorTest extends MediaWikiTestCase { * @dataProvider provideHeadings */ function testHeadings( $wikiText, $expectedXml ) { - $this->assertEquals( $expectedXml, $this->mPreprocessor->preprocessToXml( $wikiText ) ); + $this->assertEquals( $this->normalizeXml( $expectedXml ), $this->preprocessToXml( $wikiText ) ); } } -- cgit v1.2.3-54-g00ecf