3 class RemexDriverTest
extends MediaWikiTestCase
{
4 static private $remexTidyTestData = [
5 // Tests from Html5Depurate
17 'No p-wrap of blank node',
22 'p-wrap terminated by div',
27 'p-wrap not terminated by span',
29 "<p>x<span></span></p>"
32 'An element is non-blank and so gets p-wrapped',
34 "<p><span></span></p>"
37 'The blank flag is set after a block-level element',
42 'Blank detection between two block-level elements',
43 "<div></div> <div></div>",
44 "<div></div> <div></div>"
47 'But p-wrapping of non-blank content works after an element',
52 'p-wrapping between two block-level elements',
53 "<div></div>x<div></div>",
54 "<div></div><p>x</p><div></div>"
57 'p-wrap inside blockquote',
58 "<blockquote>x</blockquote>",
59 "<blockquote><p>x</p></blockquote>"
62 'A comment is blank for p-wrapping purposes',
67 'A comment is blank even when a p-wrap was opened by a text node',
72 'A comment does not open a p-wrap',
77 'A comment does not close a p-wrap',
84 "<ul><li class=\"mw-empty-elt\"></li></ul>"
88 "<ul><li><span></span></li></ul>",
89 "<ul><li><span></span></li></ul>"
93 "<ul><li>x</li></ul>",
98 "<table><tbody><tr></tr></tbody></table>",
99 "<table><tbody><tr class=\"mw-empty-elt\"></tr></tbody></table>"
104 "<p class=\"mw-empty-elt\">\n</p>"
107 'No p-wrapping of an inline element which contains a block element (T150317)',
108 "<small><div>x</div></small>",
109 "<small><div>x</div></small>"
112 'p-wrapping of an inline element which contains an inline element',
113 "<small><b>x</b></small>",
114 "<p><small><b>x</b></small></p>"
117 'p-wrapping is enabled in a blockquote in an inline element',
118 "<small><blockquote>x</blockquote></small>",
119 "<small><blockquote><p>x</p></blockquote></small>"
122 'All bare text should be p-wrapped even when surrounded by block tags',
123 "<small><blockquote>x</blockquote></small>y<div></div>z",
124 "<small><blockquote><p>x</p></blockquote></small><p>y</p><div></div><p>z</p>"
128 "<small>x<div>y</div>z</small>",
129 "<p><small>x</small></p><small><div>y</div></small><p><small>z</small></p>"
133 "<small><div>y</div>z</small>",
134 "<small><div>y</div></small><p><small>z</small></p>"
138 "<small>x<div>y</div></small>",
139 "<p><small>x</small></p><small><div>y</div></small>"
142 'Split tag stack 4 (modified to use splittable tag)',
143 "a<code>b<i>c<div>d</div></i>e</code>",
144 "<p>a<code>b<i>c</i></code></p><code><i><div>d</div></i></code><p><code>e</code></p>"
147 "Split tag stack regression check 1",
148 "x<span><div>y</div></span>",
149 "<p>x</p><span><div>y</div></span>"
152 "Split tag stack regression check 2 (modified to use splittable tag)",
153 "a<code><i><div>d</div></i>e</code>",
154 "<p>a</p><code><i><div>d</div></i></code><p><code>e</code></p>"
156 // Simple tests from pwrap.js
158 'Simple pwrap test 1',
163 '<span> is not a splittable tag, but gets p-wrapped in simple wrapping scenarios',
165 '<p><span>a</span></p>'
168 'Simple pwrap test 3',
169 'x <div>a</div> <div>b</div> y',
170 '<p>x </p><div>a</div> <div>b</div><p> y</p>'
173 'Simple pwrap test 4',
174 'x<!--c--> <div>a</div> <div>b</div> <!--c-->y',
175 '<p>x<!--c--> </p><div>a</div> <div>b</div> <!--c--><p>y</p>'
177 // Complex tests from pwrap.js
179 'Complex pwrap test 1',
180 '<i>x<div>a</div>y</i>',
181 '<p><i>x</i></p><i><div>a</div></i><p><i>y</i></p>'
184 'Complex pwrap test 2',
185 'a<small>b</small><i>c<div>d</div>e</i>f',
186 '<p>a<small>b</small><i>c</i></p><i><div>d</div></i><p><i>e</i>f</p>'
189 'Complex pwrap test 3',
190 'a<small>b<i>c<div>d</div></i>e</small>',
191 '<p>a<small>b<i>c</i></small></p><small><i><div>d</div></i></small><p><small>e</small></p>'
194 'Complex pwrap test 4',
195 'x<small><div>y</div></small>',
196 '<p>x</p><small><div>y</div></small>'
199 'Complex pwrap test 5',
200 'a<small><i><div>d</div></i>e</small>',
201 '<p>a</p><small><i><div>d</div></i></small><p><small>e</small></p>'
204 'Complex pwrap test 6',
205 '<i>a<div>b</div>c<b>d<div>e</div>f</b>g</i>',
206 // @codingStandardsIgnoreStart Generic.Files.LineLength.TooLong
207 // PHP 5 does not allow concatenation in initialisation of a class static variable
208 '<p><i>a</i></p><i><div>b</div></i><p><i>c<b>d</b></i></p><i><b><div>e</div></b></i><p><i><b>f</b>g</i></p>'
209 // @codingStandardsIgnoreEnd
211 /* FIXME the second <b> causes a stack split which clones the <i> even
212 * though no <p> is actually generated
214 'Complex pwrap test 7',
215 '<i><b><font><div>x</div></font></b><div>y</div><b><font><div>z</div></font></b></i>',
216 '<i><b><font><div>x</div></font></b><div>y</div><b><font><div>z</div></font></b></i>'
221 'Blank text node after block end',
222 '<small>x<div>y</div> <b>z</b></small>',
223 '<p><small>x</small></p><small><div>y</div></small><p><small> <b>z</b></small></p>'
226 'Text node fostering (FIXME: wrap missing)',
231 'Blockquote fostering',
232 '<table><blockquote>x</blockquote></table>',
233 '<blockquote><p>x</p></blockquote><table></table>'
236 'Block element fostering',
238 '<div>x</div><table></table>'
241 'Formatting element fostering (FIXME: wrap missing)',
243 '<b>x</b><table></table>'
246 'AAA clone of p-wrapped element (FIXME: empty b)',
248 '<p><b>x</b></p><b></b><p><b>y</b>z</p>',
251 'AAA with fostering (FIXME: wrap missing)',
252 '<table><b>1<p>2</b>3</p>',
253 '<b>1</b><p><b>2</b>3</p><table></table>'
257 public function provider() {
258 return self
::$remexTidyTestData;
262 * @dataProvider provider
263 * @covers MediaWiki\Tidy\RemexCompatFormatter
264 * @covers MediaWiki\Tidy\RemexCompatMunger
265 * @covers MediaWiki\Tidy\RemexDriver
266 * @covers MediaWiki\Tidy\RemexMungerData
268 public function testTidy( $desc, $input, $expected ) {
269 $r = new MediaWiki\Tidy\
RemexDriver( [] );
270 $result = $r->tidy( $input );
271 $this->assertEquals( $expected, $result, $desc );
274 public function html5libProvider() {
275 $files = json_decode( file_get_contents( __DIR__
. '/html5lib-tests.json' ), true );
277 foreach ( $files as $file => $fileTests ) {
278 foreach ( $fileTests as $i => $test ) {
279 $tests[] = [ "$file:$i", $test['data'] ];
286 * This is a quick and dirty test to make sure none of the html5lib tests
287 * generate exceptions. We don't really know what the expected output is.
289 * @dataProvider html5libProvider
292 public function testHtml5Lib( $desc, $input ) {
293 $r = new MediaWiki\Tidy\
RemexDriver( [] );
294 $result = $r->tidy( $input );
295 $this->assertTrue( true, $desc );