xref: /dokuwiki/_test/tests/Parsing/ParserMode/TableTest.php (revision 504c13e8df88563c11b3720b317991bc38835a35)
1<?php
2
3namespace dokuwiki\test\Parsing\ParserMode;
4
5use dokuwiki\Parsing\ParserMode\Eol;
6use dokuwiki\Parsing\ParserMode\Footnote;
7use dokuwiki\Parsing\ParserMode\Strong;
8use dokuwiki\Parsing\ParserMode\Linebreak;
9use dokuwiki\Parsing\ParserMode\Table;
10use dokuwiki\Parsing\ParserMode\Unformatted;
11
12class TableTest extends ParserTestBase
13{
14
15    function testTable() {
16        $this->P->addMode('table',new Table());
17        $this->P->parse('
18abc
19| Row 0 Col 1    | Row 0 Col 2     | Row 0 Col 3        |
20| Row 1 Col 1    | Row 1 Col 2     | Row 1 Col 3        |
21def');
22        $calls = [
23            ['document_start',[]],
24            ['p_open',[]],
25            ['cdata',["\n\nabc"]],
26            ['p_close',[]],
27            ['table_open',[3, 2, 6]],
28            ['tablerow_open',[]],
29            ['tablecell_open',[1,'left',1]],
30            ['cdata',[' Row 0 Col 1    ']],
31            ['tablecell_close',[]],
32            ['tablecell_open',[1,'left',1]],
33            ['cdata',[' Row 0 Col 2     ']],
34            ['tablecell_close',[]],
35            ['tablecell_open',[1,'left',1]],
36            ['cdata',[' Row 0 Col 3        ']],
37            ['tablecell_close',[]],
38            ['tablerow_close',[]],
39            ['tablerow_open',[]],
40            ['tablecell_open',[1,'left',1]],
41            ['cdata',[' Row 1 Col 1    ']],
42            ['tablecell_close',[]],
43            ['tablecell_open',[1,'left',1]],
44            ['cdata',[' Row 1 Col 2     ']],
45            ['tablecell_close',[]],
46            ['tablecell_open',[1,'left',1]],
47            ['cdata',[' Row 1 Col 3        ']],
48            ['tablecell_close',[]],
49            ['tablerow_close',[]],
50            ['table_close',[121]],
51            ['p_open',[]],
52            ['cdata',['def']],
53            ['p_close',[]],
54            ['document_end',[]],
55        ];
56        $this->assertCalls($calls, $this->H->calls);
57    }
58
59    function testTableWinEOL() {
60        $this->P->addMode('table',new Table());
61        $this->P->parse("\r\nabc\r\n| Row 0 Col 1    | Row 0 Col 2     | Row 0 Col 3        |\r\n| Row 1 Col 1    | Row 1 Col 2     | Row 1 Col 3        |\r\ndef");
62        $calls = [
63            ['document_start',[]],
64            ['p_open',[]],
65            ['cdata',["\n\nabc"]],
66            ['p_close',[]],
67            ['table_open',[3, 2, 6]],
68            ['tablerow_open',[]],
69            ['tablecell_open',[1,'left',1]],
70            ['cdata',[' Row 0 Col 1    ']],
71            ['tablecell_close',[]],
72            ['tablecell_open',[1,'left',1]],
73            ['cdata',[' Row 0 Col 2     ']],
74            ['tablecell_close',[]],
75            ['tablecell_open',[1,'left',1]],
76            ['cdata',[' Row 0 Col 3        ']],
77            ['tablecell_close',[]],
78            ['tablerow_close',[]],
79            ['tablerow_open',[]],
80            ['tablecell_open',[1,'left',1]],
81            ['cdata',[' Row 1 Col 1    ']],
82            ['tablecell_close',[]],
83            ['tablecell_open',[1,'left',1]],
84            ['cdata',[' Row 1 Col 2     ']],
85            ['tablecell_close',[]],
86            ['tablecell_open',[1,'left',1]],
87            ['cdata',[' Row 1 Col 3        ']],
88            ['tablecell_close',[]],
89            ['tablerow_close',[]],
90            ['table_close',[121]],
91            ['p_open',[]],
92            ['cdata',['def']],
93            ['p_close',[]],
94            ['document_end',[]],
95        ];
96        $this->assertCalls($calls, $this->H->calls);
97    }
98
99    function testEmptyTable() {
100        $this->P->addMode('table',new Table());
101        $this->P->parse('
102abc
103|
104def');
105
106        $calls = [
107            ['document_start',[]],
108            ['p_open',[]],
109            ['cdata',["\n\nabc"]],
110            ['p_close',[]],
111            ['table_open',[0, 1, 6]],
112            ['tablerow_open',[]],
113            ['tablerow_close',[]],
114            ['table_close',[7]],
115            ['p_open',[]],
116            ['cdata',['def']],
117            ['p_close',[]],
118            ['document_end',[]],
119        ];
120
121        $this->assertCalls($calls, $this->H->calls);
122    }
123
124    function testTableHeaders() {
125        $this->P->addMode('table',new Table());
126        $this->P->parse('
127abc
128^ X | Y ^ Z |
129def');
130
131        $calls = [
132            ['document_start',[]],
133            ['p_open',[]],
134            ['cdata',["\n\nabc"]],
135            ['p_close',[]],
136            ['table_open',[3, 1, 6]],
137            ['tablerow_open',[]],
138            ['tableheader_open',[1,null,1]],
139            ['cdata',[' X ']],
140            ['tableheader_close',[]],
141            ['tablecell_open',[1,null,1]],
142            ['cdata',[' Y ']],
143            ['tablecell_close',[]],
144            ['tableheader_open',[1,null,1]],
145            ['cdata',[' Z ']],
146            ['tableheader_close',[]],
147            ['tablerow_close',[]],
148            ['table_close',[19]],
149            ['p_open',[]],
150            ['cdata',['def']],
151            ['p_close',[]],
152            ['document_end',[]],
153        ];
154
155        $this->assertCalls($calls, $this->H->calls);
156
157    }
158
159    function testTableHead() {
160        $this->P->addMode('table',new Table());
161        $this->P->parse('
162abc
163^ X ^ Y ^ Z ^
164| x | y | z |
165def');
166
167        $calls = [
168            ['document_start',[]],
169            ['p_open',[]],
170            ['cdata',["\n\nabc"]],
171            ['p_close',[]],
172            ['table_open',[3, 2, 6]],
173            ['tablethead_open',[]],
174            ['tablerow_open',[]],
175            ['tableheader_open',[1,null,1]],
176            ['cdata',[' X ']],
177            ['tableheader_close',[]],
178            ['tableheader_open',[1,null,1]],
179            ['cdata',[' Y ']],
180            ['tableheader_close',[]],
181            ['tableheader_open',[1,null,1]],
182            ['cdata',[' Z ']],
183            ['tableheader_close',[]],
184            ['tablerow_close',[]],
185            ['tablethead_close',[]],
186            ['tablerow_open',[]],
187            ['tablecell_open',[1,null,1]],
188            ['cdata',[' x ']],
189            ['tablecell_close',[]],
190            ['tablecell_open',[1,null,1]],
191            ['cdata',[' y ']],
192            ['tablecell_close',[]],
193            ['tablecell_open',[1,null,1]],
194            ['cdata',[' z ']],
195            ['tablecell_close',[]],
196            ['tablerow_close',[]],
197            ['table_close',[33]],
198            ['p_open',[]],
199            ['cdata',['def']],
200            ['p_close',[]],
201            ['document_end',[]],
202        ];
203
204        $this->assertCalls($calls, $this->H->calls);
205
206    }
207
208    function testTableHeadOneRowTable() {
209        $this->P->addMode('table',new Table());
210        $this->P->parse('
211abc
212^ X ^ Y ^ Z ^
213def');
214
215        $calls = [
216            ['document_start',[]],
217            ['p_open',[]],
218            ['cdata',["\n\nabc"]],
219            ['p_close',[]],
220            ['table_open',[3, 1, 6]],
221            ['tablerow_open',[]],
222            ['tableheader_open',[1,null,1]],
223            ['cdata',[' X ']],
224            ['tableheader_close',[]],
225            ['tableheader_open',[1,null,1]],
226            ['cdata',[' Y ']],
227            ['tableheader_close',[]],
228            ['tableheader_open',[1,null,1]],
229            ['cdata',[' Z ']],
230            ['tableheader_close',[]],
231            ['tablerow_close',[]],
232            ['table_close',[19]],
233            ['p_open',[]],
234            ['cdata',['def']],
235            ['p_close',[]],
236            ['document_end',[]],
237        ];
238
239        $this->assertCalls($calls, $this->H->calls);
240
241    }
242
243    function testTableHeadMultiline() {
244        $this->P->addMode('table',new Table());
245        $this->P->parse('
246abc
247^ X1 ^ Y1 ^ Z1 ^
248^ X2 ^ Y2 ^ Z2 ^
249| A | B | C |
250def');
251
252        $calls = [
253            ['document_start',[]],
254            ['p_open',[]],
255            ['cdata',["\n\nabc"]],
256            ['p_close',[]],
257            ['table_open',[3, 3, 6]],
258            ['tablethead_open',[]],
259            ['tablerow_open',[]],
260            ['tableheader_open',[1,null,1]],
261            ['cdata',[' X1 ']],
262            ['tableheader_close',[]],
263            ['tableheader_open',[1,null,1]],
264            ['cdata',[' Y1 ']],
265            ['tableheader_close',[]],
266            ['tableheader_open',[1,null,1]],
267            ['cdata',[' Z1 ']],
268            ['tableheader_close',[]],
269            ['tablerow_close',[]],
270            ['tablerow_open',[]],
271            ['tableheader_open',[1,null,1]],
272            ['cdata',[' X2 ']],
273            ['tableheader_close',[]],
274            ['tableheader_open',[1,null,1]],
275            ['cdata',[' Y2 ']],
276            ['tableheader_close',[]],
277            ['tableheader_open',[1,null,1]],
278            ['cdata',[' Z2 ']],
279            ['tableheader_close',[]],
280            ['tablerow_close',[]],
281            ['tablethead_close',[]],
282            ['tablerow_open',[]],
283            ['tablecell_open',[1,null,1]],
284            ['cdata',[' A ']],
285            ['tablecell_close',[]],
286            ['tablecell_open',[1,null,1]],
287            ['cdata',[' B ']],
288            ['tablecell_close',[]],
289            ['tablecell_open',[1,null,1]],
290            ['cdata',[' C ']],
291            ['tablecell_close',[]],
292            ['tablerow_close',[]],
293            ['table_close',[53]],
294            ['p_open',[]],
295            ['cdata',['def']],
296            ['p_close',[]],
297            ['document_end',[]],
298        ];
299
300        $this->assertCalls($calls, $this->H->calls);
301
302    }
303
304    function testCellAlignment() {
305        $this->P->addMode('table',new Table());
306        $this->P->parse('
307abc
308|  X | Y  ^  Z  |
309def');
310
311        $calls = [
312            ['document_start',[]],
313            ['p_open',[]],
314            ['cdata',["\n\nabc"]],
315            ['p_close',[]],
316            ['table_open',[3, 1, 6]],
317            ['tablerow_open',[]],
318            ['tablecell_open',[1,'right',1]],
319            ['cdata',['  X ']],
320            ['tablecell_close',[]],
321            ['tablecell_open',[1,'left',1]],
322            ['cdata',[' Y  ']],
323            ['tablecell_close',[]],
324            ['tableheader_open',[1,'center',1]],
325            ['cdata',['  Z  ']],
326            ['tableheader_close',[]],
327            ['tablerow_close',[]],
328            ['table_close',[23]],
329            ['p_open',[]],
330            ['cdata',['def']],
331            ['p_close',[]],
332            ['document_end',[]],
333        ];
334
335        $this->assertCalls($calls, $this->H->calls);
336    }
337
338    function testCellSpan() {
339        $this->P->addMode('table',new Table());
340        $this->P->parse('
341abc
342|  d || e |
343| f ^ ^|
344||||
345def');
346
347        $calls = [
348            ['document_start',[]],
349            ['p_open',[]],
350            ['cdata',["\n\nabc"]],
351            ['p_close',[]],
352            ['table_open',[3, 3, 6]],
353            ['tablerow_open',[]],
354            ['tablecell_open',[2,'right',1]],
355            ['cdata',['  d ']],
356            ['tablecell_close',[]],
357            ['tablecell_open',[1,null,1]],
358            ['cdata',[' e ']],
359            ['tablecell_close',[]],
360            ['tablerow_close',[]],
361            ['tablerow_open',[]],
362            ['tablecell_open',[1,null,1]],
363            ['cdata',[' f ']],
364            ['tablecell_close',[]],
365            ['tableheader_open',[2,null,1]],
366            ['cdata',[' ']],
367            ['tableheader_close',[]],
368            ['tablerow_close',[]],
369            ['tablerow_open',[]],
370            ['tablerow_close',[]],
371            ['table_close',[31]],
372            ['p_open',[]],
373            ['cdata',['def']],
374            ['p_close',[]],
375            ['document_end',[]],
376        ];
377        $this->assertCalls($calls, $this->H->calls);
378    }
379
380    function testCellRowSpan() {
381        $this->P->addMode('table',new Table());
382        $this->P->parse('
383abc
384| a |  c:::||
385|:::^ d  | e|
386|b  ^  ::: |:::f|
387def');
388
389        $calls = [
390            ['document_start',[]],
391            ['p_open',[]],
392            ['cdata',["\n\nabc"]],
393            ['p_close',[]],
394            ['table_open',[3, 3, 6]],
395            ['tablerow_open',[]],
396            ['tablecell_open',[1,null,2]],
397            ['cdata',[' a ']],
398            ['tablecell_close',[]],
399            ['tablecell_open',[2,'right',1]],
400            ['cdata',['  c:::']],
401            ['tablecell_close',[]],
402            ['tablerow_close',[]],
403            ['tablerow_open',[]],
404            ['tableheader_open',[1,'left',2]],
405            ['cdata',[' d  ']],
406            ['tableheader_close',[]],
407            ['tablecell_open',[1,null,1]],
408            ['cdata',[' e']],
409            ['tablecell_close',[]],
410            ['tablerow_close',[]],
411            ['tablerow_open',[]],
412            ['tablecell_open',[1,'left',1]],
413            ['cdata',['b  ']],
414            ['tablecell_close',[]],
415            ['tablecell_open',[1,null,1]],
416            ['cdata',[':::f']],
417            ['tablecell_close',[]],
418            ['tablerow_close',[]],
419            ['table_close',[51]],
420            ['p_open',[]],
421            ['cdata',['def']],
422            ['p_close',[]],
423            ['document_end',[]],
424        ];
425        $this->assertCalls($calls, $this->H->calls);
426    }
427
428    function testCellRowSpanFirstRow() {
429        $this->P->addMode('table',new Table());
430        $this->P->parse('
431abc
432|::: ^  d:::^:::|  :::  |
433| b ^ e  | | ::: |
434|c  ^  ::: | |:::|
435def');
436
437        $calls = [
438            ['document_start',[]],
439            ['p_open',[]],
440            ['cdata',["\n\nabc"]],
441            ['p_close',[]],
442            ['table_open',[4, 3, 6]],
443            ['tablerow_open',[]],
444            ['tablecell_open',[1,null,1]],
445            ['cdata',['']],
446            ['tablecell_close',[]],
447            ['tableheader_open',[1,'right',1]],
448            ['cdata',['  d:::']],
449            ['tableheader_close',[]],
450            ['tableheader_open',[1,null,1]],
451            ['cdata',['']],
452            ['tableheader_close',[]],
453            ['tablecell_open',[1,null,3]],
454            ['cdata',['']],
455            ['tablecell_close',[]],
456            ['tablerow_close',[]],
457            ['tablerow_open',[]],
458            ['tablecell_open',[1,null,1]],
459            ['cdata',[' b ']],
460            ['tablecell_close',[]],
461            ['tableheader_open',[1,'left',2]],
462            ['cdata',[' e  ']],
463            ['tableheader_close',[]],
464            ['tablecell_open',[1,null,1]],
465            ['cdata',[' ']],
466            ['tablecell_close',[]],
467            ['tablerow_close',[]],
468            ['tablerow_open',[]],
469            ['tablecell_open',[1,'left',1]],
470            ['cdata',['c  ']],
471            ['tablecell_close',[]],
472            ['tablecell_open',[1,null,1]],
473            ['cdata',[' ']],
474            ['tablecell_close',[]],
475            ['tablerow_close',[]],
476
477            ['table_close',[69]],
478            ['p_open',[]],
479            ['cdata',['def']],
480            ['p_close',[]],
481            ['document_end',[]],
482        ];
483        $this->assertCalls($calls, $this->H->calls);
484    }
485
486    function testRowSpanTableHead() {
487        $this->P->addMode('table',new Table());
488        $this->P->parse('
489abc
490^ X1 ^ Y1 ^ Z1 ^
491^ X2 ^ ::: ^ Z2 ^
492| A3 | B3 | C3 |
493def');
494
495        $calls = [
496            ['document_start',[]],
497            ['p_open',[]],
498            ['cdata',["\n\nabc"]],
499            ['p_close',[]],
500            ['table_open',[3, 3, 6]],
501            ['tablethead_open',[]],
502            ['tablerow_open',[]],
503            ['tableheader_open',[1,null,1]],
504            ['cdata',[' X1 ']],
505            ['tableheader_close',[]],
506            ['tableheader_open',[1,null,2]],
507            ['cdata',[' Y1 ']],
508            ['tableheader_close',[]],
509            ['tableheader_open',[1,null,1]],
510            ['cdata',[' Z1 ']],
511            ['tableheader_close',[]],
512            ['tablerow_close',[]],
513            ['tablerow_open',[]],
514            ['tableheader_open',[1,null,1]],
515            ['cdata',[' X2 ']],
516            ['tableheader_close',[]],
517            ['tableheader_open',[1,null,1]],
518            ['cdata',[' Z2 ']],
519            ['tableheader_close',[]],
520            ['tablerow_close',[]],
521            ['tablethead_close',[]],
522            ['tablerow_open',[]],
523            ['tablecell_open',[1,null,1]],
524            ['cdata',[' A3 ']],
525            ['tablecell_close',[]],
526            ['tablecell_open',[1,null,1]],
527            ['cdata',[' B3 ']],
528            ['tablecell_close',[]],
529            ['tablecell_open',[1,null,1]],
530            ['cdata',[' C3 ']],
531            ['tablecell_close',[]],
532            ['tablerow_close',[]],
533            ['table_close',[57]],
534            ['p_open',[]],
535            ['cdata',['def']],
536            ['p_close',[]],
537            ['document_end',[]],
538        ];
539
540        $this->assertCalls($calls, $this->H->calls);
541
542    }
543
544    function testRowSpanAcrossTableHeadBoundary() {
545        $this->P->addMode('table',new Table());
546        $this->P->parse('
547abc
548^ X1 ^ Y1 ^ Z1 ^
549^ X2 ^ ::: ^ Z2 ^
550| A3 | ::: | C3 |
551| A4 | ::: | C4 |
552def');
553
554        $calls = [
555            ['document_start',[]],
556            ['p_open',[]],
557            ['cdata',["\n\nabc"]],
558            ['p_close',[]],
559            ['table_open',[3, 4, 6]],
560            ['tablethead_open',[]],
561            ['tablerow_open',[]],
562            ['tableheader_open',[1,null,1]],
563            ['cdata',[' X1 ']],
564            ['tableheader_close',[]],
565            ['tableheader_open',[1,null,2]],
566            ['cdata',[' Y1 ']],
567            ['tableheader_close',[]],
568            ['tableheader_open',[1,null,1]],
569            ['cdata',[' Z1 ']],
570            ['tableheader_close',[]],
571            ['tablerow_close',[]],
572            ['tablerow_open',[]],
573            ['tableheader_open',[1,null,1]],
574            ['cdata',[' X2 ']],
575            ['tableheader_close',[]],
576            ['tableheader_open',[1,null,1]],
577            ['cdata',[' Z2 ']],
578            ['tableheader_close',[]],
579            ['tablerow_close',[]],
580            ['tablethead_close',[]],
581            ['tablerow_open',[]],
582            ['tablecell_open',[1,null,1]],
583            ['cdata',[' A3 ']],
584            ['tablecell_close',[]],
585            ['tablecell_open',[1,null,2]],
586            ['cdata',['']],
587            ['tablecell_close',[]],
588            ['tablecell_open',[1,null,1]],
589            ['cdata',[' C3 ']],
590            ['tablecell_close',[]],
591            ['tablerow_close',[]],
592            ['tablerow_open',[]],
593            ['tablecell_open',[1,null,1]],
594            ['cdata',[' A4 ']],
595            ['tablecell_close',[]],
596            ['tablecell_open',[1,null,1]],
597            ['cdata',[' C4 ']],
598            ['tablecell_close',[]],
599            ['tablerow_close',[]],
600            ['table_close',[76]],
601            ['p_open',[]],
602            ['cdata',['def']],
603            ['p_close',[]],
604            ['document_end',[]],
605        ];
606
607        $this->assertCalls($calls, $this->H->calls);
608
609    }
610
611    function testCellAlignmentFormatting() {
612        $this->P->addMode('table',new Table());
613        $this->P->addMode('strong',new Strong());
614        $this->P->parse('
615abc
616|  **X** | Y  ^  Z  |
617def');
618
619        $calls = [
620            ['document_start',[]],
621            ['p_open',[]],
622            ['cdata',["\n\nabc"]],
623            ['p_close',[]],
624            ['table_open',[3, 1, 6]],
625            ['tablerow_open',[]],
626            ['tablecell_open',[1,'right',1]],
627            ['cdata',['  ']],
628            ['strong_open',[]],
629            ['cdata',['X']],
630            ['strong_close',[]],
631            ['cdata',[' ']],
632            ['tablecell_close',[]],
633            ['tablecell_open',[1,'left',1]],
634            ['cdata',[' Y  ']],
635            ['tablecell_close',[]],
636            ['tableheader_open',[1,'center',1]],
637            ['cdata',['  Z  ']],
638            ['tableheader_close',[]],
639            ['tablerow_close',[]],
640            ['table_close',[27]],
641            ['p_open',[]],
642            ['cdata',['def']],
643            ['p_close',[]],
644            ['document_end',[]],
645        ];
646
647        $this->assertCalls($calls, $this->H->calls);
648
649    }
650
651    function testTableEol() {
652        $this->P->addMode('table',new Table());
653        $this->P->addMode('eol',new Eol());
654        $this->P->parse('
655abc
656| Row 0 Col 1    | Row 0 Col 2     | Row 0 Col 3        |
657| Row 1 Col 1    | Row 1 Col 2     | Row 1 Col 3        |
658def');
659        $calls = [
660            ['document_start',[]],
661            ['p_open',[]],
662            ['cdata',["abc"]],
663            ['p_close',[]],
664            ['table_open',[3, 2, 6]],
665            ['tablerow_open',[]],
666            ['tablecell_open',[1,'left',1]],
667            ['cdata',[' Row 0 Col 1    ']],
668            ['tablecell_close',[]],
669            ['tablecell_open',[1,'left',1]],
670            ['cdata',[' Row 0 Col 2     ']],
671            ['tablecell_close',[]],
672            ['tablecell_open',[1,'left',1]],
673            ['cdata',[' Row 0 Col 3        ']],
674            ['tablecell_close',[]],
675            ['tablerow_close',[]],
676            ['tablerow_open',[]],
677            ['tablecell_open',[1,'left',1]],
678            ['cdata',[' Row 1 Col 1    ']],
679            ['tablecell_close',[]],
680            ['tablecell_open',[1,'left',1]],
681            ['cdata',[' Row 1 Col 2     ']],
682            ['tablecell_close',[]],
683            ['tablecell_open',[1,'left',1]],
684            ['cdata',[' Row 1 Col 3        ']],
685            ['tablecell_close',[]],
686            ['tablerow_close',[]],
687            ['table_close',[121]],
688            ['p_open',[]],
689            ['cdata',['def']],
690            ['p_close',[]],
691            ['document_end',[]],
692        ];
693        $this->assertCalls($calls, $this->H->calls);
694    }
695
696    // This is really a failing test - formatting able to spread across cols
697    // Problem is fixing it would mean a major rewrite of table handling
698    function testTableStrong() {
699        $this->P->addMode('table',new Table());
700        $this->P->addMode('strong',new Strong());
701        $this->P->parse('
702abc
703| **Row 0 Col 1**    | **Row 0 Col 2     | Row 0 Col 3**        |
704| Row 1 Col 1    | Row 1 Col 2     | Row 1 Col 3        |
705def');
706        $calls = [
707            ['document_start',[]],
708            ['p_open',[]],
709            ['cdata',["\n\nabc"]],
710            ['p_close',[]],
711            ['table_open',[3, 2, 6]],
712            ['tablerow_open',[]],
713            ['tablecell_open',[1,'left',1]],
714            ['cdata',[' ']],
715            ['strong_open',[]],
716            ['cdata',['Row 0 Col 1']],
717            ['strong_close',[]],
718            ['cdata',['    ']],
719            ['tablecell_close',[]],
720            ['tablecell_open',[1,'left',1]],
721            ['cdata',[' ']],
722            ['strong_open',[]],
723            ['cdata',['Row 0 Col 2     | Row 0 Col 3']],
724            ['strong_close',[]],
725            ['cdata',['        ']],
726            ['tablecell_close',[]],
727            ['tablecell_open',[1,null,1]],
728            ['cdata',['']],
729            ['tablecell_close',[]],
730            ['tablerow_close',[]],
731            ['tablerow_open',[]],
732            ['tablecell_open',[1,'left',1]],
733            ['cdata',[' Row 1 Col 1    ']],
734            ['tablecell_close',[]],
735            ['tablecell_open',[1,'left',1]],
736            ['cdata',[' Row 1 Col 2     ']],
737            ['tablecell_close',[]],
738            ['tablecell_open',[1,'left',1]],
739            ['cdata',[' Row 1 Col 3        ']],
740            ['tablecell_close',[]],
741            ['tablerow_close',[]],
742            ['table_close',[129]],
743            ['p_open',[]],
744            ['cdata',['def']],
745            ['p_close',[]],
746            ['document_end',[]],
747        ];
748        $this->assertCalls($calls, $this->H->calls);
749    }
750
751    // This is really a failing test - unformatted able to spread across cols
752    // Problem is fixing it would mean a major rewrite of table handling
753    function testTableUnformatted() {
754        $this->P->addMode('table',new Table());
755        $this->P->addMode('unformatted',new Unformatted());
756        $this->P->parse('
757abc
758| <nowiki>Row 0 Col 1</nowiki>    | <nowiki>Row 0 Col 2     | Row 0 Col 3</nowiki>        |
759| Row 1 Col 1    | Row 1 Col 2     | Row 1 Col 3        |
760def');
761        $calls = [
762            ['document_start',[]],
763            ['p_open',[]],
764            ['cdata',["\n\nabc"]],
765            ['p_close',[]],
766            ['table_open',[3, 2, 6]],
767            ['tablerow_open',[]],
768            ['tablecell_open',[1,'left',1]],
769            ['cdata',[' ']],
770            ['unformatted',['Row 0 Col 1']],
771            ['cdata',['    ']],
772            ['tablecell_close',[]],
773            ['tablecell_open',[1,'left',1]],
774            ['cdata',[' ']],
775            ['unformatted',['Row 0 Col 2     | Row 0 Col 3']],
776            ['cdata',['        ']],
777            ['tablecell_close',[]],
778            ['tablecell_open',[1,null,1]],
779            ['cdata',['']],
780            ['tablecell_close',[]],
781            ['tablerow_close',[]],
782            ['tablerow_open',[]],
783            ['tablecell_open',[1,'left',1]],
784            ['cdata',[' Row 1 Col 1    ']],
785            ['tablecell_close',[]],
786            ['tablecell_open',[1,'left',1]],
787            ['cdata',[' Row 1 Col 2     ']],
788            ['tablecell_close',[]],
789            ['tablecell_open',[1,'left',1]],
790            ['cdata',[' Row 1 Col 3        ']],
791            ['tablecell_close',[]],
792            ['tablerow_close',[]],
793            ['table_close',[155]],
794            ['p_open',[]],
795            ['cdata',['def']],
796            ['p_close',[]],
797            ['document_end',[]],
798        ];
799        $this->assertCalls($calls, $this->H->calls);
800    }
801
802    function testTableLinebreak() {
803        $this->P->addMode('table',new Table());
804        $this->P->addMode('linebreak',new Linebreak());
805        $this->P->parse('
806abc
807| Row 0\\\\ Col 1    | Row 0 Col 2     | Row 0 Col 3        |
808| Row 1 Col 1    | Row 1 Col 2     | Row 1 Col 3        |
809def');
810        $calls = [
811            ['document_start',[]],
812            ['p_open',[]],
813            ['cdata',["\n\nabc"]],
814            ['p_close',[]],
815            ['table_open',[3, 2, 6]],
816            ['tablerow_open',[]],
817            ['tablecell_open',[1,'left',1]],
818            ['cdata',[' Row 0']],
819            ['linebreak',[]],
820            ['cdata',['Col 1    ']],
821            ['tablecell_close',[]],
822            ['tablecell_open',[1,'left',1]],
823            ['cdata',[' Row 0 Col 2     ']],
824            ['tablecell_close',[]],
825            ['tablecell_open',[1,'left',1]],
826            ['cdata',[' Row 0 Col 3        ']],
827            ['tablecell_close',[]],
828            ['tablerow_close',[]],
829            ['tablerow_open',[]],
830            ['tablecell_open',[1,'left',1]],
831            ['cdata',[' Row 1 Col 1    ']],
832            ['tablecell_close',[]],
833            ['tablecell_open',[1,'left',1]],
834            ['cdata',[' Row 1 Col 2     ']],
835            ['tablecell_close',[]],
836            ['tablecell_open',[1,'left',1]],
837            ['cdata',[' Row 1 Col 3        ']],
838            ['tablecell_close',[]],
839            ['tablerow_close',[]],
840            ['table_close',[123]],
841            ['p_open',[]],
842            ['cdata',['def']],
843            ['p_close',[]],
844            ['document_end',[]],
845        ];
846
847        $this->assertCalls($calls, $this->H->calls);
848    }
849
850    // This is really a failing test - footnote able to spread across cols
851    // Problem is fixing it would mean a major rewrite of table handling
852    function testTableFootnote() {
853        $this->P->addMode('table',new Table());
854        $this->P->addMode('footnote',new Footnote());
855        $this->P->parse('
856abc
857| ((Row 0 Col 1))    | ((Row 0 Col 2     | Row 0 Col 3))        |
858| Row 1 Col 1    | Row 1 Col 2     | Row 1 Col 3        |
859def');
860        $calls = [
861            ['document_start',[]],
862            ['p_open',[]],
863            ['cdata',["\n\nabc"]],
864            ['p_close',[]],
865            ['table_open',[3, 2, 6]],
866            ['tablerow_open',[]],
867            ['tablecell_open',[1,'left',1]],
868            ['cdata',[' ']],
869            ['nest', [ [
870              ['footnote_open',[]],
871              ['cdata',['Row 0 Col 1']],
872              ['footnote_close',[]],
873            ]]],
874            ['cdata',['    ']],
875            ['tablecell_close',[]],
876            ['tablecell_open',[1,'left',1]],
877            ['cdata',[' ']],
878            ['nest', [ [
879              ['footnote_open',[]],
880              ['cdata',['Row 0 Col 2     | Row 0 Col 3']],
881              ['footnote_close',[]],
882            ]]],
883            ['cdata',['        ']],
884            ['tablecell_close',[]],
885            ['tablecell_open',[1,null,1]],
886            ['cdata',['']],
887            ['tablecell_close',[]],
888            ['tablerow_close',[]],
889            ['tablerow_open',[]],
890            ['tablecell_open',[1,'left',1]],
891            ['cdata',[' Row 1 Col 1    ']],
892            ['tablecell_close',[]],
893            ['tablecell_open',[1,'left',1]],
894            ['cdata',[' Row 1 Col 2     ']],
895            ['tablecell_close',[]],
896            ['tablecell_open',[1,'left',1]],
897            ['cdata',[' Row 1 Col 3        ']],
898            ['tablecell_close',[]],
899            ['tablerow_close',[]],
900            ['table_close',[129]],
901            ['p_open',[]],
902            ['cdata',['def']],
903            ['p_close',[]],
904            ['document_end',[]],
905        ];
906        $this->assertCalls($calls, $this->H->calls);
907    }
908
909    function testTable_FS1833() {
910        $syntax = " \n| Row 0 Col 1    |\n";
911        $this->P->addMode('table',new Table());
912        $this->P->parse($syntax);
913        $calls = [
914            ['document_start',[]],
915            ['table_open',[1, 1, 2]],
916            ['tablerow_open',[]],
917            ['tablecell_open',[1,'left',1]],
918            ['cdata',[' Row 0 Col 1    ']],
919            ['tablecell_close',[]],
920            ['tablerow_close',[]],
921            ['table_close',[strlen($syntax)]],
922            ['document_end',[]],
923        ];
924        $this->assertCalls($calls, $this->H->calls);
925    }
926
927    /**
928     * missing cells in one row get filled up...
929     */
930    function testTable_CellFix() {
931        $syntax = "\n| r1c1 | r1c2 | r1c3 |\n| r2c1 |\n";
932        $this->P->addMode('table',new Table());
933        $this->P->parse($syntax);
934        $calls = [
935            ['document_start',[]],
936            ['table_open',[3, 2, 2]],
937
938            ['tablerow_open',[]],
939            ['tablecell_open',[1,null,1]],
940            ['cdata',[' r1c1 ']],
941            ['tablecell_close',[]],
942            ['tablecell_open',[1,null,1]],
943            ['cdata',[' r1c2 ']],
944            ['tablecell_close',[]],
945            ['tablecell_open',[1,null,1]],
946            ['cdata',[' r1c3 ']],
947            ['tablecell_close',[]],
948            ['tablerow_close',[]],
949
950            ['tablerow_open',[]],
951            ['tablecell_open',[1,null,1]],
952            ['cdata',[' r2c1 ']],
953            ['tablecell_close',[]],
954            ['tablecell_open',[1,null,1]],
955            ['cdata',['']],
956            ['tablecell_close',[]],
957            ['tablecell_open',[1,null,1]],
958            ['cdata',['']],
959            ['tablecell_close',[]],
960            ['tablerow_close',[]],
961
962            ['table_close',[strlen($syntax)]],
963            ['document_end',[]],
964        ];
965        $this->assertCalls($calls, $this->H->calls);
966    }
967
968    /**
969     * ... even if the longer row comes later
970     */
971    function testTable_CellFix2() {
972        $syntax = "\n| r1c1 |\n| r2c1 | r2c2 | r2c3 |\n";
973        $this->P->addMode('table',new Table());
974        $this->P->parse($syntax);
975        $calls = [
976            ['document_start',[]],
977            ['table_open',[3, 2, 2]],
978
979            ['tablerow_open',[]],
980            ['tablecell_open',[1,null,1]],
981            ['cdata',[' r1c1 ']],
982            ['tablecell_close',[]],
983            ['tablecell_open',[1,null,1]],
984            ['cdata',['']],
985            ['tablecell_close',[]],
986            ['tablecell_open',[1,null,1]],
987            ['cdata',['']],
988            ['tablecell_close',[]],
989            ['tablerow_close',[]],
990
991            ['tablerow_open',[]],
992            ['tablecell_open',[1,null,1]],
993            ['cdata',[' r2c1 ']],
994            ['tablecell_close',[]],
995            ['tablecell_open',[1,null,1]],
996            ['cdata',[' r2c2 ']],
997            ['tablecell_close',[]],
998            ['tablecell_open',[1,null,1]],
999            ['cdata',[' r2c3 ']],
1000            ['tablecell_close',[]],
1001            ['tablerow_close',[]],
1002
1003            ['table_close',[strlen($syntax)]],
1004            ['document_end',[]],
1005        ];
1006        $this->assertCalls($calls, $this->H->calls);
1007    }
1008}
1009