1<?php 2 3namespace dokuwiki\test\Parsing\ParserMode; 4 5use dokuwiki\Parsing\ParserMode\Acronym; 6use dokuwiki\Parsing\ParserMode\Deleted; 7use dokuwiki\Parsing\ParserMode\Emphasis; 8use dokuwiki\Parsing\ParserMode\Header; 9use dokuwiki\Parsing\ParserMode\Monospace; 10use dokuwiki\Parsing\ParserMode\Strong; 11use dokuwiki\Parsing\ParserMode\Subscript; 12use dokuwiki\Parsing\ParserMode\Superscript; 13use dokuwiki\Parsing\ParserMode\Underline; 14use dokuwiki\Parsing\ParserMode\Internallink; 15use dokuwiki\Parsing\ParserMode\Table; 16 17class I18nTest extends ParserTestBase 18{ 19 20 function testFormatting() { 21 $formats = [ 22 'strong' => new Strong(), 23 'emphasis' => new Emphasis(), 24 'underline' => new Underline(), 25 'monospace' => new Monospace(), 26 'subscript' => new Subscript(), 27 'superscript' => new Superscript(), 28 'deleted' => new Deleted(), 29 ]; 30 foreach ($formats as $name => $obj) { 31 $this->P->addMode($name, $obj); 32 } 33 $this->P->parse("I**ñ**t__ë__r//n//â<sup>t</sup>i<sub>ô</sub>n''à''liz<del>æ</del>tiøn"); 34 $calls = [ 35 ['document_start',[]], 36 ['p_open',[]], 37 ['cdata',["\nI"]], 38 ['strong_open',[]], 39 ['cdata',['ñ']], 40 ['strong_close',[]], 41 ['cdata',['t']], 42 ['underline_open',[]], 43 ['cdata',['ë']], 44 ['underline_close',[]], 45 ['cdata',['r']], 46 ['emphasis_open',[]], 47 ['cdata',['n']], 48 ['emphasis_close',[]], 49 ['cdata',['â']], 50 ['superscript_open',[]], 51 ['cdata',['t']], 52 ['superscript_close',[]], 53 ['cdata',['i']], 54 ['subscript_open',[]], 55 ['cdata',['ô']], 56 ['subscript_close',[]], 57 ['cdata',['n']], 58 ['monospace_open',[]], 59 ['cdata',['à']], 60 ['monospace_close',[]], 61 ['cdata',['liz']], 62 ['deleted_open',[]], 63 ['cdata',['æ']], 64 ['deleted_close',[]], 65 ['cdata',["tiøn"]], 66 ['p_close',[]], 67 ['document_end',[]], 68 ]; 69 $this->assertCalls($calls, $this->H->calls); 70 } 71 72 function testHeader() { 73 $this->P->addMode('header',new Header()); 74 $this->P->parse("Foo\n ==== Iñtërnâtiônàlizætiøn ==== \n Bar"); 75 $calls = [ 76 ['document_start',[]], 77 ['p_open',[]], 78 ['cdata',["\nFoo"]], 79 ['p_close',[]], 80 ['header',['Iñtërnâtiônàlizætiøn',3,5]], 81 ['section_open',[3]], 82 ['p_open',[]], 83 ['cdata',["\n Bar"]], 84 ['p_close',[]], 85 ['section_close',[]], 86 ['document_end',[]], 87 ]; 88 $this->assertCalls($calls, $this->H->calls); 89 } 90 91 function testTable() { 92 $this->P->addMode('table',new Table()); 93 $this->P->parse(' 94abc 95| Row 0 Col 1 | Iñtërnâtiônàlizætiøn | Row 0 Col 3 | 96| Row 1 Col 1 | Iñtërnâtiônàlizætiøn | Row 1 Col 3 | 97def'); 98 $calls = [ 99 ['document_start',[]], 100 ['p_open',[]], 101 ['cdata',["\n\nabc"]], 102 ['p_close',[]], 103 ['table_open',[3, 2, 6]], 104 ['tablerow_open',[]], 105 ['tablecell_open',[1,'left',1]], 106 ['cdata',[' Row 0 Col 1 ']], 107 ['tablecell_close',[]], 108 ['tablecell_open',[1,'left',1]], 109 ['cdata',[' Iñtërnâtiônàlizætiøn ']], 110 ['tablecell_close',[]], 111 ['tablecell_open',[1,'left',1]], 112 ['cdata',[' Row 0 Col 3 ']], 113 ['tablecell_close',[]], 114 ['tablerow_close',[]], 115 ['tablerow_open',[]], 116 ['tablecell_open',[1,'left',1]], 117 ['cdata',[' Row 1 Col 1 ']], 118 ['tablecell_close',[]], 119 ['tablecell_open',[1,'left',1]], 120 ['cdata',[' Iñtërnâtiônàlizætiøn ']], 121 ['tablecell_close',[]], 122 ['tablecell_open',[1,'left',1]], 123 ['cdata',[' Row 1 Col 3 ']], 124 ['tablecell_close',[]], 125 ['tablerow_close',[]], 126 ['table_close',[153]], 127 ['p_open',[]], 128 ['cdata',['def']], 129 ['p_close',[]], 130 ['document_end',[]], 131 ]; 132 $this->assertCalls($calls, $this->H->calls); 133 } 134 135 function testAcronym() { 136 $t = ['Iñtërnâtiônàlizætiøn']; 137 $this->P->addMode('acronym',new Acronym($t)); 138 $this->P->parse("Foo Iñtërnâtiônàlizætiøn Bar"); 139 $calls = [ 140 ['document_start',[]], 141 ['p_open',[]], 142 ['cdata',["\nFoo "]], 143 ['acronym',['Iñtërnâtiônàlizætiøn']], 144 ['cdata',[" Bar"]], 145 ['p_close',[]], 146 ['document_end',[]], 147 ]; 148 $this->assertCalls($calls, $this->H->calls); 149 } 150 151 function testInterwiki() { 152 $this->P->addMode('internallink',new InternalLink()); 153 $this->P->parse("Foo [[wp>Iñtërnâtiônàlizætiøn|Iñtërnâtiônàlizætiøn]] Bar"); 154 $calls = [ 155 ['document_start',[]], 156 ['p_open',[]], 157 ['cdata',["\n".'Foo ']], 158 ['interwikilink',['wp>Iñtërnâtiônàlizætiøn','Iñtërnâtiônàlizætiøn','wp','Iñtërnâtiônàlizætiøn']], 159 ['cdata',[' Bar']], 160 ['p_close',[]], 161 ['document_end',[]], 162 ]; 163 $this->assertCalls($calls, $this->H->calls); 164 } 165 166 function testInternalLink() { 167 $this->P->addMode('internallink',new InternalLink()); 168 $this->P->parse("Foo [[x:Iñtërnâtiônàlizætiøn:y:foo_bar:z|Iñtërnâtiônàlizætiøn]] Bar"); 169 $calls = [ 170 ['document_start',[]], 171 ['p_open',[]], 172 ['cdata',["\n".'Foo ']], 173 ['internallink',['x:Iñtërnâtiônàlizætiøn:y:foo_bar:z','Iñtërnâtiônàlizætiøn']], 174 ['cdata',[' Bar']], 175 ['p_close',[]], 176 ['document_end',[]], 177 ]; 178 $this->assertCalls($calls, $this->H->calls); 179 } 180 181} 182