From 0127c7c4461eddb1511e35de017ae498a756b7d8 Mon Sep 17 00:00:00 2001 From: Platonides Date: Sat, 15 Jan 2011 08:35:56 +0000 Subject: [PATCH] Add preprocessing tests --- .../includes/parser/PreprocessorTest.php | 81 +++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 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 0000000000..0b191cab00 --- /dev/null +++ b/tests/phpunit/includes/parser/PreprocessorTest.php @@ -0,0 +1,81 @@ +mOptions = new ParserOptions(); + $name = isset( $wgParserConf['preprocessorClass'] ) ? $wgParserConf['preprocessorClass'] : 'Preprocessor_DOM'; + + $this->mPreprocessor = new $name( $this ); + } + + function getStripList() { + return array( 'gallery' ); + } + + 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( "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( 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 ) ); + } + +} + -- 2.20.1