1<?php 2 3namespace dokuwiki\test\Parsing\ParserMode; 4 5use dokuwiki\Parsing\Handler\Lists; 6use dokuwiki\Parsing\ParserMode\Code; 7use dokuwiki\Parsing\ParserMode\Eol; 8use dokuwiki\Parsing\ParserMode\Footnote; 9use dokuwiki\Parsing\ParserMode\Strong; 10use dokuwiki\Parsing\ParserMode\Hr; 11use dokuwiki\Parsing\ParserMode\Listblock; 12use dokuwiki\Parsing\ParserMode\Preformatted; 13use dokuwiki\Parsing\ParserMode\Quote; 14use dokuwiki\Parsing\ParserMode\Table; 15use dokuwiki\Parsing\ParserMode\Unformatted; 16 17class FootnoteTest extends ParserTestBase 18{ 19 20 function setUp() : void { 21 parent::setUp(); 22 $this->P->addMode('footnote',new Footnote()); 23 } 24 25 function testFootnote() { 26 $this->P->parse('Foo (( testing )) Bar'); 27 $calls = [ 28 ['document_start',[]], 29 ['p_open',[]], 30 ['cdata',["\n".'Foo ']], 31 ['nest', [ [ 32 ['footnote_open',[]], 33 ['cdata',[' testing ']], 34 ['footnote_close',[]], 35 ]]], 36 ['cdata',[' Bar']], 37 ['p_close',[]], 38 ['document_end',[]], 39 ]; 40 $this->assertCalls($calls, $this->H->calls); 41 } 42 43 function testNotAFootnote() { 44 $this->P->parse("Foo (( testing\n Bar"); 45 $calls = [ 46 ['document_start',[]], 47 ['p_open',[]], 48 ['cdata',["\nFoo (( testing\n Bar"]], 49 ['p_close',[]], 50 ['document_end',[]], 51 ]; 52 $this->assertCalls($calls, $this->H->calls); 53 } 54 55 function testFootnoteLinefeed() { 56 $this->P->addMode('eol',new Eol()); 57 $this->P->parse("Foo (( testing\ntesting )) Bar"); 58 $calls = [ 59 ['document_start',[]], 60 ['p_open',[]], 61 ['cdata',['Foo ']], 62 ['nest', [ [ 63 ['footnote_open',[]], 64 ['cdata',[" testing\ntesting "]], 65 ['footnote_close',[]], 66 ]]], 67 ['cdata',[' Bar']], 68 ['p_close',[]], 69 ['document_end',[]], 70 ]; 71 $this->assertCalls($calls, $this->H->calls); 72 } 73 74 function testFootnoteNested() { 75 $this->P->parse('Foo (( x((y))z )) Bar'); 76 $calls = [ 77 ['document_start',[]], 78 ['p_open',[]], 79 ['cdata',["\n".'Foo ']], 80 ['nest', [ [ 81 ['footnote_open',[]], 82 ['cdata',[' x((y']], 83 ['footnote_close',[]], 84 ]]], 85 ['cdata',['z )) Bar']], 86 ['p_close',[]], 87 ['document_end',[]], 88 ]; 89 $this->assertCalls($calls, $this->H->calls); 90 } 91 92 function testFootnoteEol() { 93 $this->P->addMode('eol',new Eol()); 94 $this->P->parse("Foo \nX(( test\ning ))Y\n Bar"); 95 $calls = [ 96 ['document_start',[]], 97 ['p_open',[]], 98 ['cdata',['Foo '."\n".'X']], 99 ['nest', [ [ 100 ['footnote_open',[]], 101 ['cdata',[" test\ning "]], 102 ['footnote_close',[]], 103 ]]], 104 ['cdata',['Y'."\n".' Bar']], 105 ['p_close',[]], 106 ['document_end',[]], 107 ]; 108 $this->assertCalls($calls, $this->H->calls); 109 } 110 111 function testFootnoteStrong() { 112 $this->P->addMode('strong',new Strong()); 113 $this->P->parse('Foo (( **testing** )) Bar'); 114 $calls = [ 115 ['document_start',[]], 116 ['p_open',[]], 117 ['cdata',["\n".'Foo ']], 118 ['nest', [ [ 119 ['footnote_open',[]], 120 ['cdata',[' ']], 121 ['strong_open',[]], 122 ['cdata',['testing']], 123 ['strong_close',[]], 124 ['cdata',[' ']], 125 ['footnote_close',[]], 126 ]]], 127 ['cdata',[' Bar']], 128 ['p_close',[]], 129 ['document_end',[]], 130 ]; 131 $this->assertCalls($calls, $this->H->calls); 132 } 133 134 function testFootnoteHr() { 135 $this->P->addMode('hr',new Hr()); 136 $this->P->parse("Foo (( \n ---- \n )) Bar"); 137 $calls = [ 138 ['document_start',[]], 139 ['p_open',[]], 140 ['cdata',["\n".'Foo ']], 141 ['nest', [ [ 142 ['footnote_open',[]], 143 ['cdata',[' ']], 144 ['hr',[]], 145 ['cdata',["\n "]], 146 ['footnote_close',[]], 147 ]]], 148 ['cdata',[' Bar']], 149 ['p_close',[]], 150 ['document_end',[]], 151 ]; 152 $this->assertCalls($calls, $this->H->calls); 153 } 154 155 function testFootnoteCode() { 156 $this->P->addMode('code',new Code()); 157 $this->P->parse("Foo (( <code>Test</code> )) Bar"); 158 $calls = [ 159 ['document_start',[]], 160 ['p_open',[]], 161 ['cdata',["\n".'Foo ']], 162 ['nest', [ [ 163 ['footnote_open',[]], 164 ['cdata',[' ']], 165 ['code',['Test',null,null]], 166 ['cdata',[' ']], 167 ['footnote_close',[]], 168 ]]], 169 ['cdata',[' Bar']], 170 ['p_close',[]], 171 ['document_end',[]], 172 ]; 173 $this->assertCalls($calls, $this->H->calls); 174 } 175 176 function testFootnotePreformatted() { 177 $this->P->addMode('preformatted',new Preformatted()); 178 $this->P->parse("Foo (( \n Test\n )) Bar"); 179 $calls = [ 180 ['document_start',[]], 181 ['p_open',[]], 182 ['cdata',["\n".'Foo ']], 183 ['nest', [ [ 184 ['footnote_open',[]], 185 ['cdata',[' ']], 186 ['preformatted',['Test']], 187 ['cdata',[' ']], 188 ['footnote_close',[]], 189 ]]], 190 ['cdata',[' Bar']], 191 ['p_close',[]], 192 ['document_end',[]], 193 ]; 194 $this->assertCalls($calls, $this->H->calls); 195 } 196 197 function testFootnotePreformattedEol() { 198 $this->P->addMode('preformatted',new Preformatted()); 199 $this->P->addMode('eol',new Eol()); 200 $this->P->parse("Foo (( \n Test\n )) Bar"); 201 $calls = [ 202 ['document_start',[]], 203 ['p_open',[]], 204 ['cdata',['Foo ']], 205 ['nest', [ [ 206 ['footnote_open',[]], 207 ['cdata',[' ']], 208 ['preformatted',['Test']], 209 ['cdata',[' ']], 210 ['footnote_close',[]], 211 ]]], 212 ['cdata',[' Bar']], 213 ['p_close',[]], 214 ['document_end',[]], 215 ]; 216 217 $this->assertCalls($calls, $this->H->calls); 218 } 219 220 function testFootnoteUnformatted() { 221 $this->P->addMode('unformatted',new Unformatted()); 222 $this->P->parse("Foo (( <nowiki>Test</nowiki> )) Bar"); 223 $calls = [ 224 ['document_start',[]], 225 ['p_open',[]], 226 ['cdata',["\n".'Foo ']], 227 ['nest', [ [ 228 ['footnote_open',[]], 229 ['cdata',[' ']], 230 ['unformatted',['Test']], 231 ['cdata',[' ']], 232 ['footnote_close',[]], 233 ]]], 234 ['cdata',[' Bar']], 235 ['p_close',[]], 236 ['document_end',[]], 237 ]; 238 $this->assertCalls($calls, $this->H->calls); 239 } 240 241 function testFootnoteNotHeader() { 242 $this->P->addMode('unformatted',new Unformatted()); 243 $this->P->parse("Foo (( \n====Test====\n )) Bar"); 244 $calls = [ 245 ['document_start',[]], 246 ['p_open',[]], 247 ['cdata',["\n".'Foo ']], 248 ['nest', [ [ 249 ['footnote_open',[]], 250 ['cdata',[" \n====Test====\n "]], 251 ['footnote_close',[]], 252 ]]], 253 ['cdata',[' Bar']], 254 ['p_close',[]], 255 ['document_end',[]], 256 ]; 257 $this->assertCalls($calls, $this->H->calls); 258 } 259 260 function testFootnoteTable() { 261 $this->P->addMode('table',new Table()); 262 $this->P->parse("Foo (( 263| Row 0 Col 1 | Row 0 Col 2 | Row 0 Col 3 | 264| Row 1 Col 1 | Row 1 Col 2 | Row 1 Col 3 | 265 )) Bar"); 266 $calls = [ 267 ['document_start',[]], 268 ['p_open',[]], 269 ['cdata',["\n".'Foo ']], 270 ['nest', [ [ 271 ['footnote_open',[]], 272 ['table_open',[3, 2, 8]], 273 ['tablerow_open',[]], 274 ['tablecell_open',[1,'left',1]], 275 ['cdata',[' Row 0 Col 1 ']], 276 ['tablecell_close',[]], 277 ['tablecell_open',[1,'left',1]], 278 ['cdata',[' Row 0 Col 2 ']], 279 ['tablecell_close',[]], 280 ['tablecell_open',[1,'left',1]], 281 ['cdata',[' Row 0 Col 3 ']], 282 ['tablecell_close',[]], 283 ['tablerow_close',[]], 284 ['tablerow_open',[]], 285 ['tablecell_open',[1,'left',1]], 286 ['cdata',[' Row 1 Col 1 ']], 287 ['tablecell_close',[]], 288 ['tablecell_open',[1,'left',1]], 289 ['cdata',[' Row 1 Col 2 ']], 290 ['tablecell_close',[]], 291 ['tablecell_open',[1,'left',1]], 292 ['cdata',[' Row 1 Col 3 ']], 293 ['tablecell_close',[]], 294 ['tablerow_close',[]], 295 ['table_close',[123]], 296 ['cdata',[' ']], 297 ['footnote_close',[]], 298 ]]], 299 ['cdata',[' Bar']], 300 ['p_close',[]], 301 ['document_end',[]], 302 ]; 303 $this->assertCalls($calls, $this->H->calls); 304 } 305 306 function testFootnoteList() { 307 $this->P->addMode('listblock',new ListBlock()); 308 $this->P->parse("Foo (( 309 *A 310 * B 311 * C 312 )) Bar"); 313 $calls = [ 314 ['document_start',[]], 315 ['p_open',[]], 316 ['cdata',["\n".'Foo ']], 317 ['nest', [ [ 318 ['footnote_open',[]], 319 ['listu_open',[]], 320 ['listitem_open',[1,Lists::NODE]], 321 ['listcontent_open',[]], 322 ['cdata',["A"]], 323 ['listcontent_close',[]], 324 ['listu_open',[]], 325 ['listitem_open',[2]], 326 ['listcontent_open',[]], 327 ['cdata',[' B']], 328 ['listcontent_close',[]], 329 ['listitem_close',[]], 330 ['listu_close',[]], 331 ['listitem_close',[]], 332 ['listitem_open',[1]], 333 ['listcontent_open',[]], 334 ['cdata',[' C']], 335 ['listcontent_close',[]], 336 ['listitem_close',[]], 337 ['listu_close',[]], 338 ['cdata',[' ']], 339 ['footnote_close',[]], 340 ]]], 341 ['cdata',[' Bar']], 342 ['p_close',[]], 343 ['document_end',[]], 344 ]; 345 $this->assertCalls($calls, $this->H->calls); 346 } 347 348 function testFootnoteQuote() { 349 $this->P->addMode('quote',new Quote()); 350 $this->P->parse("Foo (( 351> def 352>>ghi 353 )) Bar"); 354 $calls = [ 355 ['document_start',[]], 356 ['p_open',[]], 357 ['cdata',["\n".'Foo ']], 358 ['nest', [ [ 359 ['footnote_open',[]], 360 ['quote_open',[]], 361 ['cdata',[" def"]], 362 ['quote_open',[]], 363 ['cdata',["ghi"]], 364 ['quote_close',[]], 365 ['quote_close',[]], 366 ['cdata',[' ']], 367 ['footnote_close',[]], 368 ]]], 369 ['cdata',[' Bar']], 370 ['p_close',[]], 371 ['document_end',[]], 372 ]; 373 374 $this->assertCalls($calls, $this->H->calls); 375 } 376 377 function testFootnoteNesting() { 378 $this->P->addMode('strong',new Strong()); 379 $this->P->parse("(( a ** (( b )) ** c ))"); 380 381 $calls = [ 382 ['document_start',[]], 383 ['p_open',[]], 384 ['cdata',["\n"]], 385 ['nest', [ [ 386 ['footnote_open',[]], 387 ['cdata',[' a ']], 388 ['strong_open',[]], 389 ['cdata',[' (( b ']], 390 ['footnote_close',[]], 391 ]]], 392 ['cdata',[" "]], 393 ['strong_close',[]], 394 ['cdata',[" c ))"]], 395 ['p_close',[]], 396 ['document_end',[]], 397 ]; 398 399 $this->assertCalls($calls, $this->H->calls); 400 } 401} 402