From ca32f08966f1b51fcb19460f0996bb0c4048e6fe Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Sat, 3 Dec 2011 13:29:22 +0100 Subject: Update to MediaWiki 1.18.0 * also update ArchLinux skin to chagnes in MonoBook * Use only css to hide our menu bar when printing --- tests/phpunit/includes/parser/PreprocessorTest.php | 195 +++++++++++++++++++++ 1 file changed, 195 insertions(+) create mode 100644 tests/phpunit/includes/parser/PreprocessorTest.php (limited to 'tests/phpunit/includes/parser/PreprocessorTest.php') diff --git a/tests/phpunit/includes/parser/PreprocessorTest.php b/tests/phpunit/includes/parser/PreprocessorTest.php new file mode 100644 index 00000000..7a5948d4 --- /dev/null +++ b/tests/phpunit/includes/parser/PreprocessorTest.php @@ -0,0 +1,195 @@ +mOptions = new ParserOptions(); + $name = isset( $wgParserConf['preprocessorClass'] ) ? $wgParserConf['preprocessorClass'] : 'Preprocessor_DOM'; + + $this->mPreprocessor = new $name( $this ); + } + + function getStripList() { + return array( 'gallery', 'display map' /* Used by Maps, see r80025 CR */, '/foo' ); + } + + function provideCases() { + return array( + array( "Foo", "Foo" ), + array( "", "<!-- Foo -->" ), + array( "", "<!-- Foo --><!-- Bar -->" ), + array( " ", "<!-- Foo --> <!-- Bar -->" ), + array( " \n ", "<!-- Foo --> \n <!-- Bar -->" ), + array( " \n \n", "<!-- Foo --> \n <!-- Bar -->\n" ), + array( " \n", "<!-- Foo --> <!-- Bar -->\n" ), + array( "Bar", "<!-->Bar" ), + array( "\n== Baz ==\n", "== Foo ==\n <!-- Bar -->\n== Baz ==\n" ), + array( "", "gallery" ), + array( "Foo Bar", "Foo gallery Bar" ), + array( "", "gallery</gallery>" ), + array( " ", "<foo> gallery</gallery>" ), + array( " ", "<foo> gallery<gallery></gallery>" ), + array( " Foo bar ", "<noinclude> Foo bar </noinclude>" ), + array( "\n{{Foo}}\n", "<noinclude>\n\n</noinclude>" ), + array( "\n{{Foo}}\n\n", "<noinclude>\n\n</noinclude>\n" ), + array( "foo bar", "galleryfoo bar" ), + array( "<{{foo}}>", "<>" ), + array( "<{{{foo}}}>", "<foo>" ), + array( "", "gallery</gallery</gallery>" ), + array( "=== Foo === ", "=== Foo === " ), + array( "=== Foo === ", "==<!-- -->= Foo === " ), + array( "=== Foo === ", "=== Foo ==<!-- -->= " ), + array( "=== Foo ===\n", "=== Foo ===<!-- -->\n" ), + array( "=== Foo === \n", "=== Foo ===<!-- --> <!-- -->\n" ), + array( "== Foo ==\n== Bar == \n", "== Foo ==\n== Bar == \n" ), + array( "===========", "===========" ), + array( "Foo\n=\n==\n=\n", "Foo\n=\n==\n=\n" ), + 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}}", "{<!-- -->{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}}}}}", "{" ), + 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]]}}", "{{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", "/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( "{{ {{Foo}}", "{{ "), + array( "{{Foobar {{Foo}} {{Bar}} {{Baz}} ", "{{Foobar "), + array( "[[Foo]] |", "[[Foo]] |"), + array( "{{Foo|Bar|", "{{Foo|Bar|"), + array( "[[Foo]", "[[Foo]"), + array( "[[Foo|Bar]", "[[Foo|Bar]"), + array( "{{Foo| [[Bar] }}", "{{Foo| [[Bar] }}"), + array( "{{Foo| [[Bar|Baz] }}", "{{Foo| [[Bar|Baz] }}"), + array( "{{Foo|bar=[[baz]}}", "{{Foo|bar=[[baz]}}"), + array( "{{foo|", "{{foo|"), + array( "{{foo|}", "{{foo|}"), + array( "{{foo|} }}", ""), + array( "{{foo|bar=|}", "{{foo|bar=|}"), + array( "{{Foo|} Bar=", "{{Foo|} Bar="), + array( "{{Foo|} Bar=}}", ""), + /* array( file_get_contents( dirname( __FILE__ ) . '/QuoteQuran.txt' ), file_get_contents( dirname( __FILE__ ) . '/QuoteQuranExpanded.txt' ) ), */ + ); + } + + /** + * @dataProvider provideCases + */ + function testPreprocessorOutput( $wikiText, $expectedXml ) { + $this->assertEquals( $expectedXml, $this->mPreprocessor->preprocessToXml( $wikiText ) ); + } + + /** + * These are more complex test cases taken out of wiki articles. + */ + function provideFiles() { + return array( + array( "QuoteQuran" ), # http://en.wikipedia.org/w/index.php?title=Template:QuoteQuran/sandbox&oldid=237348988 GFDL + CC-BY-SA by Striver + array( "Factorial" ), # http://en.wikipedia.org/w/index.php?title=Template:Factorial&oldid=98548758 GFDL + CC-BY-SA by Polonium + array( "All_system_messages" ), # http://tl.wiktionary.org/w/index.php?title=Suleras:All_system_messages&oldid=2765 GPL text generated by MediaWiki + array( "Fundraising" ), # http://tl.wiktionary.org/w/index.php?title=MediaWiki:Sitenotice&oldid=5716 GFDL + CC-BY-SA, copied there by Sky Harbor. + ); + } + + /** + * @dataProvider provideFiles + */ + function testPreprocessorOutputFiles( $filename ) { + $folder = dirname( __FILE__ ) . "/../../../parser/preprocess"; + $wikiText = file_get_contents( "$folder/$filename.txt" ); + $output = $this->mPreprocessor->preprocessToXml( $wikiText ); + + $expectedFilename = "$folder/$filename.expected"; + if ( file_exists( $expectedFilename ) ) { + $this->assertStringEqualsFile( $expectedFilename, $output ); + } else { + $tempFilename = tempnam( $folder, "$filename." ); + file_put_contents( $tempFilename, $output ); + $this->markTestIncomplete( "File $expectedFilename missing. Output stored as $tempFilename" ); + } + } + + /** + * Tests from Bug 28642 ยท https://bugzilla.wikimedia.org/28642 + */ + function provideHeadings() { + return array( /* These should become headings: */ + array( "== h ==", "== h ==<!--c1-->" ), + array( "== h == ", "== h == <!--c1-->" ), + array( "== h == ", "== h ==<!--c1--> " ), + array( "== h == ", "== h == <!--c1--> " ), + array( "== h ==", "== h ==<!--c1--><!--c2-->" ), + array( "== h == ", "== h == <!--c1--><!--c2-->" ), + array( "== h == ", "== h ==<!--c1--><!--c2--> " ), + array( "== h == ", "== h == <!--c1--><!--c2--> " ), + array( "== h == ", "== h == <!--c1--> <!--c2-->" ), + array( "== h == ", "== h ==<!--c1--> <!--c2--> " ), + array( "== h == ", "== h == <!--c1--> <!--c2--> " ), + array( "== h ==", "== h ==<!--c1--><!--c2--><!--c3-->" ), + array( "== h == ", "== h ==<!--c1--> <!--c2--><!--c3-->" ), + array( "== h == ", "== h ==<!--c1--><!--c2--> <!--c3-->" ), + array( "== h == ", "== h ==<!--c1--> <!--c2--> <!--c3-->" ), + array( "== h == ", "== h == <!--c1--><!--c2--><!--c3-->" ), + array( "== h == ", "== h == <!--c1--> <!--c2--><!--c3-->" ), + array( "== h == ", "== h == <!--c1--><!--c2--> <!--c3-->" ), + array( "== h == ", "== h == <!--c1--> <!--c2--> <!--c3-->" ), + array( "== h == ", "== h ==<!--c1--><!--c2--><!--c3--> " ), + array( "== h == ", "== h ==<!--c1--> <!--c2--><!--c3--> " ), + array( "== h == ", "== h ==<!--c1--><!--c2--> <!--c3--> " ), + array( "== h == ", "== h ==<!--c1--> <!--c2--> <!--c3--> " ), + array( "== h == ", "== h == <!--c1--><!--c2--><!--c3--> " ), + array( "== h == ", "== h == <!--c1--> <!--c2--><!--c3--> " ), + array( "== h == ", "== h == <!--c1--><!--c2--> <!--c3--> " ), + array( "== h == ", "== h == <!--c1--> <!--c2--> <!--c3--> " ), + + /* These are not working: */ + array( "== h == ", "== h ==<!--c1--> <!--c2-->" ), + array( "== h == ", "== h == <!--c1--> <!--c2-->" ), + array( "== h == ", "== h ==<!--c1--> <!--c2--> " ), + array( "== h == x ", "== h == x <!--c1--><!--c2--><!--c3--> " ), + array( "== h == x ", "== h ==<!--c1--> x <!--c2--><!--c3--> " ), + array( "== h == x ", "== h ==<!--c1--><!--c2--><!--c3--> x " ), + ); + } + + /** + * @dataProvider provideHeadings + */ + function testHeadings( $wikiText, $expectedXml ) { + $this->assertEquals( $expectedXml, $this->mPreprocessor->preprocessToXml( $wikiText ) ); + } +} + -- cgit v1.2.2