MediaWiki
REL1_31
RemexDriverTest.php
Go to the documentation of this file.
1
<?php
2
3
class
RemexDriverTest
extends
MediaWikiTestCase
{
4
static
private
$remexTidyTestData
= [
5
// Tests from Html5Depurate
6
[
7
'Empty string'
,
8
""
,
9
""
10
],
11
[
12
'Simple p-wrap'
,
13
"x"
,
14
"<p>x</p>"
15
],
16
[
17
'No p-wrap of blank node'
,
18
" "
,
19
" "
20
],
21
[
22
'p-wrap terminated by div'
,
23
"x<div></div>"
,
24
"<p>x</p><div></div>"
25
],
26
[
27
'p-wrap not terminated by span'
,
28
"x<span></span>"
,
29
"<p>x<span></span></p>"
30
],
31
[
32
'An element is non-blank and so gets p-wrapped'
,
33
"<span></span>"
,
34
"<p><span></span></p>"
35
],
36
[
37
'The blank flag is set after a block-level element'
,
38
"<div></div> "
,
39
"<div></div> "
40
],
41
[
42
'Blank detection between two block-level elements'
,
43
"<div></div> <div></div>"
,
44
"<div></div> <div></div>"
45
],
46
[
47
'But p-wrapping of non-blank content works after an element'
,
48
"<div></div>x"
,
49
"<div></div><p>x</p>"
50
],
51
[
52
'p-wrapping between two block-level elements'
,
53
"<div></div>x<div></div>"
,
54
"<div></div><p>x</p><div></div>"
55
],
56
[
57
'p-wrap inside blockquote'
,
58
"<blockquote>x</blockquote>"
,
59
"<blockquote><p>x</p></blockquote>"
60
],
61
[
62
'A comment is blank for p-wrapping purposes'
,
63
"<!-- x -->"
,
64
"<!-- x -->"
65
],
66
[
67
'A comment is blank even when a p-wrap was opened by a text node'
,
68
" <!-- x -->"
,
69
" <!-- x -->"
70
],
71
[
72
'A comment does not open a p-wrap'
,
73
"<!-- x -->x"
,
74
"<!-- x --><p>x</p>"
75
],
76
[
77
'A comment does not close a p-wrap'
,
78
"x<!-- x -->"
,
79
"<p>x<!-- x --></p>"
80
],
81
[
82
'Empty li'
,
83
"<ul><li></li></ul>"
,
84
"<ul><li class=\"mw-empty-elt\"></li></ul>"
85
],
86
[
87
'li with element'
,
88
"<ul><li><span></span></li></ul>"
,
89
"<ul><li><span></span></li></ul>"
90
],
91
[
92
'li with text'
,
93
"<ul><li>x</li></ul>"
,
94
"<ul><li>x</li></ul>"
95
],
96
[
97
'Empty tr'
,
98
"<table><tbody><tr></tr></tbody></table>"
,
99
"<table><tbody><tr class=\"mw-empty-elt\"></tr></tbody></table>"
100
],
101
[
102
'Empty p'
,
103
"<p>\n</p>"
,
104
"<p class=\"mw-empty-elt\">\n</p>"
105
],
106
[
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>"
110
],
111
[
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>"
115
],
116
[
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>"
120
],
121
[
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>"
125
],
126
[
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>"
130
],
131
[
132
'Split tag stack 2'
,
133
"<small><div>y</div>z</small>"
,
134
"<small><div>y</div></small><p><small>z</small></p>"
135
],
136
[
137
'Split tag stack 3'
,
138
"<small>x<div>y</div></small>"
,
139
"<p><small>x</small></p><small><div>y</div></small>"
140
],
141
[
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>"
145
],
146
[
147
"Split tag stack regression check 1"
,
148
"x<span><div>y</div></span>"
,
149
"<p>x</p><span><div>y</div></span>"
150
],
151
[
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>"
155
],
156
// Simple tests from pwrap.js
157
[
158
'Simple pwrap test 1'
,
159
'a'
,
160
'<p>a</p>'
161
],
162
[
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>'
166
],
167
[
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>'
171
],
172
[
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>'
176
],
177
// Complex tests from pwrap.js
178
[
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>'
182
],
183
[
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>'
187
],
188
[
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>'
192
],
193
[
194
'Complex pwrap test 4'
,
195
'x<small><div>y</div></small>'
,
196
'<p>x</p><small><div>y</div></small>'
197
],
198
[
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>'
202
],
203
// phpcs:disable Generic.Files.LineLength
204
[
205
'Complex pwrap test 6'
,
206
'<i>a<div>b</div>c<b>d<div>e</div>f</b>g</i>'
,
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
],
210
// phpcs:enable
211
/* FIXME the second <b> causes a stack split which clones the <i> even
212
* though no <p> is actually generated
213
[
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>'
217
],
218
*/
219
// New local tests
220
[
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>'
224
],
225
[
226
'Text node fostering (FIXME: wrap missing)'
,
227
'<table>x</table>'
,
228
'x<table></table>'
229
],
230
[
231
'Blockquote fostering'
,
232
'<table><blockquote>x</blockquote></table>'
,
233
'<blockquote><p>x</p></blockquote><table></table>'
234
],
235
[
236
'Block element fostering'
,
237
'<table><div>x'
,
238
'<div>x</div><table></table>'
239
],
240
[
241
'Formatting element fostering (FIXME: wrap missing)'
,
242
'<table><b>x'
,
243
'<b>x</b><table></table>'
244
],
245
[
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>'
,
249
],
250
[
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>'
254
],
255
[
256
'AAA causes reparent of p-wrapped text node (T178632)'
,
257
'<i><blockquote>x</i></blockquote>'
,
258
'<i></i><blockquote><p><i>x</i></p></blockquote>'
,
259
],
260
[
261
'p-wrap ended by reparenting (T200827)'
,
262
'<i><blockquote><p></i>'
,
263
'<i></i><blockquote><p><i></i></p><p><i></i></p></blockquote>'
,
264
],
265
];
266
267
public
function
provider
() {
268
return
self::$remexTidyTestData
;
269
}
270
278
public
function
testTidy
( $desc,
$input
, $expected ) {
279
$r =
new
MediaWiki\Tidy\RemexDriver
( [] );
280
$result = $r->tidy(
$input
);
281
$this->assertEquals( $expected, $result, $desc );
282
}
283
284
public
function
html5libProvider
() {
285
$files = json_decode( file_get_contents( __DIR__ .
'/html5lib-tests.json'
),
true
);
286
$tests = [];
287
foreach
( $files as $file => $fileTests ) {
288
foreach
( $fileTests as $i => $test ) {
289
$tests[] = [
"$file:$i"
, $test[
'data'
] ];
290
}
291
}
292
return
$tests;
293
}
294
302
public
function
testHtml5Lib
( $desc,
$input
) {
303
$r =
new
MediaWiki\Tidy\RemexDriver
( [] );
304
$result = $r->tidy(
$input
);
305
$this->assertTrue(
true
, $desc );
306
}
307
}
MediaWikiTestCase
Definition
MediaWikiTestCase.php:17
MediaWiki\Tidy\RemexDriver
Definition
RemexDriver.php:11
RemexDriverTest
Definition
RemexDriverTest.php:3
RemexDriverTest\html5libProvider
html5libProvider()
Definition
RemexDriverTest.php:284
RemexDriverTest\testHtml5Lib
testHtml5Lib( $desc, $input)
This is a quick and dirty test to make sure none of the html5lib tests generate exceptions.
Definition
RemexDriverTest.php:302
RemexDriverTest\testTidy
testTidy( $desc, $input, $expected)
provider MediaWiki\Tidy\RemexCompatFormatter MediaWiki\Tidy\RemexCompatMunger MediaWiki\Tidy\RemexDri...
Definition
RemexDriverTest.php:278
RemexDriverTest\$remexTidyTestData
static $remexTidyTestData
Definition
RemexDriverTest.php:4
RemexDriverTest\provider
provider()
Definition
RemexDriverTest.php:267
$input
if(is_array($mode)) switch( $mode) $input
Definition
postprocess-phan.php:145
tests
phpunit
includes
tidy
RemexDriverTest.php
Generated on Mon Nov 25 2024 15:36:37 for MediaWiki by
1.10.0