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