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