*/
protected $mOptions;
/**
- * @var Preprocessor
+ * @var array
*/
- protected $mPreprocessor;
+ protected $mPreprocessors;
+
+ protected static $classNames = [
+ 'Preprocessor_DOM',
+ 'Preprocessor_Hash'
+ ];
protected function setUp() {
- global $wgParserConf, $wgContLang;
+ global $wgContLang;
parent::setUp();
$this->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", "<root>Foo</root>" ],
[ "<!-- Foo -->", "<root><comment><!-- Foo --></comment></root>" ],
[ "<!-- Foo --><!-- Bar -->", "<root><comment><!-- Foo --></comment><comment><!-- Bar --></comment></root>" ],
[ "{{Foo|} Bar=", "<root>{{Foo|} Bar=</root>" ],
[ "{{Foo|} Bar=}}", "<root><template><title>Foo</title><part><name>} Bar</name>=<value></value></part></template></root>" ],
/* [ file_get_contents( __DIR__ . '/QuoteQuran.txt' ], file_get_contents( __DIR__ . '/QuoteQuranExpanded.txt' ) ], */
- ];
+ ] );
// @codingStandardsIgnoreEnd
}
* 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 {
* @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 <equals> 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 ) );
}
/**
*/
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 ) ) {
*/
public static function provideHeadings() {
// @codingStandardsIgnoreStart Ignore Generic.Files.LineLength.TooLong
- return [ /* These should become headings: */
+ return self::addClassArg( [
+ /* These should become headings: */
[ "== h ==<!--c1-->", "<root><h level=\"2\" i=\"1\">== h ==<comment><!--c1--></comment></h></root>" ],
[ "== h == <!--c1-->", "<root><h level=\"2\" i=\"1\">== h == <comment><!--c1--></comment></h></root>" ],
[ "== h ==<!--c1--> ", "<root><h level=\"2\" i=\"1\">== h ==<comment><!--c1--></comment> </h></root>" ],
[ "== h == x <!--c1--><!--c2--><!--c3--> ", "<root>== h == x <comment><!--c1--></comment><comment><!--c2--></comment><comment><!--c3--></comment> </root>" ],
[ "== h ==<!--c1--> x <!--c2--><!--c3--> ", "<root>== h ==<comment><!--c1--></comment> x <comment><!--c2--></comment><comment><!--c3--></comment> </root>" ],
[ "== h ==<!--c1--><!--c2--><!--c3--> x ", "<root>== h ==<comment><!--c1--></comment><comment><!--c2--></comment><comment><!--c3--></comment> x </root>" ],
- ];
+ ] );
// @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 ) );
}
}