xref: /dokuwiki/_test/tests/inc/parser/parser_quotes.test.php (revision f6af1fe63a13b2734d1b69817ec800c51e6def9c)
1<?php
2require_once 'parser.inc.php';
3
4class TestOfDoku_Parser_Quotes extends TestOfDoku_Parser {
5
6    function setUp() {
7        parent::setUp();
8        global $conf;
9        $conf['typography'] = 2;
10    }
11
12    function testSingleQuoteOpening() {
13        $this->P->addMode('quotes',new Doku_Parser_Mode_Quotes());
14        $this->P->parse("Foo 'hello Bar");
15
16        $calls = array (
17            array('document_start',array()),
18            array('p_open',array()),
19            array('cdata',array("\n".'Foo ')),
20            array('singlequoteopening',array()),
21            array('cdata',array('hello Bar')),
22            array('p_close',array()),
23            array('document_end',array()),
24        );
25
26        $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls);
27    }
28
29    function testSingleQuoteOpeningSpecial() {
30        $this->P->addMode('quotes',new Doku_Parser_Mode_Quotes());
31        $this->P->parse("Foo said:'hello Bar");
32
33        $calls = array (
34            array('document_start',array()),
35            array('p_open',array()),
36            array('cdata',array("\n".'Foo said:')),
37            array('singlequoteopening',array()),
38            array('cdata',array('hello Bar')),
39            array('p_close',array()),
40            array('document_end',array()),
41        );
42
43        $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls);
44    }
45
46    function testSingleQuoteClosing() {
47        $this->P->addMode('quotes',new Doku_Parser_Mode_Quotes());
48        $this->P->parse("Foo hello' Bar");
49
50        $calls = array (
51            array('document_start',array()),
52            array('p_open',array()),
53            array('cdata',array("\n".'Foo hello')),
54            array('singlequoteclosing',array()),
55            array('cdata',array(' Bar')),
56            array('p_close',array()),
57            array('document_end',array()),
58        );
59
60        $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls);
61    }
62
63    function testSingleQuoteClosingSpecial() {
64        $this->P->addMode('quotes',new Doku_Parser_Mode_Quotes());
65        $this->P->parse("Foo hello') Bar");
66
67        $calls = array (
68            array('document_start',array()),
69            array('p_open',array()),
70            array('cdata',array("\n".'Foo hello')),
71            array('singlequoteclosing',array()),
72            array('cdata',array(') Bar')),
73            array('p_close',array()),
74            array('document_end',array()),
75        );
76
77        $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls);
78    }
79
80    function testSingleQuotes() {
81        $this->P->addMode('quotes',new Doku_Parser_Mode_Quotes());
82        $this->P->parse("Foo 'hello' Bar");
83
84        $calls = array (
85            array('document_start',array()),
86            array('p_open',array()),
87            array('cdata',array("\n".'Foo ')),
88            array('singlequoteopening',array()),
89            array('cdata',array('hello')),
90            array('singlequoteclosing',array()),
91            array('cdata',array(' Bar')),
92            array('p_close',array()),
93            array('document_end',array()),
94        );
95
96        $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls);
97    }
98
99    function testApostrophe() {
100        $this->P->addMode('quotes',new Doku_Parser_Mode_Quotes());
101        $this->P->parse("hey it's fine weather today");
102
103        $calls = array (
104            array('document_start',array()),
105            array('p_open',array()),
106            array('cdata',array("\n".'hey it')),
107            array('apostrophe',array()),
108            array('cdata',array('s fine weather today')),
109            array('p_close',array()),
110            array('document_end',array()),
111        );
112
113        $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls);
114    }
115
116
117    function testSingleQuotesSpecial() {
118        $this->P->addMode('quotes',new Doku_Parser_Mode_Quotes());
119        $this->P->parse("Foo ('hello') Bar");
120
121        $calls = array (
122            array('document_start',array()),
123            array('p_open',array()),
124            array('cdata',array("\n".'Foo (')),
125            array('singlequoteopening',array()),
126            array('cdata',array('hello')),
127            array('singlequoteclosing',array()),
128            array('cdata',array(') Bar')),
129            array('p_close',array()),
130            array('document_end',array()),
131        );
132
133        $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls);
134    }
135
136    function testDoubleQuoteOpening() {
137        $this->P->addMode('quotes',new Doku_Parser_Mode_Quotes());
138        $this->P->parse('Foo "hello Bar');
139
140        $calls = array (
141            array('document_start',array()),
142            array('p_open',array()),
143            array('cdata',array("\n".'Foo ')),
144            array('doublequoteopening',array()),
145            array('cdata',array('hello Bar')),
146            array('p_close',array()),
147            array('document_end',array()),
148        );
149
150        $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls);
151    }
152
153    function testDoubleQuoteOpeningSpecial() {
154        $this->P->addMode('quotes',new Doku_Parser_Mode_Quotes());
155        $this->P->parse('Foo said:"hello Bar');
156
157        $calls = array (
158            array('document_start',array()),
159            array('p_open',array()),
160            array('cdata',array("\n".'Foo said:')),
161            array('doublequoteopening',array()),
162            array('cdata',array('hello Bar')),
163            array('p_close',array()),
164            array('document_end',array()),
165        );
166
167        $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls);
168    }
169
170    function testDoubleQuoteClosing() {
171        $this->P->addMode('quotes',new Doku_Parser_Mode_Quotes());
172        $this->P->parse('Foo hello" Bar');
173
174        $calls = array (
175            array('document_start',array()),
176            array('p_open',array()),
177            array('cdata',array("\n".'Foo hello')),
178            array('doublequoteclosing',array()),
179            array('cdata',array(' Bar')),
180            array('p_close',array()),
181            array('document_end',array()),
182        );
183
184        $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls);
185    }
186
187    function testDoubleQuoteClosingSpecial() {
188        $this->P->addMode('quotes',new Doku_Parser_Mode_Quotes());
189        $this->P->parse('Foo hello") Bar');
190
191        $calls = array (
192            array('document_start',array()),
193            array('p_open',array()),
194            array('cdata',array("\n".'Foo hello')),
195            array('doublequoteclosing',array()),
196            array('cdata',array(') Bar')),
197            array('p_close',array()),
198            array('document_end',array()),
199        );
200
201        $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls);
202    }
203
204    function testDoubleQuotes() {
205        $this->P->addMode('quotes',new Doku_Parser_Mode_Quotes());
206        $this->P->parse('Foo "hello" Bar');
207
208        $calls = array (
209            array('document_start',array()),
210            array('p_open',array()),
211            array('cdata',array("\n".'Foo ')),
212            array('doublequoteopening',array()),
213            array('cdata',array('hello')),
214            array('doublequoteclosing',array()),
215            array('cdata',array(' Bar')),
216            array('p_close',array()),
217            array('document_end',array()),
218        );
219
220        $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls);
221    }
222
223    function testDoubleQuotesSpecial() {
224        $this->P->addMode('quotes',new Doku_Parser_Mode_Quotes());
225        $this->P->parse('Foo ("hello") Bar');
226
227        $calls = array (
228            array('document_start',array()),
229            array('p_open',array()),
230            array('cdata',array("\n".'Foo (')),
231            array('doublequoteopening',array()),
232            array('cdata',array('hello')),
233            array('doublequoteclosing',array()),
234            array('cdata',array(') Bar')),
235            array('p_close',array()),
236            array('document_end',array()),
237        );
238
239        $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls);
240    }
241
242    function testAllQuotes() {
243        $this->P->addMode('quotes',new Doku_Parser_Mode_Quotes());
244        $this->P->parse('There was written "He thought \'It\'s a man\'s world\'".');
245
246        $calls = array (
247            array('document_start',array()),
248            array('p_open',array()),
249            array('cdata',array("\n".'There was written ')),
250            array('doublequoteopening',array()),
251            array('cdata',array('He thought ')),
252            array('singlequoteopening',array()),
253            array('cdata',array('It')),
254            array('apostrophe',array()),
255            array('cdata',array('s a man')),
256            array('apostrophe',array()),
257            array('cdata',array('s world')),
258            array('singlequoteclosing',array()),
259            array('doublequoteclosing',array()),
260            array('cdata',array(".")),
261            array('p_close',array()),
262            array('document_end',array()),
263        );
264
265        $this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls);
266    }
267
268}
269
270