rdbms: Rename "memCache" to "memStash" in LBFactory
[mediawiki.git] / tests / phpunit / includes / tidy / RemexDriverTest.php
blob6b16cbf695cd33b9b1f4013479e0e0b32d5777cb
1 <?php
3 class RemexDriverTest extends MediaWikiTestCase {
4 static private $remexTidyTestData = [
5 // Tests from Html5Depurate
7 'Empty string',
8 "",
9 ""
12 'Simple p-wrap',
13 "x",
14 "<p>x</p>"
17 'No p-wrap of blank node',
18 " ",
19 " "
22 'p-wrap terminated by div',
23 "x<div></div>",
24 "<p>x</p><div></div>"
27 'p-wrap not terminated by span',
28 "x<span></span>",
29 "<p>x<span></span></p>"
32 'An element is non-blank and so gets p-wrapped',
33 "<span></span>",
34 "<p><span></span></p>"
37 'The blank flag is set after a block-level element',
38 "<div></div> ",
39 "<div></div> "
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',
48 "<div></div>x",
49 "<div></div><p>x</p>"
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',
63 "<!-- x -->",
64 "<!-- x -->"
67 'A comment is blank even when a p-wrap was opened by a text node',
68 " <!-- x -->",
69 " <!-- x -->"
72 'A comment does not open a p-wrap',
73 "<!-- x -->x",
74 "<!-- x --><p>x</p>"
77 'A comment does not close a p-wrap',
78 "x<!-- x -->",
79 "<p>x<!-- x --></p>"
82 'Empty li',
83 "<ul><li></li></ul>",
84 "<ul><li class=\"mw-empty-elt\"></li></ul>"
87 'li with element',
88 "<ul><li><span></span></li></ul>",
89 "<ul><li><span></span></li></ul>"
92 'li with text',
93 "<ul><li>x</li></ul>",
94 "<ul><li>x</li></ul>"
97 'Empty tr',
98 "<table><tbody><tr></tr></tbody></table>",
99 "<table><tbody><tr class=\"mw-empty-elt\"></tr></tbody></table>"
102 'Empty p',
103 "<p>\n</p>",
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>"
127 'Split tag stack 1',
128 "<small>x<div>y</div>z</small>",
129 "<p><small>x</small></p><small><div>y</div></small><p><small>z</small></p>"
132 'Split tag stack 2',
133 "<small><div>y</div>z</small>",
134 "<small><div>y</div></small><p><small>z</small></p>"
137 'Split tag stack 3',
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',
159 'a',
160 '<p>a</p>'
163 '<span> is not a splittable tag, but gets p-wrapped in simple wrapping scenarios',
164 '<span>a</span>',
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>'
219 // New local tests
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)',
227 '<table>x</table>',
228 'x<table></table>'
231 'Blockquote fostering',
232 '<table><blockquote>x</blockquote></table>',
233 '<blockquote><p>x</p></blockquote><table></table>'
236 'Block element fostering',
237 '<table><div>x',
238 '<div>x</div><table></table>'
241 'Formatting element fostering (FIXME: wrap missing)',
242 '<table><b>x',
243 '<b>x</b><table></table>'
246 'AAA clone of p-wrapped element (FIXME: empty b)',
247 '<b>x<p>y</b>z</p>',
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 );
276 $tests = [];
277 foreach ( $files as $file => $fileTests ) {
278 foreach ( $fileTests as $i => $test ) {
279 $tests[] = [ "$file:$i", $test['data'] ];
282 return $tests;
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
290 * @coversNothing
292 public function testHtml5Lib( $desc, $input ) {
293 $r = new MediaWiki\Tidy\RemexDriver( [] );
294 $result = $r->tidy( $input );
295 $this->assertTrue( true, $desc );