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