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( "", "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=baz}}", "" ), array( "{{Foo|1=bar|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}}}}}", "" ), 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( 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 ) ) { $expectedXml = file_get_contents( $expectedFilename ); $this->assertEquals( $expectedXml, $output ); } else { $tempFilename = tempnam( $folder, "$filename." ); file_put_contents( $tempFilename, $output ); $this->markTestIncomplete( "File $expectedFilename missing. Output stored as $tempFilename" ); } } }