Debian Codegraph @

vendor/wikimedia/parsoid/tests/parser/tableFixupsParserTests.txt

raw
1 !! Version 2
2 #
3 # This file will hold tests for table fixup dom handlers.
4 # For now, we are only adding tests for unsupported scenarios here.
5 # Eventually, once the monolithic parser test file is split up,
6 # all table fixup tests will move here.
7
8 !! article
9 Main Page
10 !! text
11 blah blah
12 !! endarticle
13
14 !! article
15 Template:1x
16 !! text
17 {{{1}}}
18 !! endarticle
19
20 !! article
21 Template:td_class
22 !! text
23 class="foo"
24 !! endarticle
25
26 !! article
27 Template:td_content
28 !! text
29 | foobar
30 !! endarticle
31
32 !! article
33 Template:td_attrs_and_content
34 !! text
35 {{{1}}} | foobar
36 !! endarticle
37
38 !! article
39 Template:td_attrs_and_content_with_newlines
40 !! text
41 class="foo" | foobar
42 baz
43 !! endarticle
44
45 !! article
46 No Merging Here
47 !! text
48 Dummy article to suppress redlinks in tests
49 !! end
50
51 ## FIXME: This is fixable -- if we relax some restrictions from older code
52 !! test
53 Unsupported scenario: Cell combining with captions
54 !! options
55 parsoid=wt2html
56 !! wikitext
57 {|
58 |+class="foo"{{1x|1={{!}}some caption}}
59 |bar
60 |}
61 !! html/php
62 <table>
63 <caption class="foo">some caption
64 </caption>
65 <tbody><tr>
66 <td>bar
67 </td></tr></tbody></table>
68 !! html/parsoid
69 <table>
70 <caption>class="foo"</caption><tbody about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1","named":true}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"{{!}}some caption"}},"i":0}},"\n|bar\n"]}'><tr><td>some caption</td>
71 <td>bar</td></tr>
72 </tbody></table>
73 !! end
74
75 !! test
76 Unsupported scenario: Templated cell merge with another templated cell
77 !! options
78 parsoid=wt2html
79 !! wikitext
80 {|
81 |{{1x|1=class="foo"}}{{1x|1={{!}}foo}}
82 |}
83 !! html/php
84 <table>
85 <tbody><tr>
86 <td class="foo">foo
87 </td></tr></tbody></table>
88 !! html/parsoid
89 <table>
90 <tbody><tr><td about="#mwt2" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1","named":true}]]}' data-mw='{"parts":["|{{1x|1=class=\"foo\"}}",{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"{{!}}foo"}},"i":0}}]}'>foo</td></tr>
91 </tbody></table>
92 !! end
93
94 ## FIXME: This is fixable -- if we relax some restrictions from older code
95 !! test
96 Unsupported scenario: Templated cell with attributes merging with previous cell
97 !! options
98 parsoid=wt2html
99 !! wikitext
100 {|
101 |class="foo"{{1x|1={{!}}title="foo"{{!}}foo}}
102 |}
103 !! html/php
104 <table>
105 <tbody><tr>
106 <td class="foo">title="foo"|foo
107 </td></tr></tbody></table>
108 !! html/parsoid
109 <table>
110 <tbody><tr><td about="#mwt1" typeof="mw:Transclusion" class="foo" data-parsoid='{"pi":[[{"k":"1","named":true}]]}' data-mw='{"parts":["|class=\"foo\"",{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"{{!}}title=\"foo\"{{!}}foo"}},"i":0}}]}'>title="foo"</td><td about="#mwt1">foo</td></tr>
111 </tbody></table>
112 !! end
113
114 !! test
115 Unsupported scenario: Templated cell merging with previous cell with attributes
116 !! options
117 parsoid=wt2html
118 !! wikitext
119 {|
120 |class="foo"|title="foo"{{1x|1={{!}}foo}}
121 |}
122 !! html/php
123 <table>
124 <tbody><tr>
125 <td class="foo">title="foo"|foo
126 </td></tr></tbody></table>
127 !! html/parsoid
128 <table>
129 <tbody><tr><td about="#mwt1" typeof="mw:Transclusion" class="foo" data-parsoid='{"pi":[[{"k":"1","named":true}]]}' data-mw='{"parts":["|class=\"foo\"|title=\"foo\"",{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"{{!}}foo"}},"i":0}}]}'>title="foo"|foo</td></tr>
130 </tbody></table>
131 !! end
132
133 !! test
134 Unsupported scenario: Templated cell not merging with previous cell with attributes and trailing vertical bar
135 !! options
136 parsoid=wt2html
137 !! wikitext
138 {|
139 |class="foo"|content|{{1x|1={{!}}foo}}
140 |}
141 !! html/php
142 <table>
143 <tbody><tr>
144 <td class="foo">content</td>
145 <td>foo
146 </td></tr></tbody></table>
147 !! html/parsoid
148 <table>
149 <tbody><tr><td about="#mwt1" typeof="mw:Transclusion" class="foo" data-parsoid='{"pi":[[{"k":"1","named":true}]]}' data-mw='{"parts":["|class=\"foo\"|content|",{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"{{!}}foo"}},"i":0}}]}'>content</td><td about="#mwt1">foo</td></tr>
150 </tbody></table>
151 !! end
152
153 !! test
154 Unsupported scenario: Templated cell not merging with previous cell and trailing vertical bar
155 !! options
156 parsoid=wt2html
157 !! wikitext
158 {|
159 | [[Main Page]] content|{{1x|1={{!}}foo}}
160 |}
161 !! html/php
162 <table>
163 <tbody><tr>
164 <td><a href="/wiki/Main_Page" title="Main Page">Main Page</a> content</td>
165 <td>foo
166 </td></tr></tbody></table>
167 !! html/parsoid
168 <table>
169 <tbody><tr>
170 <td><a rel="mw:WikiLink" href="./Main_Page" title="Main Page">Main Page</a> content</td>
171 <td typeof="mw:Transclusion" data-mw='{"parts":["|", {"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"{{!}}foo"}},"i":0}}]}'>foo</td>
172 </tr>
173 </tbody></table>
174 !! end
175
176 !! test
177 Unsupported scenario: Templated cell not merging with previous cell and trailing vertical bar, attributes and row syntax
178 !! options
179 parsoid=wt2html
180 !! wikitext
181 {|
182 |one||[[two]]||three|{{1x|{{!}}four}}
183 |}
184 !! html/php
185 <table>
186 <tbody><tr>
187 <td>one</td>
188 <td><a href="/index.php?title=Two&amp;action=edit&amp;redlink=1" class="new" title="Two (page does not exist)">two</a></td>
189 <td>three</td>
190 <td>four
191 </td></tr></tbody></table>
192 !! html/parsoid
193 <table>
194 <tbody><tr><td>one</td><td data-parsoid='{"stx":"row"}'><a rel="mw:WikiLink" href="./Two?action=edit&amp;redlink=1" title="Two" class="new" typeof="mw:LocalizedAttrs" data-mw-i18n='{"title":{"lang":"x-page","key":"red-link-title","params":["Two"]}}'>two</a></td><td data-parsoid='{"stx":"row"}'>three</td><td about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"{{!}}four"}},"i":0}}]}'>four</td></tr>
195 </tbody></table>
196 !! end
197
198 !! test
199 Merge tds (T52603)
200 !! wikitext
201 {|
202 |{{1x|{{!}} foo}}
203 |}
204 !! html/php
205 <table>
206 <tbody><tr>
207 <td>foo
208 </td></tr></tbody></table>
209 !! html/parsoid
210 <table><tbody>
211 <tr><td about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":["|",{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"{{!}} foo"}},"i":0}}]}'> foo</td></tr>
212 </tbody></table>
213 !! end
214
215 !! test
216 Merge tds in nested transclusion content (T52603)
217 !! wikitext
218 {{1x|<div>}}
219 {|
220 |{{1x|{{!}} foo}}
221 |}
222 {{1x|</div>}}
223 !! html/php
224 <div>
225 <table>
226 <tbody><tr>
227 <td>foo
228 </td></tr></tbody></table>
229 </div>
230 !! html/parsoid
231 <div about="#mwt1" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"&lt;div>"}},"i":0}},"\n{|\n|",{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"{{!}} foo"}},"i":1}},"\n|}\n",{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"&lt;/div>"}},"i":2}}]}'>
232 <table>
233 <tbody><tr><td>foo</td></tr>
234 </tbody></table>
235 </div>
236 !! end
237
238 !! test
239 Table cell attributes and content from multiple templates
240 !! wikitext
241 {|
242 |-
243 | {{td_class}} {{td_attrs_and_content|1=style='border:1px solid blue'}} baz
244 |}
245 !! html/php
246 <table>
247
248 <tbody><tr>
249 <td class="foo" style="border:1px solid blue">foobar baz
250 </td></tr></tbody></table>
251 !! html/parsoid
252 <table>
253 <tbody><tr data-parsoid='{"startTagSrc":"|-"}'>
254 <td class="foo" style="border:1px solid blue" typeof="mw:Transclusion" about="#mwt2" data-parsoid='{"pi":[[],[{"k":"1","named":true}]]}' data-mw='{"parts":["| ",{"template":{"target":{"wt":"td_class","href":"./Template:Td_class"},"params":{},"i":0}}," ",{"template":{"target":{"wt":"td_attrs_and_content","href":"./Template:Td_attrs_and_content"},"params":{"1":{"wt":"style=&apos;border:1px solid blue&apos;"}},"i":1}}," baz"]}'>foobar baz</td></tr>
255 </tbody></table>
256 !! end
257
258 !! test
259 Table cell attribute merging edge cases
260 !! config
261 wgParserEnableLegacyMediaDOM=false
262 !! wikitext
263 {|
264 | {{td_attrs_and_content|1=<div>foo</div> class="foo"}} baz
265 |-
266 |{{td_attrs_and_content|1=[[No Merging Here]] class="foo"}} baz
267 |-
268 |{{td_attrs_and_content|1=[[File:Foo.jpg]] class="foo"}} baz
269 |}
270 !! html/php
271 <table>
272 <tbody><tr>
273 <td class="foo">foobar baz
274 </td></tr>
275 <tr>
276 <td><a href="/wiki/No_Merging_Here" title="No Merging Here">No Merging Here</a> class="foo" | foobar baz
277 </td></tr>
278 <tr>
279 <td><span class="mw-default-size" typeof="mw:Error mw:File"><a href="/index.php?title=Special:Upload&amp;wpDestFile=Foo.jpg" class="new" title="File:Foo.jpg"><span class="mw-file-element mw-broken-media">File:Foo.jpg</span></a></span> class="foo" | foobar baz
280 </td></tr></tbody></table>
281 !! html/parsoid
282 <table>
283 <tbody><tr data-parsoid='{"autoInsertedStart":true}'><td class="foo" typeof="mw:Transclusion" about="#mwt1" data-parsoid='{"pi":[[{"k":"1","named":true}]]}' data-mw='{"parts":["| ",{"template":{"target":{"wt":"td_attrs_and_content","href":"./Template:Td_attrs_and_content"},"params":{"1":{"wt":"&lt;div>foo&lt;/div> class=\"foo\""}},"i":0}}," baz"]}'>foobar baz</td></tr>
284 <tr data-parsoid='{"startTagSrc":"|-"}'>
285 <td><a rel="mw:WikiLink" href="./No_Merging_Here" title="No Merging Here" about="#mwt2" typeof="mw:Transclusion" data-parsoid='{"stx":"simple","a":{"href":"./No_Merging_Here"},"sa":{"href":"No Merging Here"},"pi":[[{"k":"1","named":true}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"td_attrs_and_content","href":"./Template:Td_attrs_and_content"},"params":{"1":{"wt":"[[No Merging Here]] class=\"foo\""}},"i":0}}]}'>No Merging Here</a><span about="#mwt2"> class="foo" | foobar</span> baz</td></tr>
286 <tr data-parsoid='{"startTagSrc":"|-"}'>
287 <td><span class="mw-default-size" typeof="mw:Transclusion mw:Error mw:File" about="#mwt3" data-parsoid='{"optList":[],"pi":[[{"k":"1","named":true}]]}' data-mw='{"errors":[{"key":"apierror-filedoesnotexist","message":"This image does not exist."}],"parts":[{"template":{"target":{"wt":"td_attrs_and_content","href":"./Template:Td_attrs_and_content"},"params":{"1":{"wt":"[[File:Foo.jpg]] class=\"foo\""}},"i":0}}]}'><a href="./Special:FilePath/Foo.jpg"><span class="mw-file-element mw-broken-media" resource="./File:Foo.jpg">File:Foo.jpg</span></a></span><span about="#mwt3"> class="foo" | foobar</span> baz</td></tr>
288 </tbody></table>
289 !! end
290
291 !! test
292 Fixup of interrupted table-cell parsing because of multi-line transclusion
293 !! wikitext
294 {|
295 ! class="c1" |Col 1.1!! class="c2" |{{1x|
296 1=Col 1.2}}!! class="c3" |Col 1.3!! class="c4" |Col 1.4
297 ! class="d1" |Col 2.1!! class="d2" |{{1x|
298 1=Col 2.2}}!! class="d3" |Col 2.3! abcd!! class="d4" |Col 2.4
299 | class="e1" |Col 3.1|| class="e2" |{{1x|
300 1=Col 3.2}}|| class="e3" |Col 3.3| abcd|| class="e4" |Col 3.4
301 |}
302 !! html/php
303 <table>
304 <tbody><tr>
305 <th class="c1">Col 1.1</th>
306 <th class="c2">Col 1.2</th>
307 <th class="c3">Col 1.3</th>
308 <th class="c4">Col 1.4
309 </th>
310 <th class="d1">Col 2.1</th>
311 <th class="d2">Col 2.2</th>
312 <th class="d3">Col 2.3! abcd</th>
313 <th class="d4">Col 2.4
314 </th>
315 <td class="e1">Col 3.1</td>
316 <td class="e2">Col 3.2</td>
317 <td class="e3">Col 3.3| abcd</td>
318 <td class="e4">Col 3.4
319 </td></tr></tbody></table>
320 !! html/parsoid
321 <table>
322 <tbody><tr><th class="c1">Col 1.1</th><th class="c2" data-parsoid='{"stx":"row"}'><span about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1","named":true,"spc":["\n","","",""]}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"Col 1.2"}},"i":0}}]}'>Col 1.2</span></th><th class="c3" data-parsoid='{"stx":"row"}'>Col 1.3</th><th class="c4" data-parsoid='{"stx":"row"}'>Col 1.4</th>
323 <th class="d1">Col 2.1</th><th class="d2" data-parsoid='{"stx":"row"}'><span about="#mwt2" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1","named":true,"spc":["\n","","",""]}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"Col 2.2"}},"i":0}}]}'>Col 2.2</span></th><th class="d3" data-parsoid='{"stx":"row"}'>Col 2.3! abcd</th><th class="d4" data-parsoid='{"stx":"row"}'>Col 2.4</th>
324 <td class="e1">Col 3.1</td><td class="e2" data-parsoid='{"stx":"row"}'><span about="#mwt3" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1","named":true,"spc":["\n","","",""]}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"1x","href":"./Template:1x"},"params":{"1":{"wt":"Col 3.2"}},"i":0}}]}'>Col 3.2</span></td><td class="e3" data-parsoid='{"stx":"row"}'>Col 3.3| abcd</td><td class="e4" data-parsoid='{"stx":"row"}'>Col 3.4</td></tr>
325 </tbody></table>
326 !! end
327
328 !! test
329 Ensure newlines in collected attribute doesn't trip up reparsing
330 !! wikitext
331 {|
332 |rowspan="1" {{td_attrs_and_content_with_newlines}}
333 |}
334 !! html/php
335 <table>
336 <tbody><tr>
337 <td rowspan="1" class="foo">foobar
338 <pre> baz
339 </pre>
340 </td></tr></tbody></table>
341 !! html/parsoid
342 <table>
343 <tbody><tr><td rowspan="1" class="foo" typeof="mw:Transclusion" about="#mwt1" data-parsoid='{"pi":[[]]}' data-mw='{"parts":["|rowspan=\"1\" ",{"template":{"target":{"wt":"td_attrs_and_content_with_newlines","href":"./Template:Td_attrs_and_content_with_newlines"},"params":{},"i":0}}]}'>foobar
344 <pre about="#mwt1"> baz </pre></td></tr>
345 </tbody></table>
346 !! end
347
348 !! test
349 Ensure a cell with newlines doesn't combine with following cell
350 !! wikitext
351 {|
352 |-
353 | combined-and-lost {{td_content|}}
354 |-
355 |not combined
356 {{td_content|}}
357 |}
358 !! html/php
359 <table>
360
361 <tbody><tr>
362 <td>foobar
363 </td></tr>
364 <tr>
365 <td>not combined
366 </td>
367 <td>foobar
368 </td></tr></tbody></table>
369 !! html/parsoid
370 <table>
371 <tbody><tr data-parsoid='{"startTagSrc":"|-"}'>
372 <td about="#mwt1" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1"}]]}' data-mw='{"parts":["| combined-and-lost ",{"template":{"target":{"wt":"td_content","href":"./Template:Td_content"},"params":{"1":{"wt":""}},"i":0}}]}'>foobar</td></tr>
373 <tr data-parsoid='{"startTagSrc":"|-"}'>
374 <td>not combined
375 </td><td about="#mwt2" typeof="mw:Transclusion" data-parsoid='{"pi":[[{"k":"1"}]]}' data-mw='{"parts":[{"template":{"target":{"wt":"td_content","href":"./Template:Td_content"},"params":{"1":{"wt":""}},"i":0}}]}'>foobar</td></tr>
376 </tbody></table>
377 !! end
378
379 !! test
380 Table cell attributes and nested transclusions
381 !! wikitext
382 {|
383 | '''{{td_attrs_and_content|1=style='border:1px solid blue;'}}'''
384 |}
385 !! html/php
386 <table>
387 <tbody><tr>
388 <td>foobar<b></b>
389 </td></tr></tbody></table>
390 !! html/parsoid
391 <table>
392 <tbody><tr><td style="border:1px solid blue;" typeof="mw:Transclusion" about="#mwt1" data-mw='{"parts":["| &apos;&apos;&apos;",{"template":{"target":{"wt":"td_attrs_and_content","href":"./Template:Td_attrs_and_content"},"params":{"1":{"wt":"style=&apos;border:1px solid blue;&apos;"}},"i":0}},"&apos;&apos;&apos;"]}'>foobar</td></tr>
393 </tbody></table>
394 !! end
395
396 !! test
397 T331486: Newline entities should be properly handled while fixing up table cells
398 !! wikitext
399 {|
400 |{{td_attrs_and_content|1=title="a&#10;b" class="xyz"}}
401 |}
402 !! html/php
403 <table>
404 <tbody><tr>
405 <td title="a&#10;b" class="xyz">foobar
406 </td></tr></tbody></table>
407 !! html/parsoid
408 <table>
409 <tbody><tr><td title="a
410 b" class="xyz" typeof="mw:Transclusion" about="#mwt1" data-mw='{"parts":["|",{"template":{"target":{"wt":"td_attrs_and_content","href":"./Template:Td_attrs_and_content"},"params":{"1":{"wt":"title=\"a&amp;#10;b\" class=\"xyz\""}},"i":0}}]}'>foobar</td></tr>
411 </tbody></table>
412 !! end
413
414 !! article
415 Template:tdfoo
416 !! text
417 || y
418 !! endarticle
419
420 # This test currently fails in Parsoid
421 !! test
422 Ensure td-cell-type is switched to th when the first cell in a row is a <th>
423 !! wikitext
424 {|
425 !a||b
426 !c{{tdfoo}}
427 |}
428 !! html/php
429 <table>
430 <tbody><tr>
431 <th>a</th>
432 <th>b
433 </th>
434 <th>c</th>
435 <th>y
436 </th></tr></tbody></table>
437 !! html/parsoid
438 <table>
439 <tbody><tr>
440 <th>a</th><th>b</tb>
441 <th>c</th><th about="#mwt2" typeof="mw:Transclusion" data-mw='{"parts":[{"template":{"target":{"wt":"tdfoo","href":"./Template:Tdfoo"},"params":{},"i":0}}]}'>y</th></tr>
442 </tbody></table>
443 !! end