X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2Fparser%2FPreprocessorTest.php;h=6710b1929b6a6720a34e32f4ecb4f028d264de56;hb=65d7d79d1ba09afc362f9e542b7df97b7ecc9c3e;hp=a62503a62929028d89ae358665358a788ce6381b;hpb=90f599a5a2b46794a3002ee2f2563fc456a2fddb;p=lhc%2Fweb%2Fwiklou.git
diff --git a/tests/phpunit/includes/parser/PreprocessorTest.php b/tests/phpunit/includes/parser/PreprocessorTest.php
index a62503a629..6710b1929b 100644
--- a/tests/phpunit/includes/parser/PreprocessorTest.php
+++ b/tests/phpunit/includes/parser/PreprocessorTest.php
@@ -1,5 +1,29 @@
mOptions = ParserOptions::newFromUserAndLang( new User, $wgContLang );
- $name = isset( $wgParserConf['preprocessorClass'] )
- ? $wgParserConf['preprocessorClass']
- : 'Preprocessor_DOM';
- $this->mPreprocessor = new $name( $this );
+ $this->mPreprocessors = [];
+ foreach ( self::$classNames as $className ) {
+ $this->mPreprocessors[$className] = new $className( $this );
+ }
}
function getStripList() {
return [ 'gallery', 'display map' /* Used by Maps, see r80025 CR */, '/foo' ];
}
+ protected static function addClassArg( $testCases ) {
+ $newTestCases = [];
+ foreach ( self::$classNames as $className ) {
+ foreach ( $testCases as $testCase ) {
+ array_unshift( $testCase, $className );
+ $newTestCases[] = $testCase;
+ }
+ }
+ return $newTestCases;
+ }
+
public static function provideCases() {
// @codingStandardsIgnoreStart Ignore Generic.Files.LineLength.TooLong
- return [
+ return self::addClassArg( [
[ "Foo", "Foo" ],
[ "", "<!-- Foo -->" ],
[ "", "<!-- Foo --><!-- Bar -->" ],
@@ -115,7 +155,7 @@ class PreprocessorTest extends MediaWikiTestCase {
[ "{{Foo|} Bar=", "{{Foo|} Bar=" ],
[ "{{Foo|} Bar=}}", "Foo} Bar=" ],
/* [ file_get_contents( __DIR__ . '/QuoteQuran.txt' ], file_get_contents( __DIR__ . '/QuoteQuranExpanded.txt' ) ], */
- ];
+ ] );
// @codingStandardsIgnoreEnd
}
@@ -123,15 +163,17 @@ class PreprocessorTest extends MediaWikiTestCase {
* Get XML preprocessor tree from the preprocessor (which may not be the
* native XML-based one).
*
+ * @param string $className
* @param string $wikiText
* @return string
*/
- protected function preprocessToXml( $wikiText ) {
- if ( method_exists( $this->mPreprocessor, 'preprocessToXml' ) ) {
- return $this->normalizeXml( $this->mPreprocessor->preprocessToXml( $wikiText ) );
+ protected function preprocessToXml( $className, $wikiText ) {
+ $preprocessor = $this->mPreprocessors[$className];
+ if ( method_exists( $preprocessor, 'preprocessToXml' ) ) {
+ return $this->normalizeXml( $preprocessor->preprocessToXml( $wikiText ) );
}
- $dom = $this->mPreprocessor->preprocessToObj( $wikiText );
+ $dom = $preprocessor->preprocessToObj( $wikiText );
if ( is_callable( [ $dom, 'saveXML' ] ) ) {
return $dom->saveXML();
} else {
@@ -146,15 +188,20 @@ class PreprocessorTest extends MediaWikiTestCase {
* @return string
*/
protected function normalizeXml( $xml ) {
- return preg_replace( '!<([a-z]+)/>!', '<$1>$1>', str_replace( ' />', '/>', $xml ) );
+ // Normalize self-closing tags
+ $xml = preg_replace( '!<([a-z]+)/>!', '<$1>$1>', str_replace( ' />', '/>', $xml ) );
+ // Remove tags, which only occur in Preprocessor_Hash and
+ // have no semantic value
+ $xml = preg_replace( '!?equals>!', '', $xml );
+ return $xml;
}
/**
* @dataProvider provideCases
- * @covers Preprocessor_DOM::preprocessToXml
*/
- public function testPreprocessorOutput( $wikiText, $expectedXml ) {
- $this->assertEquals( $this->normalizeXml( $expectedXml ), $this->preprocessToXml( $wikiText ) );
+ public function testPreprocessorOutput( $className, $wikiText, $expectedXml ) {
+ $this->assertEquals( $this->normalizeXml( $expectedXml ),
+ $this->preprocessToXml( $className, $wikiText ) );
}
/**
@@ -162,24 +209,23 @@ class PreprocessorTest extends MediaWikiTestCase {
*/
public static function provideFiles() {
// @codingStandardsIgnoreStart Ignore Generic.Files.LineLength.TooLong
- return [
+ return self::addClassArg( [
[ "QuoteQuran" ], # http://en.wikipedia.org/w/index.php?title=Template:QuoteQuran/sandbox&oldid=237348988 GFDL + CC BY-SA by Striver
[ "Factorial" ], # http://en.wikipedia.org/w/index.php?title=Template:Factorial&oldid=98548758 GFDL + CC BY-SA by Polonium
[ "All_system_messages" ], # http://tl.wiktionary.org/w/index.php?title=Suleras:All_system_messages&oldid=2765 GPL text generated by MediaWiki
[ "Fundraising" ], # http://tl.wiktionary.org/w/index.php?title=MediaWiki:Sitenotice&oldid=5716 GFDL + CC BY-SA, copied there by Sky Harbor.
[ "NestedTemplates" ], # bug 27936
- ];
+ ] );
// @codingStandardsIgnoreEnd
}
/**
* @dataProvider provideFiles
- * @covers Preprocessor_DOM::preprocessToXml
*/
- public function testPreprocessorOutputFiles( $filename ) {
+ public function testPreprocessorOutputFiles( $className, $filename ) {
$folder = __DIR__ . "/../../../parser/preprocess";
$wikiText = file_get_contents( "$folder/$filename.txt" );
- $output = $this->preprocessToXml( $wikiText );
+ $output = $this->preprocessToXml( $className, $wikiText );
$expectedFilename = "$folder/$filename.expected";
if ( file_exists( $expectedFilename ) ) {
@@ -197,7 +243,8 @@ class PreprocessorTest extends MediaWikiTestCase {
*/
public static function provideHeadings() {
// @codingStandardsIgnoreStart Ignore Generic.Files.LineLength.TooLong
- return [ /* These should become headings: */
+ return self::addClassArg( [
+ /* These should become headings: */
[ "== h ==", "== h ==<!--c1-->" ],
[ "== h == ", "== h == <!--c1-->" ],
[ "== h == ", "== h ==<!--c1--> " ],
@@ -233,15 +280,15 @@ class PreprocessorTest extends MediaWikiTestCase {
[ "== h == x ", "== h == x <!--c1--><!--c2--><!--c3--> " ],
[ "== h == x ", "== h ==<!--c1--> x <!--c2--><!--c3--> " ],
[ "== h == x ", "== h ==<!--c1--><!--c2--><!--c3--> x " ],
- ];
+ ] );
// @codingStandardsIgnoreEnd
}
/**
* @dataProvider provideHeadings
- * @covers Preprocessor_DOM::preprocessToXml
*/
- public function testHeadings( $wikiText, $expectedXml ) {
- $this->assertEquals( $this->normalizeXml( $expectedXml ), $this->preprocessToXml( $wikiText ) );
+ public function testHeadings( $className, $wikiText, $expectedXml ) {
+ $this->assertEquals( $this->normalizeXml( $expectedXml ),
+ $this->preprocessToXml( $className, $wikiText ) );
}
}