49 $this->mPreprocessors = [];
50 foreach ( self::$classNames
as $className ) {
51 $this->mPreprocessors[$className] =
new $className( $this );
56 return [
'gallery',
'display map' ,
'/foo' ];
61 foreach ( self::$classNames
as $className ) {
62 foreach ( $testCases
as $testCase ) {
63 array_unshift( $testCase, $className );
64 $newTestCases[] = $testCase;
73 [
"Foo",
"<root>Foo</root>" ],
74 [
"<!-- Foo -->",
"<root><comment><!-- Foo --></comment></root>" ],
75 [
"<!-- Foo --><!-- Bar -->",
"<root><comment><!-- Foo --></comment><comment><!-- Bar --></comment></root>" ],
76 [
"<!-- Foo --> <!-- Bar -->",
"<root><comment><!-- Foo --></comment> <comment><!-- Bar --></comment></root>" ],
77 [
"<!-- Foo --> \n <!-- Bar -->",
"<root><comment><!-- Foo --></comment> \n <comment><!-- Bar --></comment></root>" ],
78 [
"<!-- Foo --> \n <!-- Bar -->\n",
"<root><comment><!-- Foo --></comment> \n<comment> <!-- Bar -->\n</comment></root>" ],
79 [
"<!-- Foo --> <!-- Bar -->\n",
"<root><comment><!-- Foo --></comment> <comment><!-- Bar --></comment>\n</root>" ],
80 [
"<!-->Bar",
"<root><comment><!-->Bar</comment></root>" ],
81 [
"<!-- Comment -- comment",
"<root><comment><!-- Comment -- comment</comment></root>" ],
82 [
"== Foo ==\n <!-- Bar -->\n== Baz ==\n",
"<root><h level=\"2\" i=\"1\">== Foo ==</h>\n<comment> <!-- Bar -->\n</comment><h level=\"2\" i=\"2\">== Baz ==</h>\n</root>" ],
83 [
"<gallery/>",
"<root><ext><name>gallery</name><attr></attr></ext></root>" ],
84 [
"Foo <gallery/> Bar",
"<root>Foo <ext><name>gallery</name><attr></attr></ext> Bar</root>" ],
85 [
"<gallery></gallery>",
"<root><ext><name>gallery</name><attr></attr><inner></inner><close></gallery></close></ext></root>" ],
86 [
"<foo> <gallery></gallery>",
"<root><foo> <ext><name>gallery</name><attr></attr><inner></inner><close></gallery></close></ext></root>" ],
87 [
"<foo> <gallery><gallery></gallery>",
"<root><foo> <ext><name>gallery</name><attr></attr><inner><gallery></inner><close></gallery></close></ext></root>" ],
88 [
"<noinclude> Foo bar </noinclude>",
"<root><ignore><noinclude></ignore> Foo bar <ignore></noinclude></ignore></root>" ],
89 [
"<noinclude>\n{{Foo}}\n</noinclude>",
"<root><ignore><noinclude></ignore>\n<template lineStart=\"1\"><title>Foo</title></template>\n<ignore></noinclude></ignore></root>" ],
90 [
"<noinclude>\n{{Foo}}\n</noinclude>\n",
"<root><ignore><noinclude></ignore>\n<template lineStart=\"1\"><title>Foo</title></template>\n<ignore></noinclude></ignore>\n</root>" ],
91 [
"<gallery>foo bar",
"<root><gallery>foo bar</root>" ],
92 [
"<{{foo}}>",
"<root><<template><title>foo</title></template>></root>" ],
93 [
"<{{{foo}}}>",
"<root><<tplarg><title>foo</title></tplarg>></root>" ],
94 [
"<gallery></gallery</gallery>",
"<root><ext><name>gallery</name><attr></attr><inner></gallery</inner><close></gallery></close></ext></root>" ],
95 [
"=== Foo === ",
"<root><h level=\"3\" i=\"1\">=== Foo === </h></root>" ],
96 [
"==<!-- -->= Foo === ",
"<root><h level=\"2\" i=\"1\">==<comment><!-- --></comment>= Foo === </h></root>" ],
97 [
"=== Foo ==<!-- -->= ",
"<root><h level=\"1\" i=\"1\">=== Foo ==<comment><!-- --></comment>= </h></root>" ],
98 [
"=== Foo ===<!-- -->\n",
"<root><h level=\"3\" i=\"1\">=== Foo ===<comment><!-- --></comment></h>\n</root>" ],
99 [
"=== Foo ===<!-- --> <!-- -->\n",
"<root><h level=\"3\" i=\"1\">=== Foo ===<comment><!-- --></comment> <comment><!-- --></comment></h>\n</root>" ],
100 [
"== Foo ==\n== Bar == \n",
"<root><h level=\"2\" i=\"1\">== Foo ==</h>\n<h level=\"2\" i=\"2\">== Bar == </h>\n</root>" ],
101 [
"===========",
"<root><h level=\"5\" i=\"1\">===========</h></root>" ],
102 [
"Foo\n=\n==\n=\n",
"<root>Foo\n=\n==\n=\n</root>" ],
103 [
"{{Foo}}",
"<root><template><title>Foo</title></template></root>" ],
104 [
"\n{{Foo}}",
"<root>\n<template lineStart=\"1\"><title>Foo</title></template></root>" ],
105 [
"{{Foo|bar}}",
"<root><template><title>Foo</title><part><name index=\"1\" /><value>bar</value></part></template></root>" ],
106 [
"{{Foo|bar}}a",
"<root><template><title>Foo</title><part><name index=\"1\" /><value>bar</value></part></template>a</root>" ],
107 [
"{{Foo|bar|baz}}",
"<root><template><title>Foo</title><part><name index=\"1\" /><value>bar</value></part><part><name index=\"2\" /><value>baz</value></part></template></root>" ],
108 [
"{{Foo|1=bar}}",
"<root><template><title>Foo</title><part><name>1</name>=<value>bar</value></part></template></root>" ],
109 [
"{{Foo|=bar}}",
"<root><template><title>Foo</title><part><name></name>=<value>bar</value></part></template></root>" ],
110 [
"{{Foo|bar=baz}}",
"<root><template><title>Foo</title><part><name>bar</name>=<value>baz</value></part></template></root>" ],
111 [
"{{Foo|{{bar}}=baz}}",
"<root><template><title>Foo</title><part><name><template><title>bar</title></template></name>=<value>baz</value></part></template></root>" ],
112 [
"{{Foo|1=bar|baz}}",
"<root><template><title>Foo</title><part><name>1</name>=<value>bar</value></part><part><name index=\"1\" /><value>baz</value></part></template></root>" ],
113 [
"{{Foo|1=bar|2=baz}}",
"<root><template><title>Foo</title><part><name>1</name>=<value>bar</value></part><part><name>2</name>=<value>baz</value></part></template></root>" ],
114 [
"{{Foo|bar|foo=baz}}",
"<root><template><title>Foo</title><part><name index=\"1\" /><value>bar</value></part><part><name>foo</name>=<value>baz</value></part></template></root>" ],
115 [
"{{{1}}}",
"<root><tplarg><title>1</title></tplarg></root>" ],
116 [
"{{{1|}}}",
"<root><tplarg><title>1</title><part><name index=\"1\" /><value></value></part></tplarg></root>" ],
117 [
"{{{Foo}}}",
"<root><tplarg><title>Foo</title></tplarg></root>" ],
118 [
"{{{Foo|}}}",
"<root><tplarg><title>Foo</title><part><name index=\"1\" /><value></value></part></tplarg></root>" ],
119 [
"{{{Foo|bar|baz}}}",
"<root><tplarg><title>Foo</title><part><name index=\"1\" /><value>bar</value></part><part><name index=\"2\" /><value>baz</value></part></tplarg></root>" ],
120 [
"{<!-- -->{Foo}}",
"<root>{<comment><!-- --></comment>{Foo}}</root>" ],
121 [
"{{{{Foobar}}}}",
"<root>{<tplarg><title>Foobar</title></tplarg>}</root>" ],
122 [
"{{{ {{Foo}} }}}",
"<root><tplarg><title> <template><title>Foo</title></template> </title></tplarg></root>" ],
123 [
"{{ {{{Foo}}} }}",
"<root><template><title> <tplarg><title>Foo</title></tplarg> </title></template></root>" ],
124 [
"{{{{{Foo}}}}}",
"<root><template><title><tplarg><title>Foo</title></tplarg></title></template></root>" ],
125 [
"{{{{{Foo}} }}}",
"<root><tplarg><title><template><title>Foo</title></template> </title></tplarg></root>" ],
126 [
"{{{{{{Foo}}}}}}",
"<root><tplarg><title><tplarg><title>Foo</title></tplarg></title></tplarg></root>" ],
127 [
"{{{{{{Foo}}}}}",
"<root>{<template><title><tplarg><title>Foo</title></tplarg></title></template></root>" ],
128 [
"[[[Foo]]",
"<root>[[[Foo]]</root>" ],
129 [
"{{Foo|[[[[bar]]|baz]]}}",
"<root><template><title>Foo</title><part><name index=\"1\" /><value>[[[[bar]]|baz]]</value></part></template></root>" ],
130 [
"{{Foo|[[[[bar]|baz]]}}",
"<root>{{Foo|[[[[bar]|baz]]}}</root>" ],
131 [
"{{Foo|Foo [[[[bar]|baz]]}}",
"<root>{{Foo|Foo [[[[bar]|baz]]}}</root>" ],
132 [
"Foo <display map>Bar</display map >Baz",
"<root>Foo <ext><name>display map</name><attr></attr><inner>Bar</inner><close></display map ></close></ext>Baz</root>" ],
133 [
"Foo <display map foo>Bar</display map >Baz",
"<root>Foo <ext><name>display map</name><attr> foo</attr><inner>Bar</inner><close></display map ></close></ext>Baz</root>" ],
134 [
"Foo <gallery bar=\"baz\" />",
"<root>Foo <ext><name>gallery</name><attr> bar="baz" </attr></ext></root>" ],
135 [
"Foo <gallery bar=\"1\" baz=2 />",
"<root>Foo <ext><name>gallery</name><attr> bar="1" baz=2 </attr></ext></root>" ],
136 [
"</foo>Foo<//foo>",
"<root><ext><name>/foo</name><attr></attr><inner>Foo</inner><close><//foo></close></ext></root>" ], # Worth blacklisting IMHO
137 [
"{{#ifexpr: ({{{1|1}}} = 2) | Foo | Bar }}",
"<root><template><title>#ifexpr: (<tplarg><title>1</title><part><name index=\"1\" /><value>1</value></part></tplarg> = 2) </title><part><name index=\"1\" /><value> Foo </value></part><part><name index=\"2\" /><value> Bar </value></part></template></root>" ],
138 [
"{{#if: {{{1|}}} | Foo | {{Bar}} }}",
"<root><template><title>#if: <tplarg><title>1</title><part><name index=\"1\" /><value></value></part></tplarg> </title><part><name index=\"1\" /><value> Foo </value></part><part><name index=\"2\" /><value> <template><title>Bar</title></template> </value></part></template></root>" ],
139 [
"{{#if: {{{1|}}} | Foo | [[Bar]] }}",
"<root><template><title>#if: <tplarg><title>1</title><part><name index=\"1\" /><value></value></part></tplarg> </title><part><name index=\"1\" /><value> Foo </value></part><part><name index=\"2\" /><value> [[Bar]] </value></part></template></root>" ],
140 [
"{{#if: {{{1|}}} | [[Foo]] | Bar }}",
"<root><template><title>#if: <tplarg><title>1</title><part><name index=\"1\" /><value></value></part></tplarg> </title><part><name index=\"1\" /><value> [[Foo]] </value></part><part><name index=\"2\" /><value> Bar </value></part></template></root>" ],
141 [
"{{#if: {{{1|}}} | 1 | {{#if: {{{1|}}} | 2 | 3 }} }}",
"<root><template><title>#if: <tplarg><title>1</title><part><name index=\"1\" /><value></value></part></tplarg> </title><part><name index=\"1\" /><value> 1 </value></part><part><name index=\"2\" /><value> <template><title>#if: <tplarg><title>1</title><part><name index=\"1\" /><value></value></part></tplarg> </title><part><name index=\"1\" /><value> 2 </value></part><part><name index=\"2\" /><value> 3 </value></part></template> </value></part></template></root>" ],
142 [
"{{ {{Foo}}",
"<root>{{ <template><title>Foo</title></template></root>" ],
143 [
"{{Foobar {{Foo}} {{Bar}} {{Baz}} ",
"<root>{{Foobar <template><title>Foo</title></template> <template><title>Bar</title></template> <template><title>Baz</title></template> </root>" ],
144 [
"[[Foo]] |",
"<root>[[Foo]] |</root>" ],
145 [
"{{Foo|Bar|",
"<root>{{Foo|Bar|</root>" ],
146 [
"[[Foo]",
"<root>[[Foo]</root>" ],
147 [
"[[Foo|Bar]",
"<root>[[Foo|Bar]</root>" ],
148 [
"{{Foo| [[Bar] }}",
"<root>{{Foo| [[Bar] }}</root>" ],
149 [
"{{Foo| [[Bar|Baz] }}",
"<root>{{Foo| [[Bar|Baz] }}</root>" ],
150 [
"{{Foo|bar=[[baz]}}",
"<root>{{Foo|bar=[[baz]}}</root>" ],
151 [
"{{foo|",
"<root>{{foo|</root>" ],
152 [
"{{foo|}",
"<root>{{foo|}</root>" ],
153 [
"{{foo|} }}",
"<root><template><title>foo</title><part><name index=\"1\" /><value>} </value></part></template></root>" ],
154 [
"{{foo|bar=|}",
"<root>{{foo|bar=|}</root>" ],
155 [
"{{Foo|} Bar=",
"<root>{{Foo|} Bar=</root>" ],
156 [
"{{Foo|} Bar=}}",
"<root><template><title>Foo</title><part><name>} Bar</name>=<value></value></part></template></root>" ],
171 $preprocessor = $this->mPreprocessors[$className];
172 if ( method_exists( $preprocessor,
'preprocessToXml' ) ) {
173 return $this->
normalizeXml( $preprocessor->preprocessToXml( $wikiText ) );
176 $dom = $preprocessor->preprocessToObj( $wikiText );
177 if ( is_callable( [ $dom,
'saveXML' ] ) ) {
178 return $dom->saveXML();
192 $xml = preg_replace(
'!<([a-z]+)/>!',
'<$1></$1>', str_replace(
' />',
'/>', $xml ) );
195 $xml = preg_replace(
'!</?equals>!',
'', $xml );
203 $this->assertEquals( $this->
normalizeXml( $expectedXml ),
213 [
"QuoteQuran" ], #
https:
214 [
"Factorial" ], #
https:
215 [
"All_system_messages" ], #
https:
216 [
"Fundraising" ], #
https:
217 [
"NestedTemplates" ], # T29936
226 $folder = __DIR__ .
"/../../../parser/preprocess";
227 $wikiText = file_get_contents(
"$folder/$filename.txt" );
230 $expectedFilename =
"$folder/$filename.expected";
231 if ( file_exists( $expectedFilename ) ) {
232 $expectedXml = $this->
normalizeXml( file_get_contents( $expectedFilename ) );
233 $this->assertEquals( $expectedXml,
$output );
235 $tempFilename = tempnam( $folder,
"$filename." );
236 file_put_contents( $tempFilename,
$output );
237 $this->markTestIncomplete(
"File $expectedFilename missing. Output stored as $tempFilename" );
248 [
"== h ==<!--c1-->",
"<root><h level=\"2\" i=\"1\">== h ==<comment><!--c1--></comment></h></root>" ],
249 [
"== h == <!--c1-->",
"<root><h level=\"2\" i=\"1\">== h == <comment><!--c1--></comment></h></root>" ],
250 [
"== h ==<!--c1--> ",
"<root><h level=\"2\" i=\"1\">== h ==<comment><!--c1--></comment> </h></root>" ],
251 [
"== h == <!--c1--> ",
"<root><h level=\"2\" i=\"1\">== h == <comment><!--c1--></comment> </h></root>" ],
252 [
"== h ==<!--c1--><!--c2-->",
"<root><h level=\"2\" i=\"1\">== h ==<comment><!--c1--></comment><comment><!--c2--></comment></h></root>" ],
253 [
"== h == <!--c1--><!--c2-->",
"<root><h level=\"2\" i=\"1\">== h == <comment><!--c1--></comment><comment><!--c2--></comment></h></root>" ],
254 [
"== h ==<!--c1--><!--c2--> ",
"<root><h level=\"2\" i=\"1\">== h ==<comment><!--c1--></comment><comment><!--c2--></comment> </h></root>" ],
255 [
"== h == <!--c1--><!--c2--> ",
"<root><h level=\"2\" i=\"1\">== h == <comment><!--c1--></comment><comment><!--c2--></comment> </h></root>" ],
256 [
"== h == <!--c1--> <!--c2-->",
"<root><h level=\"2\" i=\"1\">== h == <comment><!--c1--></comment> <comment><!--c2--></comment></h></root>" ],
257 [
"== h ==<!--c1--> <!--c2--> ",
"<root><h level=\"2\" i=\"1\">== h ==<comment><!--c1--></comment> <comment><!--c2--></comment> </h></root>" ],
258 [
"== h == <!--c1--> <!--c2--> ",
"<root><h level=\"2\" i=\"1\">== h == <comment><!--c1--></comment> <comment><!--c2--></comment> </h></root>" ],
259 [
"== h ==<!--c1--><!--c2--><!--c3-->",
"<root><h level=\"2\" i=\"1\">== h ==<comment><!--c1--></comment><comment><!--c2--></comment><comment><!--c3--></comment></h></root>" ],
260 [
"== h ==<!--c1--> <!--c2--><!--c3-->",
"<root><h level=\"2\" i=\"1\">== h ==<comment><!--c1--></comment> <comment><!--c2--></comment><comment><!--c3--></comment></h></root>" ],
261 [
"== h ==<!--c1--><!--c2--> <!--c3-->",
"<root><h level=\"2\" i=\"1\">== h ==<comment><!--c1--></comment><comment><!--c2--></comment> <comment><!--c3--></comment></h></root>" ],
262 [
"== h ==<!--c1--> <!--c2--> <!--c3-->",
"<root><h level=\"2\" i=\"1\">== h ==<comment><!--c1--></comment> <comment><!--c2--></comment> <comment><!--c3--></comment></h></root>" ],
263 [
"== h == <!--c1--><!--c2--><!--c3-->",
"<root><h level=\"2\" i=\"1\">== h == <comment><!--c1--></comment><comment><!--c2--></comment><comment><!--c3--></comment></h></root>" ],
264 [
"== h == <!--c1--> <!--c2--><!--c3-->",
"<root><h level=\"2\" i=\"1\">== h == <comment><!--c1--></comment> <comment><!--c2--></comment><comment><!--c3--></comment></h></root>" ],
265 [
"== h == <!--c1--><!--c2--> <!--c3-->",
"<root><h level=\"2\" i=\"1\">== h == <comment><!--c1--></comment><comment><!--c2--></comment> <comment><!--c3--></comment></h></root>" ],
266 [
"== h == <!--c1--> <!--c2--> <!--c3-->",
"<root><h level=\"2\" i=\"1\">== h == <comment><!--c1--></comment> <comment><!--c2--></comment> <comment><!--c3--></comment></h></root>" ],
267 [
"== h ==<!--c1--><!--c2--><!--c3--> ",
"<root><h level=\"2\" i=\"1\">== h ==<comment><!--c1--></comment><comment><!--c2--></comment><comment><!--c3--></comment> </h></root>" ],
268 [
"== h ==<!--c1--> <!--c2--><!--c3--> ",
"<root><h level=\"2\" i=\"1\">== h ==<comment><!--c1--></comment> <comment><!--c2--></comment><comment><!--c3--></comment> </h></root>" ],
269 [
"== h ==<!--c1--><!--c2--> <!--c3--> ",
"<root><h level=\"2\" i=\"1\">== h ==<comment><!--c1--></comment><comment><!--c2--></comment> <comment><!--c3--></comment> </h></root>" ],
270 [
"== h ==<!--c1--> <!--c2--> <!--c3--> ",
"<root><h level=\"2\" i=\"1\">== h ==<comment><!--c1--></comment> <comment><!--c2--></comment> <comment><!--c3--></comment> </h></root>" ],
271 [
"== h == <!--c1--><!--c2--><!--c3--> ",
"<root><h level=\"2\" i=\"1\">== h == <comment><!--c1--></comment><comment><!--c2--></comment><comment><!--c3--></comment> </h></root>" ],
272 [
"== h == <!--c1--> <!--c2--><!--c3--> ",
"<root><h level=\"2\" i=\"1\">== h == <comment><!--c1--></comment> <comment><!--c2--></comment><comment><!--c3--></comment> </h></root>" ],
273 [
"== h == <!--c1--><!--c2--> <!--c3--> ",
"<root><h level=\"2\" i=\"1\">== h == <comment><!--c1--></comment><comment><!--c2--></comment> <comment><!--c3--></comment> </h></root>" ],
274 [
"== h == <!--c1--> <!--c2--> <!--c3--> ",
"<root><h level=\"2\" i=\"1\">== h == <comment><!--c1--></comment> <comment><!--c2--></comment> <comment><!--c3--></comment> </h></root>" ],
275 [
"== h ==<!--c1--> <!--c2-->",
"<root><h level=\"2\" i=\"1\">== h ==<comment><!--c1--></comment> <comment><!--c2--></comment></h></root>" ],
276 [
"== h == <!--c1--> <!--c2-->",
"<root><h level=\"2\" i=\"1\">== h == <comment><!--c1--></comment> <comment><!--c2--></comment></h></root>" ],
277 [
"== h ==<!--c1--> <!--c2--> ",
"<root><h level=\"2\" i=\"1\">== h ==<comment><!--c1--></comment> <comment><!--c2--></comment> </h></root>" ],
280 [
"== h == x <!--c1--><!--c2--><!--c3--> ",
"<root>== h == x <comment><!--c1--></comment><comment><!--c2--></comment><comment><!--c3--></comment> </root>" ],
281 [
"== h ==<!--c1--> x <!--c2--><!--c3--> ",
"<root>== h ==<comment><!--c1--></comment> x <comment><!--c2--></comment><comment><!--c3--></comment> </root>" ],
282 [
"== h ==<!--c1--><!--c2--><!--c3--> x ",
"<root>== h ==<comment><!--c1--></comment><comment><!--c2--></comment><comment><!--c3--></comment> x </root>" ],
291 $this->assertEquals( $this->
normalizeXml( $expectedXml ),