xref: /dokuwiki/_test/tests/Parsing/ParserMode/QuotesTest.php (revision 504c13e8df88563c11b3720b317991bc38835a35)
1<?php
2
3namespace dokuwiki\test\Parsing\ParserMode;
4
5use dokuwiki\Parsing\ParserMode\Quotes;
6
7class QuotesTest extends ParserTestBase
8{
9
10    function setUp() : void {
11        parent::setUp();
12        global $conf;
13        $conf['typography'] = 2;
14    }
15
16    function testSingleQuoteOpening() {
17        $raw = "Foo 'hello Bar";
18        $this->P->addMode('quotes',new Quotes());
19        $this->P->parse($raw);
20
21        $calls = [
22            ['document_start',[]],
23            ['p_open',[]],
24            ['cdata',["\n".'Foo ']],
25            ['singlequoteopening',[]],
26            ['cdata',['hello Bar']],
27            ['p_close',[]],
28            ['document_end',[]],
29        ];
30
31        $this->assertCalls($calls, $this->H->calls, 'wikitext => '.$raw);
32    }
33
34    function testSingleQuoteOpeningSpecial() {
35        $raw = "Foo said:'hello Bar";
36        $this->P->addMode('quotes',new Quotes());
37        $this->P->parse($raw);
38
39        $calls = [
40            ['document_start',[]],
41            ['p_open',[]],
42            ['cdata',["\n".'Foo said:']],
43            ['singlequoteopening',[]],
44            ['cdata',['hello Bar']],
45            ['p_close',[]],
46            ['document_end',[]],
47        ];
48
49        $this->assertCalls($calls, $this->H->calls, 'wikitext => '.$raw);
50    }
51
52    function testSingleQuoteClosing() {
53        $raw = "Foo hello' Bar";
54        $this->P->addMode('quotes',new Quotes());
55        $this->P->parse($raw);
56
57        $calls = [
58            ['document_start',[]],
59            ['p_open',[]],
60            ['cdata',["\n".'Foo hello']],
61            ['singlequoteclosing',[]],
62            ['cdata',[' Bar']],
63            ['p_close',[]],
64            ['document_end',[]],
65        ];
66
67        $this->assertCalls($calls, $this->H->calls, 'wikitext => '.$raw);
68    }
69
70    function testSingleQuoteClosingSpecial() {
71        $raw = "Foo hello') Bar";
72        $this->P->addMode('quotes',new Quotes());
73        $this->P->parse($raw);
74
75        $calls = [
76            ['document_start',[]],
77            ['p_open',[]],
78            ['cdata',["\n".'Foo hello']],
79            ['singlequoteclosing',[]],
80            ['cdata',[') Bar']],
81            ['p_close',[]],
82            ['document_end',[]],
83        ];
84
85        $this->assertCalls($calls, $this->H->calls, 'wikitext => '.$raw);
86    }
87
88    function testSingleQuotes() {
89        $raw = "Foo 'hello' Bar";
90        $this->P->addMode('quotes',new Quotes());
91        $this->P->parse($raw);
92
93        $calls = [
94            ['document_start',[]],
95            ['p_open',[]],
96            ['cdata',["\n".'Foo ']],
97            ['singlequoteopening',[]],
98            ['cdata',['hello']],
99            ['singlequoteclosing',[]],
100            ['cdata',[' Bar']],
101            ['p_close',[]],
102            ['document_end',[]],
103        ];
104
105        $this->assertCalls($calls, $this->H->calls, 'wikitext => '.$raw);
106    }
107
108    function testApostrophe() {
109        $raw = "hey it's fine weather today";
110        $this->P->addMode('quotes',new Quotes());
111        $this->P->parse($raw);
112
113        $calls = [
114            ['document_start',[]],
115            ['p_open',[]],
116            ['cdata',["\n".'hey it']],
117            ['apostrophe',[]],
118            ['cdata',['s fine weather today']],
119            ['p_close',[]],
120            ['document_end',[]],
121        ];
122
123        $this->assertCalls($calls, $this->H->calls, 'wikitext => '.$raw);
124    }
125
126
127    function testSingleQuotesSpecial() {
128        $raw = "Foo ('hello') Bar";
129        $this->P->addMode('quotes',new Quotes());
130        $this->P->parse($raw);
131
132        $calls = [
133            ['document_start',[]],
134            ['p_open',[]],
135            ['cdata',["\n".'Foo (']],
136            ['singlequoteopening',[]],
137            ['cdata',['hello']],
138            ['singlequoteclosing',[]],
139            ['cdata',[') Bar']],
140            ['p_close',[]],
141            ['document_end',[]],
142        ];
143
144        $this->assertCalls($calls, $this->H->calls, 'wikitext => '.$raw);
145    }
146
147    function testDoubleQuoteOpening() {
148        $raw = 'Foo "hello Bar';
149        $this->P->addMode('quotes',new Quotes());
150        $this->P->parse($raw);
151
152        $calls = [
153            ['document_start',[]],
154            ['p_open',[]],
155            ['cdata',["\n".'Foo ']],
156            ['doublequoteopening',[]],
157            ['cdata',['hello Bar']],
158            ['p_close',[]],
159            ['document_end',[]],
160        ];
161
162        $this->assertCalls($calls, $this->H->calls, 'wikitext => '.$raw);
163    }
164
165    function testDoubleQuoteOpeningSpecial() {
166        $raw = 'Foo said:"hello Bar';
167        $this->P->addMode('quotes',new Quotes());
168        $this->P->parse($raw);
169
170        $calls = [
171            ['document_start',[]],
172            ['p_open',[]],
173            ['cdata',["\n".'Foo said:']],
174            ['doublequoteopening',[]],
175            ['cdata',['hello Bar']],
176            ['p_close',[]],
177            ['document_end',[]],
178        ];
179
180        $this->assertCalls($calls, $this->H->calls, 'wikitext => '.$raw);
181    }
182
183    function testDoubleQuoteClosing() {
184        $raw = 'Foo hello" Bar';
185        $this->P->addMode('quotes', new Quotes());
186        $this->H->setStatus('doublequote', 1);
187        $this->P->parse($raw);
188
189        $calls = [
190            ['document_start',[]],
191            ['p_open',[]],
192            ['cdata',["\n".'Foo hello']],
193            ['doublequoteclosing',[]],
194            ['cdata',[' Bar']],
195            ['p_close',[]],
196            ['document_end',[]],
197        ];
198
199        $this->assertCalls($calls, $this->H->calls, 'wikitext => '.$raw);
200    }
201
202    function testDoubleQuoteClosingSpecial() {
203        $raw = 'Foo hello") Bar';
204        $this->P->addMode('quotes', new Quotes());
205        $this->H->setStatus('doublequote', 1);
206
207        $this->P->parse($raw);
208
209        $calls = [
210            ['document_start',[]],
211            ['p_open',[]],
212            ['cdata',["\n".'Foo hello']],
213            ['doublequoteclosing',[]],
214            ['cdata',[') Bar']],
215            ['p_close',[]],
216            ['document_end',[]],
217        ];
218
219        $this->assertCalls($calls, $this->H->calls, 'wikitext => '.$raw);
220    }
221    function testDoubleQuoteClosingSpecial2() {
222        $raw = 'Foo hello") Bar';
223        $this->P->addMode('quotes', new Quotes());
224
225        $this->P->parse($raw);
226
227        $calls = [
228            ['document_start',[]],
229            ['p_open',[]],
230            ['cdata',["\n".'Foo hello']],
231            ['doublequoteopening',[]],
232            ['cdata',[') Bar']],
233            ['p_close',[]],
234            ['document_end',[]],
235        ];
236
237        $this->assertCalls($calls, $this->H->calls, 'wikitext => '.$raw);
238    }
239
240    function testDoubleQuotes() {
241        $raw = 'Foo "hello" Bar';
242        $this->P->addMode('quotes',new Quotes());
243        $this->P->parse($raw);
244
245        $calls = [
246            ['document_start',[]],
247            ['p_open',[]],
248            ['cdata',["\n".'Foo ']],
249            ['doublequoteopening',[]],
250            ['cdata',['hello']],
251            ['doublequoteclosing',[]],
252            ['cdata',[' Bar']],
253            ['p_close',[]],
254            ['document_end',[]],
255        ];
256
257        $this->assertCalls($calls, $this->H->calls, 'wikitext => '.$raw);
258    }
259
260    function testDoubleQuotesSpecial() {
261        $raw = 'Foo ("hello") Bar';
262        $this->P->addMode('quotes',new Quotes());
263        $this->P->parse($raw);
264
265        $calls = [
266            ['document_start',[]],
267            ['p_open',[]],
268            ['cdata',["\n".'Foo (']],
269            ['doublequoteopening',[]],
270            ['cdata',['hello']],
271            ['doublequoteclosing',[]],
272            ['cdata',[') Bar']],
273            ['p_close',[]],
274            ['document_end',[]],
275        ];
276
277        $this->assertCalls($calls, $this->H->calls, 'wikitext => '.$raw);
278    }
279
280    function testDoubleQuotesEnclosingBrackets() {
281        $raw = 'Foo "{hello}" Bar';
282        $this->P->addMode('quotes',new Quotes());
283        $this->P->parse($raw);
284
285        $calls = [
286            ['document_start',[]],
287            ['p_open',[]],
288            ['cdata',["\n".'Foo ']],
289            ['doublequoteopening',[]],
290            ['cdata',['{hello}']],
291            ['doublequoteclosing',[]],
292            ['cdata',[' Bar']],
293            ['p_close',[]],
294            ['document_end',[]],
295        ];
296
297        $this->assertCalls($calls, $this->H->calls, 'wikitext - '.$raw);
298    }
299
300    function testDoubleQuotesEnclosingLink() {
301        $raw = 'Foo "[[www.domain.com]]" Bar';
302        $this->P->addMode('quotes',new Quotes());
303        $this->P->parse($raw);
304
305        $calls = [
306            ['document_start',[]],
307            ['p_open',[]],
308            ['cdata',["\n".'Foo ']],
309            ['doublequoteopening',[]],
310            ['cdata',['[[www.domain.com]]']],
311            ['doublequoteclosing',[]],
312            ['cdata',[' Bar']],
313            ['p_close',[]],
314            ['document_end',[]],
315        ];
316
317        $this->assertCalls($calls, $this->H->calls, 'wikitext => '.$raw);
318    }
319
320
321    function testAllQuotes() {
322        $raw = 'There was written "He thought \'It\'s a man\'s world\'".';
323        $this->P->addMode('quotes',new Quotes());
324        $this->P->parse($raw);
325
326        $calls = [
327            ['document_start',[]],
328            ['p_open',[]],
329            ['cdata',["\n".'There was written ']],
330            ['doublequoteopening',[]],
331            ['cdata',['He thought ']],
332            ['singlequoteopening',[]],
333            ['cdata',['It']],
334            ['apostrophe',[]],
335            ['cdata',['s a man']],
336            ['apostrophe',[]],
337            ['cdata',['s world']],
338            ['singlequoteclosing',[]],
339            ['doublequoteclosing',[]],
340            ['cdata',["."]],
341            ['p_close',[]],
342            ['document_end',[]],
343        ];
344
345        $this->assertCalls($calls, $this->H->calls, 'wikitext => '.$raw);
346    }
347
348}
349