Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F4138411
WfEscapeWikiTextTest.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
WfEscapeWikiTextTest.php
View Options
<?php
/**
* @group GlobalFunctions
* @covers ::wfEscapeWikiText
*/
class
WfEscapeWikiTextTest
extends
MediaWikiUnitTestCase
{
/**
* @dataProvider provideEscape
*/
public
function
testEscape
(
$input
,
$expected
)
{
// save global
global
$wgEnableMagicLinks
;
$old
=
$wgEnableMagicLinks
;
$wgEnableMagicLinks
=
[];
try
{
$actual
=
wfEscapeWikiText
(
$input
);
// Sanity check that the output can be decoded back to the input
// input as well.
$decoded
=
html_entity_decode
(
$actual
,
ENT_QUOTES
|
ENT_SUBSTITUTE
|
ENT_HTML5
);
$this
->
assertEquals
(
$decoded
,
(
string
)
$input
);
// And that the output was what we expected
$this
->
assertEquals
(
$expected
,
$actual
);
}
finally
{
// restore global
$wgEnableMagicLinks
=
$old
;
}
}
public
function
provideEscape
()
{
return
[
'null'
=>
[
null
,
''
,
],
'false'
=>
[
false
,
''
,
],
'empty string'
=>
[
''
,
''
,
],
'no escapes'
=>
[
'a'
,
'a'
,
],
'braces and brackets'
=>
[
'[[WikiLink]] {{Template}} <html>'
,
'[[WikiLink]] {{Template}} <html>'
,
],
'quotes'
=>
[
'"
\'
'
,
'"''
,
],
'tokens'
=>
[
'{| |- |+ !! ~~~~~ __FOO__'
,
'{| |- |+ !! ~~~~~ __FOO__'
,
],
'start of line'
=>
[
"* foo
\n
! bar
\n
# bat
\n
:baz
\n
pre
\n
----"
,
"* foo
\n
! bar
\n
# bat
\n
:baz
\n
 pre
\n
----"
,
],
'paragraph separators'
=>
[
"a
\n\n\n\n
b"
,
"a
\n
\n
b"
,
],
'language converter'
=>
[
'-{ foo ; bar }-'
,
'-{ foo ; bar }-'
,
],
'left-side context: |+'
=>
[
'+ foo + bar'
,
'+ foo + bar'
,
],
'left-side context: |-'
=>
[
'- foo - bar'
,
'- foo - bar'
,
],
'left-side context: __FOO__'
=>
[
'_FOO__'
,
'_FOO__'
,
],
'left-side context: ~~~'
=>
[
'~~ long string here'
,
'~~ long string here'
,
],
'left-side context: newlines'
=>
[
"
\n\n\n
Foo"
,
"
\n
Foo"
,
],
'right-side context: ~~~'
=>
[
'long string here ~~'
,
'long string here ~~'
,
],
'right-side context: __FOO__'
=>
[
'__FOO_'
,
'__FOO_'
,
],
'right-side context: newlines'
=>
[
"foo
\n\n\n
"
,
"foo
\n
"
,
],
// A single character input needs to be protected against both
// left-side context and right-side context.
'both-side context: +'
=>
[
// | + + (left side)
'+'
,
'+'
,
],
'both-side context: -'
=>
[
// | + - (left side)
'-'
,
'-'
,
],
'both-side context: _'
=>
[
// _ + _FOO as well as __FOO_ + _
'_'
,
'_'
,
],
'both-side context: ~'
=>
[
// ~ + ~~ as well as ~~ + ~
'~'
,
'~'
,
],
'both-side context:
\\
n'
=>
[
// \n + \n
"
\n
"
,
' '
,
],
'both-side context:
\\
t'
=>
[
// \n + \t + \n becomes paragraph break
"
\t
"
,
'	'
,
],
];
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Wed, Aug 19, 14:39 (3 w, 4 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
36/3d/eb24c844d9c2fba35b7c82f5bf11
Default Alt Text
WfEscapeWikiTextTest.php (2 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment