1*504c13e8SAndreas Gohr<?php 2*504c13e8SAndreas Gohr 3*504c13e8SAndreas Gohrnamespace dokuwiki\test\Parsing\ParserMode; 4*504c13e8SAndreas Gohr 5*504c13e8SAndreas Gohruse dokuwiki\Parsing\ParserMode\Acronym; 6*504c13e8SAndreas Gohruse dokuwiki\Parsing\ParserMode\Entity; 7*504c13e8SAndreas Gohruse dokuwiki\Parsing\ParserMode\Hr; 8*504c13e8SAndreas Gohruse dokuwiki\Parsing\ParserMode\Multiplyentity; 9*504c13e8SAndreas Gohruse dokuwiki\Parsing\ParserMode\Smiley; 10*504c13e8SAndreas Gohruse dokuwiki\Parsing\ParserMode\Wordblock; 11*504c13e8SAndreas Gohr 12*504c13e8SAndreas Gohrclass ReplacementsTest extends ParserTestBase 13*504c13e8SAndreas Gohr{ 14*504c13e8SAndreas Gohr 15*504c13e8SAndreas Gohr function testSingleAcronym() { 16*504c13e8SAndreas Gohr $this->P->addMode('acronym',new Acronym(['FOOBAR'])); 17*504c13e8SAndreas Gohr $this->P->parse('abc FOOBAR xyz'); 18*504c13e8SAndreas Gohr $calls = [ 19*504c13e8SAndreas Gohr ['document_start',[]], 20*504c13e8SAndreas Gohr ['p_open',[]], 21*504c13e8SAndreas Gohr ['cdata',["\n".'abc ']], 22*504c13e8SAndreas Gohr ['acronym',['FOOBAR']], 23*504c13e8SAndreas Gohr ['cdata',[' xyz']], 24*504c13e8SAndreas Gohr ['p_close',[]], 25*504c13e8SAndreas Gohr ['document_end',[]], 26*504c13e8SAndreas Gohr ]; 27*504c13e8SAndreas Gohr $this->assertCalls($calls, $this->H->calls); 28*504c13e8SAndreas Gohr } 29*504c13e8SAndreas Gohr 30*504c13e8SAndreas Gohr function testAlmostAnAcronym() { 31*504c13e8SAndreas Gohr $this->P->addMode('acronym',new Acronym(['FOOBAR'])); 32*504c13e8SAndreas Gohr $this->P->parse('abcFOOBARxyz'); 33*504c13e8SAndreas Gohr $calls = [ 34*504c13e8SAndreas Gohr ['document_start',[]], 35*504c13e8SAndreas Gohr ['p_open',[]], 36*504c13e8SAndreas Gohr ['cdata',["\n".'abcFOOBARxyz']], 37*504c13e8SAndreas Gohr ['p_close',[]], 38*504c13e8SAndreas Gohr ['document_end',[]], 39*504c13e8SAndreas Gohr ]; 40*504c13e8SAndreas Gohr $this->assertCalls($calls, $this->H->calls); 41*504c13e8SAndreas Gohr } 42*504c13e8SAndreas Gohr 43*504c13e8SAndreas Gohr function testPickAcronymCorrectly() { 44*504c13e8SAndreas Gohr $this->P->addMode('acronym',new Acronym(['FOO'])); 45*504c13e8SAndreas Gohr $this->P->parse('FOOBAR FOO'); 46*504c13e8SAndreas Gohr $calls = [ 47*504c13e8SAndreas Gohr ['document_start',[]], 48*504c13e8SAndreas Gohr ['p_open',[]], 49*504c13e8SAndreas Gohr ['cdata',["\n".'FOOBAR ']], 50*504c13e8SAndreas Gohr ['acronym',['FOO']], 51*504c13e8SAndreas Gohr ['cdata',['']], 52*504c13e8SAndreas Gohr ['p_close',[]], 53*504c13e8SAndreas Gohr ['document_end',[]], 54*504c13e8SAndreas Gohr ]; 55*504c13e8SAndreas Gohr $this->assertCalls($calls, $this->H->calls); 56*504c13e8SAndreas Gohr } 57*504c13e8SAndreas Gohr 58*504c13e8SAndreas Gohr function testMultipleAcronyms() { 59*504c13e8SAndreas Gohr $this->P->addMode('acronym',new Acronym(['FOO','BAR'])); 60*504c13e8SAndreas Gohr $this->P->parse('abc FOO def BAR xyz'); 61*504c13e8SAndreas Gohr $calls = [ 62*504c13e8SAndreas Gohr ['document_start',[]], 63*504c13e8SAndreas Gohr ['p_open',[]], 64*504c13e8SAndreas Gohr ['cdata',["\n".'abc ']], 65*504c13e8SAndreas Gohr ['acronym',['FOO']], 66*504c13e8SAndreas Gohr ['cdata',[' def ']], 67*504c13e8SAndreas Gohr ['acronym',['BAR']], 68*504c13e8SAndreas Gohr ['cdata',[' xyz']], 69*504c13e8SAndreas Gohr ['p_close',[]], 70*504c13e8SAndreas Gohr ['document_end',[]], 71*504c13e8SAndreas Gohr ]; 72*504c13e8SAndreas Gohr $this->assertCalls($calls, $this->H->calls); 73*504c13e8SAndreas Gohr } 74*504c13e8SAndreas Gohr 75*504c13e8SAndreas Gohr function testMultipleAcronymsWithSubset1() { 76*504c13e8SAndreas Gohr $this->P->addMode('acronym',new Acronym(['FOO','A.FOO','FOO.1','A.FOO.1'])); 77*504c13e8SAndreas Gohr $this->P->parse('FOO A.FOO FOO.1 A.FOO.1'); 78*504c13e8SAndreas Gohr $calls = [ 79*504c13e8SAndreas Gohr ['document_start',[]], 80*504c13e8SAndreas Gohr ['p_open',[]], 81*504c13e8SAndreas Gohr ['cdata',["\n"]], 82*504c13e8SAndreas Gohr ['acronym',['FOO']], 83*504c13e8SAndreas Gohr ['cdata',[" "]], 84*504c13e8SAndreas Gohr ['acronym',['A.FOO']], 85*504c13e8SAndreas Gohr ['cdata',[" "]], 86*504c13e8SAndreas Gohr ['acronym',['FOO.1']], 87*504c13e8SAndreas Gohr ['cdata',[" "]], 88*504c13e8SAndreas Gohr ['acronym',['A.FOO.1']], 89*504c13e8SAndreas Gohr ['cdata',['']], 90*504c13e8SAndreas Gohr ['p_close',[]], 91*504c13e8SAndreas Gohr ['document_end',[]], 92*504c13e8SAndreas Gohr ]; 93*504c13e8SAndreas Gohr $this->assertCalls($calls, $this->H->calls); 94*504c13e8SAndreas Gohr } 95*504c13e8SAndreas Gohr 96*504c13e8SAndreas Gohr function testMultipleAcronymsWithSubset2() { 97*504c13e8SAndreas Gohr $this->P->addMode('acronym',new Acronym(['A.FOO.1','FOO.1','A.FOO','FOO'])); 98*504c13e8SAndreas Gohr $this->P->parse('FOO A.FOO FOO.1 A.FOO.1'); 99*504c13e8SAndreas Gohr $calls = [ 100*504c13e8SAndreas Gohr ['document_start',[]], 101*504c13e8SAndreas Gohr ['p_open',[]], 102*504c13e8SAndreas Gohr ['cdata',["\n"]], 103*504c13e8SAndreas Gohr ['acronym',['FOO']], 104*504c13e8SAndreas Gohr ['cdata',[" "]], 105*504c13e8SAndreas Gohr ['acronym',['A.FOO']], 106*504c13e8SAndreas Gohr ['cdata',[" "]], 107*504c13e8SAndreas Gohr ['acronym',['FOO.1']], 108*504c13e8SAndreas Gohr ['cdata',[" "]], 109*504c13e8SAndreas Gohr ['acronym',['A.FOO.1']], 110*504c13e8SAndreas Gohr ['cdata',['']], 111*504c13e8SAndreas Gohr ['p_close',[]], 112*504c13e8SAndreas Gohr ['document_end',[]], 113*504c13e8SAndreas Gohr ]; 114*504c13e8SAndreas Gohr $this->assertCalls($calls, $this->H->calls); 115*504c13e8SAndreas Gohr } 116*504c13e8SAndreas Gohr 117*504c13e8SAndreas Gohr function testSingleSmileyFail() { 118*504c13e8SAndreas Gohr $this->P->addMode('smiley',new Smiley([':-)'])); 119*504c13e8SAndreas Gohr $this->P->parse('abc:-)xyz'); 120*504c13e8SAndreas Gohr $calls = [ 121*504c13e8SAndreas Gohr ['document_start',[]], 122*504c13e8SAndreas Gohr ['p_open',[]], 123*504c13e8SAndreas Gohr ['cdata',["\nabc:-)xyz"]], 124*504c13e8SAndreas Gohr ['p_close',[]], 125*504c13e8SAndreas Gohr ['document_end',[]], 126*504c13e8SAndreas Gohr ]; 127*504c13e8SAndreas Gohr $this->assertCalls($calls, $this->H->calls); 128*504c13e8SAndreas Gohr } 129*504c13e8SAndreas Gohr 130*504c13e8SAndreas Gohr function testSingleSmiley() { 131*504c13e8SAndreas Gohr $this->P->addMode('smiley',new Smiley([':-)'])); 132*504c13e8SAndreas Gohr $this->P->parse('abc :-) xyz'); 133*504c13e8SAndreas Gohr $calls = [ 134*504c13e8SAndreas Gohr ['document_start',[]], 135*504c13e8SAndreas Gohr ['p_open',[]], 136*504c13e8SAndreas Gohr ['cdata',["\n".'abc ']], 137*504c13e8SAndreas Gohr ['smiley',[':-)']], 138*504c13e8SAndreas Gohr ['cdata',[' xyz']], 139*504c13e8SAndreas Gohr ['p_close',[]], 140*504c13e8SAndreas Gohr ['document_end',[]], 141*504c13e8SAndreas Gohr ]; 142*504c13e8SAndreas Gohr $this->assertCalls($calls, $this->H->calls); 143*504c13e8SAndreas Gohr } 144*504c13e8SAndreas Gohr 145*504c13e8SAndreas Gohr function testMultipleSmileysFail() { 146*504c13e8SAndreas Gohr $this->P->addMode('smiley',new Smiley([':-)','^_^'])); 147*504c13e8SAndreas Gohr $this->P->parse('abc:-)x^_^yz'); 148*504c13e8SAndreas Gohr $calls = [ 149*504c13e8SAndreas Gohr ['document_start',[]], 150*504c13e8SAndreas Gohr ['p_open',[]], 151*504c13e8SAndreas Gohr ['cdata',["\nabc:-)x^_^yz"]], 152*504c13e8SAndreas Gohr ['p_close',[]], 153*504c13e8SAndreas Gohr ['document_end',[]], 154*504c13e8SAndreas Gohr ]; 155*504c13e8SAndreas Gohr $this->assertCalls($calls, $this->H->calls); 156*504c13e8SAndreas Gohr } 157*504c13e8SAndreas Gohr 158*504c13e8SAndreas Gohr function testMultipleSmileys() { 159*504c13e8SAndreas Gohr $this->P->addMode('smiley',new Smiley([':-)','^_^'])); 160*504c13e8SAndreas Gohr $this->P->parse('abc :-) x ^_^ yz'); 161*504c13e8SAndreas Gohr $calls = [ 162*504c13e8SAndreas Gohr ['document_start',[]], 163*504c13e8SAndreas Gohr ['p_open',[]], 164*504c13e8SAndreas Gohr ['cdata',["\n".'abc ']], 165*504c13e8SAndreas Gohr ['smiley',[':-)']], 166*504c13e8SAndreas Gohr ['cdata',[' x ']], 167*504c13e8SAndreas Gohr ['smiley',['^_^']], 168*504c13e8SAndreas Gohr ['cdata',[' yz']], 169*504c13e8SAndreas Gohr ['p_close',[]], 170*504c13e8SAndreas Gohr ['document_end',[]], 171*504c13e8SAndreas Gohr ]; 172*504c13e8SAndreas Gohr $this->assertCalls($calls, $this->H->calls); 173*504c13e8SAndreas Gohr } 174*504c13e8SAndreas Gohr 175*504c13e8SAndreas Gohr function testBackslashSmileyFail() { 176*504c13e8SAndreas Gohr $this->P->addMode('smiley',new Smiley([':-\\\\'])); 177*504c13e8SAndreas Gohr $this->P->parse('abc:-\\\xyz'); 178*504c13e8SAndreas Gohr $calls = [ 179*504c13e8SAndreas Gohr ['document_start',[]], 180*504c13e8SAndreas Gohr ['p_open',[]], 181*504c13e8SAndreas Gohr ['cdata',["\nabc".':-\\\\'."xyz"]], 182*504c13e8SAndreas Gohr ['p_close',[]], 183*504c13e8SAndreas Gohr ['document_end',[]], 184*504c13e8SAndreas Gohr ]; 185*504c13e8SAndreas Gohr $this->assertCalls($calls, $this->H->calls); 186*504c13e8SAndreas Gohr } 187*504c13e8SAndreas Gohr 188*504c13e8SAndreas Gohr function testBackslashSmiley() { 189*504c13e8SAndreas Gohr $this->P->addMode('smiley',new Smiley([':-\\\\'])); 190*504c13e8SAndreas Gohr $this->P->parse('abc :-\\\ xyz'); 191*504c13e8SAndreas Gohr $calls = [ 192*504c13e8SAndreas Gohr ['document_start',[]], 193*504c13e8SAndreas Gohr ['p_open',[]], 194*504c13e8SAndreas Gohr ['cdata',["\n".'abc ']], 195*504c13e8SAndreas Gohr ['smiley',[':-\\\\']], 196*504c13e8SAndreas Gohr ['cdata',[' xyz']], 197*504c13e8SAndreas Gohr ['p_close',[]], 198*504c13e8SAndreas Gohr ['document_end',[]], 199*504c13e8SAndreas Gohr ]; 200*504c13e8SAndreas Gohr $this->assertCalls($calls, $this->H->calls); 201*504c13e8SAndreas Gohr } 202*504c13e8SAndreas Gohr 203*504c13e8SAndreas Gohr function testSingleWordblock() { 204*504c13e8SAndreas Gohr $this->P->addMode('wordblock',new Wordblock(['CAT'])); 205*504c13e8SAndreas Gohr $this->P->parse('abc CAT xyz'); 206*504c13e8SAndreas Gohr $calls = [ 207*504c13e8SAndreas Gohr ['document_start',[]], 208*504c13e8SAndreas Gohr ['p_open',[]], 209*504c13e8SAndreas Gohr ['cdata',["\n".'abc ']], 210*504c13e8SAndreas Gohr ['wordblock',['CAT']], 211*504c13e8SAndreas Gohr ['cdata',[' xyz']], 212*504c13e8SAndreas Gohr ['p_close',[]], 213*504c13e8SAndreas Gohr ['document_end',[]], 214*504c13e8SAndreas Gohr ]; 215*504c13e8SAndreas Gohr $this->assertCalls($calls, $this->H->calls); 216*504c13e8SAndreas Gohr } 217*504c13e8SAndreas Gohr 218*504c13e8SAndreas Gohr function testWordblockCase() { 219*504c13e8SAndreas Gohr $this->P->addMode('wordblock',new Wordblock(['CAT'])); 220*504c13e8SAndreas Gohr $this->P->parse('abc cat xyz'); 221*504c13e8SAndreas Gohr $calls = [ 222*504c13e8SAndreas Gohr ['document_start',[]], 223*504c13e8SAndreas Gohr ['p_open',[]], 224*504c13e8SAndreas Gohr ['cdata',["\n".'abc ']], 225*504c13e8SAndreas Gohr ['wordblock',['cat']], 226*504c13e8SAndreas Gohr ['cdata',[' xyz']], 227*504c13e8SAndreas Gohr ['p_close',[]], 228*504c13e8SAndreas Gohr ['document_end',[]], 229*504c13e8SAndreas Gohr ]; 230*504c13e8SAndreas Gohr $this->assertCalls($calls, $this->H->calls); 231*504c13e8SAndreas Gohr } 232*504c13e8SAndreas Gohr 233*504c13e8SAndreas Gohr function testMultipleWordblock() { 234*504c13e8SAndreas Gohr $this->P->addMode('wordblock',new Wordblock(['CAT','dog'])); 235*504c13e8SAndreas Gohr $this->P->parse('abc cat x DOG yz'); 236*504c13e8SAndreas Gohr $calls = [ 237*504c13e8SAndreas Gohr ['document_start',[]], 238*504c13e8SAndreas Gohr ['p_open',[]], 239*504c13e8SAndreas Gohr ['cdata',["\n".'abc ']], 240*504c13e8SAndreas Gohr ['wordblock',['cat']], 241*504c13e8SAndreas Gohr ['cdata',[' x ']], 242*504c13e8SAndreas Gohr ['wordblock',['DOG']], 243*504c13e8SAndreas Gohr ['cdata',[' yz']], 244*504c13e8SAndreas Gohr ['p_close',[]], 245*504c13e8SAndreas Gohr ['document_end',[]], 246*504c13e8SAndreas Gohr ]; 247*504c13e8SAndreas Gohr $this->assertCalls($calls, $this->H->calls); 248*504c13e8SAndreas Gohr } 249*504c13e8SAndreas Gohr 250*504c13e8SAndreas Gohr function testSingleEntity() { 251*504c13e8SAndreas Gohr $this->P->addMode('entity',new Entity(['->'])); 252*504c13e8SAndreas Gohr $this->P->parse('x -> y'); 253*504c13e8SAndreas Gohr $calls = [ 254*504c13e8SAndreas Gohr ['document_start',[]], 255*504c13e8SAndreas Gohr ['p_open',[]], 256*504c13e8SAndreas Gohr ['cdata',["\n".'x ']], 257*504c13e8SAndreas Gohr ['entity',['->']], 258*504c13e8SAndreas Gohr ['cdata',[' y']], 259*504c13e8SAndreas Gohr ['p_close',[]], 260*504c13e8SAndreas Gohr ['document_end',[]], 261*504c13e8SAndreas Gohr ]; 262*504c13e8SAndreas Gohr $this->assertCalls($calls, $this->H->calls); 263*504c13e8SAndreas Gohr } 264*504c13e8SAndreas Gohr 265*504c13e8SAndreas Gohr function testMultipleEntities() { 266*504c13e8SAndreas Gohr $this->P->addMode('entity',new Entity(['->','<-'])); 267*504c13e8SAndreas Gohr $this->P->parse('x -> y <- z'); 268*504c13e8SAndreas Gohr $calls = [ 269*504c13e8SAndreas Gohr ['document_start',[]], 270*504c13e8SAndreas Gohr ['p_open',[]], 271*504c13e8SAndreas Gohr ['cdata',["\n".'x ']], 272*504c13e8SAndreas Gohr ['entity',['->']], 273*504c13e8SAndreas Gohr ['cdata',[' y ']], 274*504c13e8SAndreas Gohr ['entity',['<-']], 275*504c13e8SAndreas Gohr ['cdata',[' z']], 276*504c13e8SAndreas Gohr ['p_close',[]], 277*504c13e8SAndreas Gohr ['document_end',[]], 278*504c13e8SAndreas Gohr ]; 279*504c13e8SAndreas Gohr $this->assertCalls($calls, $this->H->calls); 280*504c13e8SAndreas Gohr } 281*504c13e8SAndreas Gohr 282*504c13e8SAndreas Gohr function testMultiplyEntity() { 283*504c13e8SAndreas Gohr $this->P->addMode('multiplyentity',new Multiplyentity()); 284*504c13e8SAndreas Gohr $this->P->parse('Foo 10x20 Bar'); 285*504c13e8SAndreas Gohr $calls = [ 286*504c13e8SAndreas Gohr ['document_start',[]], 287*504c13e8SAndreas Gohr ['p_open',[]], 288*504c13e8SAndreas Gohr ['cdata',["\n".'Foo ']], 289*504c13e8SAndreas Gohr ['multiplyentity',[10,20]], 290*504c13e8SAndreas Gohr ['cdata',[' Bar']], 291*504c13e8SAndreas Gohr ['p_close',[]], 292*504c13e8SAndreas Gohr ['document_end',[]], 293*504c13e8SAndreas Gohr ]; 294*504c13e8SAndreas Gohr $this->assertCalls($calls, $this->H->calls); 295*504c13e8SAndreas Gohr } 296*504c13e8SAndreas Gohr 297*504c13e8SAndreas Gohr function testMultiplyEntityHex() { 298*504c13e8SAndreas Gohr $this->P->addMode('multiplyentity',new Multiplyentity()); 299*504c13e8SAndreas Gohr $this->P->parse('Foo 0x123 Bar'); 300*504c13e8SAndreas Gohr $calls = [ 301*504c13e8SAndreas Gohr ['document_start',[]], 302*504c13e8SAndreas Gohr ['p_open',[]], 303*504c13e8SAndreas Gohr ['cdata',["\n".'Foo 0x123 Bar']], 304*504c13e8SAndreas Gohr ['p_close',[]], 305*504c13e8SAndreas Gohr ['document_end',[]], 306*504c13e8SAndreas Gohr ]; 307*504c13e8SAndreas Gohr $this->assertCalls($calls, $this->H->calls); 308*504c13e8SAndreas Gohr } 309*504c13e8SAndreas Gohr 310*504c13e8SAndreas Gohr function testHR() { 311*504c13e8SAndreas Gohr $this->P->addMode('hr',new Hr()); 312*504c13e8SAndreas Gohr $this->P->parse("Foo \n ---- \n Bar"); 313*504c13e8SAndreas Gohr $calls = [ 314*504c13e8SAndreas Gohr ['document_start',[]], 315*504c13e8SAndreas Gohr ['p_open',[]], 316*504c13e8SAndreas Gohr ['cdata',["\n".'Foo ']], 317*504c13e8SAndreas Gohr ['p_close',[]], 318*504c13e8SAndreas Gohr ['hr',[]], 319*504c13e8SAndreas Gohr ['p_open',[]], 320*504c13e8SAndreas Gohr ['cdata',["\n Bar"]], 321*504c13e8SAndreas Gohr ['p_close',[]], 322*504c13e8SAndreas Gohr ['document_end',[]], 323*504c13e8SAndreas Gohr ]; 324*504c13e8SAndreas Gohr $this->assertCalls($calls, $this->H->calls); 325*504c13e8SAndreas Gohr } 326*504c13e8SAndreas Gohr 327*504c13e8SAndreas Gohr function testHREol() { 328*504c13e8SAndreas Gohr $this->P->addMode('hr',new Hr()); 329*504c13e8SAndreas Gohr $this->P->parse("Foo \n----\n Bar"); 330*504c13e8SAndreas Gohr $calls = [ 331*504c13e8SAndreas Gohr ['document_start',[]], 332*504c13e8SAndreas Gohr ['p_open',[]], 333*504c13e8SAndreas Gohr ['cdata',["\n".'Foo ']], 334*504c13e8SAndreas Gohr ['p_close',[]], 335*504c13e8SAndreas Gohr ['hr',[]], 336*504c13e8SAndreas Gohr ['p_open',[]], 337*504c13e8SAndreas Gohr ['cdata',["\n Bar"]], 338*504c13e8SAndreas Gohr ['p_close',[]], 339*504c13e8SAndreas Gohr ['document_end',[]], 340*504c13e8SAndreas Gohr ]; 341*504c13e8SAndreas Gohr $this->assertCalls($calls, $this->H->calls); 342*504c13e8SAndreas Gohr } 343*504c13e8SAndreas Gohr} 344