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