xref: /dokuwiki/_test/tests/Parsing/ParserMode/QuotesTest.php (revision fe58309edafb067d90f3f40ef3d416100d558a04)
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 testSingleQuotesAfterStrong() {
148        $raw = "**'hello'**";
149        $this->P->addMode('quotes',new Quotes());
150        $this->P->parse($raw);
151
152        $calls = [
153            ['document_start',[]],
154            ['p_open',[]],
155            ['cdata',["\n".'**']],
156            ['singlequoteopening',[]],
157            ['cdata',['hello']],
158            ['singlequoteclosing',[]],
159            ['cdata',['**']],
160            ['p_close',[]],
161            ['document_end',[]],
162        ];
163
164        $this->assertCalls($calls, $this->H->calls, 'wikitext => '.$raw);
165    }
166
167    function testSingleQuotesAfterUnderline() {
168        $raw = "__'hello'__";
169        $this->P->addMode('quotes',new Quotes());
170        $this->P->parse($raw);
171
172        $calls = [
173            ['document_start',[]],
174            ['p_open',[]],
175            ['cdata',["\n".'__']],
176            ['singlequoteopening',[]],
177            ['cdata',['hello']],
178            ['singlequoteclosing',[]],
179            ['cdata',['__']],
180            ['p_close',[]],
181            ['document_end',[]],
182        ];
183
184        $this->assertCalls($calls, $this->H->calls, 'wikitext => '.$raw);
185    }
186
187    function testDoubleQuoteOpening() {
188        $raw = 'Foo "hello Bar';
189        $this->P->addMode('quotes',new Quotes());
190        $this->P->parse($raw);
191
192        $calls = [
193            ['document_start',[]],
194            ['p_open',[]],
195            ['cdata',["\n".'Foo ']],
196            ['doublequoteopening',[]],
197            ['cdata',['hello Bar']],
198            ['p_close',[]],
199            ['document_end',[]],
200        ];
201
202        $this->assertCalls($calls, $this->H->calls, 'wikitext => '.$raw);
203    }
204
205    function testDoubleQuoteOpeningSpecial() {
206        $raw = 'Foo said:"hello Bar';
207        $this->P->addMode('quotes',new Quotes());
208        $this->P->parse($raw);
209
210        $calls = [
211            ['document_start',[]],
212            ['p_open',[]],
213            ['cdata',["\n".'Foo said:']],
214            ['doublequoteopening',[]],
215            ['cdata',['hello Bar']],
216            ['p_close',[]],
217            ['document_end',[]],
218        ];
219
220        $this->assertCalls($calls, $this->H->calls, 'wikitext => '.$raw);
221    }
222
223    function testDoubleQuoteClosing() {
224        $raw = 'Foo hello" Bar';
225        $this->P->addMode('quotes', new Quotes());
226        $this->H->setStatus('doublequote', 1);
227        $this->P->parse($raw);
228
229        $calls = [
230            ['document_start',[]],
231            ['p_open',[]],
232            ['cdata',["\n".'Foo hello']],
233            ['doublequoteclosing',[]],
234            ['cdata',[' Bar']],
235            ['p_close',[]],
236            ['document_end',[]],
237        ];
238
239        $this->assertCalls($calls, $this->H->calls, 'wikitext => '.$raw);
240    }
241
242    function testDoubleQuoteClosingSpecial() {
243        $raw = 'Foo hello") Bar';
244        $this->P->addMode('quotes', new Quotes());
245        $this->H->setStatus('doublequote', 1);
246
247        $this->P->parse($raw);
248
249        $calls = [
250            ['document_start',[]],
251            ['p_open',[]],
252            ['cdata',["\n".'Foo hello']],
253            ['doublequoteclosing',[]],
254            ['cdata',[') Bar']],
255            ['p_close',[]],
256            ['document_end',[]],
257        ];
258
259        $this->assertCalls($calls, $this->H->calls, 'wikitext => '.$raw);
260    }
261    function testDoubleQuoteClosingSpecial2() {
262        $raw = 'Foo hello") Bar';
263        $this->P->addMode('quotes', new Quotes());
264
265        $this->P->parse($raw);
266
267        $calls = [
268            ['document_start',[]],
269            ['p_open',[]],
270            ['cdata',["\n".'Foo hello']],
271            ['doublequoteopening',[]],
272            ['cdata',[') Bar']],
273            ['p_close',[]],
274            ['document_end',[]],
275        ];
276
277        $this->assertCalls($calls, $this->H->calls, 'wikitext => '.$raw);
278    }
279
280    function testDoubleQuotes() {
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 testDoubleQuotesSpecial() {
301        $raw = 'Foo ("hello") 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',['hello']],
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    function testDoubleQuotesEnclosingBrackets() {
321        $raw = 'Foo "{hello}" Bar';
322        $this->P->addMode('quotes',new Quotes());
323        $this->P->parse($raw);
324
325        $calls = [
326            ['document_start',[]],
327            ['p_open',[]],
328            ['cdata',["\n".'Foo ']],
329            ['doublequoteopening',[]],
330            ['cdata',['{hello}']],
331            ['doublequoteclosing',[]],
332            ['cdata',[' Bar']],
333            ['p_close',[]],
334            ['document_end',[]],
335        ];
336
337        $this->assertCalls($calls, $this->H->calls, 'wikitext - '.$raw);
338    }
339
340    function testDoubleQuotesEnclosingLink() {
341        $raw = 'Foo "[[www.domain.com]]" Bar';
342        $this->P->addMode('quotes',new Quotes());
343        $this->P->parse($raw);
344
345        $calls = [
346            ['document_start',[]],
347            ['p_open',[]],
348            ['cdata',["\n".'Foo ']],
349            ['doublequoteopening',[]],
350            ['cdata',['[[www.domain.com]]']],
351            ['doublequoteclosing',[]],
352            ['cdata',[' Bar']],
353            ['p_close',[]],
354            ['document_end',[]],
355        ];
356
357        $this->assertCalls($calls, $this->H->calls, 'wikitext => '.$raw);
358    }
359
360
361    function testAllQuotes() {
362        $raw = 'There was written "He thought \'It\'s a man\'s world\'".';
363        $this->P->addMode('quotes',new Quotes());
364        $this->P->parse($raw);
365
366        $calls = [
367            ['document_start',[]],
368            ['p_open',[]],
369            ['cdata',["\n".'There was written ']],
370            ['doublequoteopening',[]],
371            ['cdata',['He thought ']],
372            ['singlequoteopening',[]],
373            ['cdata',['It']],
374            ['apostrophe',[]],
375            ['cdata',['s a man']],
376            ['apostrophe',[]],
377            ['cdata',['s world']],
378            ['singlequoteclosing',[]],
379            ['doublequoteclosing',[]],
380            ['cdata',["."]],
381            ['p_close',[]],
382            ['document_end',[]],
383        ];
384
385        $this->assertCalls($calls, $this->H->calls, 'wikitext => '.$raw);
386    }
387
388}
389