| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
class WfEscapeWikiTextTest extends MediaWikiUnitTestCase { |
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
public function testEscape( $input, $expected ) { |
| 12 |
|
| 13 |
global $wgEnableMagicLinks; |
| 14 |
$old = $wgEnableMagicLinks; |
| 15 |
$wgEnableMagicLinks = []; |
| 16 |
|
| 17 |
try { |
| 18 |
$actual = wfEscapeWikiText( $input ); |
| 19 |
|
| 20 |
|
| 21 |
$decoded = html_entity_decode( $actual, ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML5 ); |
| 22 |
$this->assertEquals( $decoded, (string)$input ); |
| 23 |
|
| 24 |
$this->assertEquals( $expected, $actual ); |
| 25 |
} finally { |
| 26 |
|
| 27 |
$wgEnableMagicLinks = $old; |
| 28 |
} |
| 29 |
} |
| 30 |
|
| 31 |
public function provideEscape() { |
| 32 |
return [ |
| 33 |
'null' => [ |
| 34 |
null, |
| 35 |
'', |
| 36 |
], |
| 37 |
'false' => [ |
| 38 |
false, |
| 39 |
'', |
| 40 |
], |
| 41 |
'empty string' => [ |
| 42 |
'', |
| 43 |
'', |
| 44 |
], |
| 45 |
'no escapes' => [ |
| 46 |
'a', |
| 47 |
'a', |
| 48 |
], |
| 49 |
'braces and brackets' => [ |
| 50 |
'[[WikiLink]] {{Template}} <html>', |
| 51 |
'[[WikiLink]] {{Template}} <html>', |
| 52 |
], |
| 53 |
'quotes' => [ |
| 54 |
'"\'', |
| 55 |
'"'', |
| 56 |
], |
| 57 |
'tokens' => [ |
| 58 |
'{| |- |+ !! ~~~~~ __FOO__', |
| 59 |
'{| |- |+ !! ~~~~~ __FOO__', |
| 60 |
], |
| 61 |
'start of line' => [ |
| 62 |
"* foo\n! bar\n# bat\n:baz\n pre\n----", |
| 63 |
"* foo\n! bar\n# bat\n:baz\n pre\n----", |
| 64 |
], |
| 65 |
'paragraph separators' => [ |
| 66 |
"a\n\n\n\nb", |
| 67 |
"a\n \n b", |
| 68 |
], |
| 69 |
'language converter' => [ |
| 70 |
'-{ foo ; bar }-', |
| 71 |
'-{ foo ; bar }-', |
| 72 |
], |
| 73 |
'left-side context: |+' => [ |
| 74 |
'+ foo + bar', |
| 75 |
'+ foo + bar', |
| 76 |
], |
| 77 |
'left-side context: |-' => [ |
| 78 |
'- foo - bar', |
| 79 |
'- foo - bar', |
| 80 |
], |
| 81 |
'left-side context: __FOO__' => [ |
| 82 |
'_FOO__', |
| 83 |
'_FOO__', |
| 84 |
], |
| 85 |
'left-side context: ~~~' => [ |
| 86 |
'~~ long string here', |
| 87 |
'~~ long string here', |
| 88 |
], |
| 89 |
'left-side context: newlines' => [ |
| 90 |
"\n\n\nFoo", |
| 91 |
" \n Foo", |
| 92 |
], |
| 93 |
'right-side context: ~~~' => [ |
| 94 |
'long string here ~~', |
| 95 |
'long string here ~~', |
| 96 |
], |
| 97 |
'right-side context: __FOO__' => [ |
| 98 |
'__FOO_', |
| 99 |
'__FOO_', |
| 100 |
], |
| 101 |
'right-side context: newlines' => [ |
| 102 |
"foo\n\n\n", |
| 103 |
"foo\n ", |
| 104 |
], |
| 105 |
|
| 106 |
|
| 107 |
'both-side context: +' => [ |
| 108 |
'+', |
| 109 |
'+', |
| 110 |
], |
| 111 |
'both-side context: -' => [ |
| 112 |
'-', |
| 113 |
'-', |
| 114 |
], |
| 115 |
'both-side context: _' => [ |
| 116 |
'_', |
| 117 |
'_', |
| 118 |
], |
| 119 |
'both-side context: ~' => [ |
| 120 |
'~', |
| 121 |
'~', |
| 122 |
], |
| 123 |
'both-side context: \\n' => [ |
| 124 |
"\n", |
| 125 |
' ', |
| 126 |
], |
| 127 |
'both-side context: \\t' => [ |
| 128 |
"\t", |
| 129 |
'	', |
| 130 |
], |
| 131 |
]; |
| 132 |
} |
| 133 |
} |