xref: /dokuwiki/_test/tests/Parsing/ParserMode/HeadersTest.php (revision 504c13e8df88563c11b3720b317991bc38835a35)
1<?php
2
3namespace dokuwiki\test\Parsing\ParserMode;
4
5use dokuwiki\Parsing\ParserMode\Eol;
6use dokuwiki\Parsing\ParserMode\Header;
7
8class HeadersTest extends ParserTestBase
9{
10
11    function testHeader1() {
12        $this->P->addMode('header',new Header());
13        $this->P->parse("abc \n ====== Header ====== \n def");
14        $calls = [
15            ['document_start',[]],
16            ['p_open',[]],
17            ['cdata',["\nabc "]],
18            ['p_close',[]],
19            ['header',['Header',1,6]],
20            ['section_open',[1]],
21            ['p_open',[]],
22            ['cdata',["\n def"]],
23            ['p_close',[]],
24            ['section_close',[]],
25            ['document_end',[]],
26        ];
27        $this->assertCalls($calls, $this->H->calls);
28    }
29
30    function testHeader2() {
31        $this->P->addMode('header',new Header());
32        $this->P->parse("abc \n  ===== Header ===== \n def");
33        $calls = [
34            ['document_start',[]],
35            ['p_open',[]],
36            ['cdata',["\nabc "]],
37            ['p_close',[]],
38            ['header',['Header',2,6]],
39            ['section_open',[2]],
40            ['p_open',[]],
41            ['cdata',["\n def"]],
42            ['p_close',[]],
43            ['section_close',[]],
44            ['document_end',[]],
45        ];
46        $this->assertCalls($calls, $this->H->calls);
47    }
48
49    function testHeader3() {
50        $this->P->addMode('header',new Header());
51        $this->P->parse("abc \n ==== Header ==== \n def");
52        $calls = [
53            ['document_start',[]],
54            ['p_open',[]],
55            ['cdata',["\nabc "]],
56            ['p_close',[]],
57            ['header',['Header',3,6]],
58            ['section_open',[3]],
59            ['p_open',[]],
60            ['cdata',["\n def"]],
61            ['p_close',[]],
62            ['section_close',[]],
63            ['document_end',[]],
64        ];
65        $this->assertCalls($calls, $this->H->calls);
66    }
67
68    function testHeader4() {
69        $this->P->addMode('header',new Header());
70        $this->P->parse("abc \n === Header === \n def");
71        $calls = [
72            ['document_start',[]],
73            ['p_open',[]],
74            ['cdata',["\nabc "]],
75            ['p_close',[]],
76            ['header',['Header',4,6]],
77            ['section_open',[4]],
78            ['p_open',[]],
79            ['cdata',["\n def"]],
80            ['p_close',[]],
81            ['section_close',[]],
82            ['document_end',[]],
83        ];
84        $this->assertCalls($calls, $this->H->calls);
85    }
86
87    function testHeader5() {
88        $this->P->addMode('header',new Header());
89        $this->P->parse("abc \n  == Header ==  \n def");
90        $calls = [
91            ['document_start',[]],
92            ['p_open',[]],
93            ['cdata',["\nabc "]],
94            ['p_close',[]],
95            ['header',['Header',5,6]],
96            ['section_open',[5]],
97            ['p_open',[]],
98            ['cdata',["\n def"]],
99            ['p_close',[]],
100            ['section_close',[]],
101            ['document_end',[]],
102        ];
103        $this->assertCalls($calls, $this->H->calls);
104    }
105
106    function testHeader2UnevenSmaller() {
107        $this->P->addMode('header',new Header());
108        $this->P->parse("abc \n  ===== Header ==  \n def");
109        $calls = [
110            ['document_start',[]],
111            ['p_open',[]],
112            ['cdata',["\nabc "]],
113            ['p_close',[]],
114            ['header',['Header',2,6]],
115            ['section_open',[2]],
116            ['p_open',[]],
117            ['cdata',["\n def"]],
118            ['p_close',[]],
119            ['section_close',[]],
120            ['document_end',[]],
121        ];
122        $this->assertCalls($calls, $this->H->calls);
123    }
124
125    function testHeader2UnevenBigger() {
126        $this->P->addMode('header',new Header());
127        $this->P->parse("abc \n  ===== Header ===========  \n def");
128        $calls = [
129            ['document_start',[]],
130            ['p_open',[]],
131            ['cdata',["\nabc "]],
132            ['p_close',[]],
133            ['header',['Header',2,6]],
134            ['section_open',[2]],
135            ['p_open',[]],
136            ['cdata',["\n def"]],
137            ['p_close',[]],
138            ['section_close',[]],
139            ['document_end',[]],
140        ];
141        $this->assertCalls($calls, $this->H->calls);
142    }
143
144    function testHeaderLarge() {
145        $this->P->addMode('header',new Header());
146        $this->P->parse("abc \n ======= Header ======= \n def");
147        $calls = [
148            ['document_start',[]],
149            ['p_open',[]],
150            ['cdata',["\nabc "]],
151            ['p_close',[]],
152            ['header',['Header',1,6]],
153            ['section_open',[1]],
154            ['p_open',[]],
155            ['cdata',["\n def"]],
156            ['p_close',[]],
157            ['section_close',[]],
158            ['document_end',[]],
159        ];
160        $this->assertCalls($calls, $this->H->calls);
161    }
162
163    function testHeaderSmall() {
164        $this->P->addMode('header',new Header());
165        $this->P->parse("abc \n= Header =\n def");
166        $calls = [
167            ['document_start',[]],
168            ['p_open',[]],
169            ['cdata',["\nabc \n= Header =\n def"]],
170            ['p_close',[]],
171            ['document_end',[]],
172        ];
173        $this->assertCalls($calls, $this->H->calls);
174    }
175
176
177    function testHeader1Mixed() {
178        $this->P->addMode('header',new Header());
179        $this->P->parse("abc \n====== == Header == ======\n def");
180        $calls = [
181            ['document_start',[]],
182            ['p_open',[]],
183            ['cdata',["\nabc "]],
184            ['p_close',[]],
185            ['header',['== Header ==',1,6]],
186            ['section_open',[1]],
187            ['p_open',[]],
188            ['cdata',["\n def"]],
189            ['p_close',[]],
190            ['section_close',[]],
191            ['document_end',[]],
192        ];
193        $this->assertCalls($calls, $this->H->calls);
194    }
195
196    function testHeader5Mixed() {
197        $this->P->addMode('header',new Header());
198        $this->P->parse("abc \n== ====== Header ====== ==\n def");
199        $calls = [
200            ['document_start',[]],
201            ['p_open',[]],
202            ['cdata',["\nabc "]],
203            ['p_close',[]],
204            ['header',['====== Header ======',5,6]],
205            ['section_open',[5]],
206            ['p_open',[]],
207            ['cdata',["\n def"]],
208            ['p_close',[]],
209            ['section_close',[]],
210            ['document_end',[]],
211        ];
212        $this->assertCalls($calls, $this->H->calls);
213    }
214
215    function testHeaderMultiline() {
216        $this->P->addMode('header',new Header());
217        $this->P->parse("abc \n== ====== Header\n ====== ==\n def");
218        $calls = [
219            ['document_start',[]],
220            ['p_open',[]],
221            ['cdata',["\nabc \n== ====== Header"]],
222            ['p_close',[]],
223            ['header',['',1,23]],
224            ['section_open',[1]],
225            ['p_open',[]],
226            ['cdata',["\n def"]],
227            ['p_close',[]],
228            ['section_close',[]],
229            ['document_end',[]],
230        ];
231        $this->assertCalls($calls, $this->H->calls);
232    }
233
234    function testHeader1Eol() {
235        $this->P->addMode('header',new Header());
236        $this->P->addMode('eol',new Eol());
237        $this->P->parse("abc \n ====== Header ====== \n def");
238        $calls = [
239            ['document_start',[]],
240            ['p_open',[]],
241            ['cdata',['abc ']],
242            ['p_close',[]],
243            ['header',['Header',1, 6]],
244            ['section_open',[1]],
245            ['p_open',[]],
246            ['cdata',[' def']],
247            ['p_close',[]],
248            ['section_close',[]],
249            ['document_end',[]],
250        ];
251        $this->assertCalls($calls, $this->H->calls);
252
253    }
254
255    function testHeaderMulti2() {
256        $this->P->addMode('header',new Header());
257        $this->P->parse("abc \n ====== Header ====== \n def abc \n ===== Header2 ===== \n def");
258        $calls = [
259            ['document_start',[]],
260            ['p_open',[]],
261            ['cdata',["\nabc "]],
262            ['p_close',[]],
263            ['header',['Header',1,6]],
264            ['section_open',[1]],
265            ['p_open',[]],
266            ['cdata',["\n def abc "]],
267            ['p_close',[]],
268            ['section_close',[]],
269            ['header',['Header2',2,39]],
270            ['section_open',[2]],
271            ['p_open',[]],
272            ['cdata',["\n def"]],
273            ['p_close',[]],
274            ['section_close',[]],
275            ['document_end',[]]
276        ];
277        $this->assertCalls($calls, $this->H->calls);
278    }
279
280}
281