Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F7404544
RemoveRedLinksTest.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
RemoveRedLinksTest.php
View Options
<?php
namespace
Test\Parsoid\Html2Wt
;
use
PHPUnit\Framework\TestCase
;
use
Wikimedia\Parsoid\Html2Wt\RemoveRedLinks
;
use
Wikimedia\Parsoid\Mocks\MockEnv
;
use
Wikimedia\Parsoid\Utils\ContentUtils
;
use
Wikimedia\Parsoid\Utils\DOMCompat
;
/**
* @coversDefaultClass \Wikimedia\Parsoid\Html2Wt\RemoveRedLinks
*/
class
RemoveRedLinksTest
extends
TestCase
{
/**
* @covers ::run
* @dataProvider provideRedLinks
*/
public
function
testRun
(
string
$html
,
string
$expected
,
string
$message
)
{
$doc
=
ContentUtils
::
createAndLoadDocument
(
$html
,
[
'markNew'
=>
true
]
);
$body
=
DOMCompat
::
getBody
(
$doc
);
$env
=
new
MockEnv
(
[]
);
$removeRedLinks
=
new
RemoveRedLinks
(
$env
);
$removeRedLinks
->
run
(
$body
);
$actual
=
ContentUtils
::
ppToXML
(
$body
,
[
'discardDataParsoid'
=>
true
,
'innerXML'
=>
true
]
);
$this
->
assertEquals
(
$expected
,
$actual
,
$message
);
}
public
function
provideRedLinks
():
array
{
return
[
[
'<a href="./Hello" rel="mw:WikiLink">Hello</a>'
,
'<a href="./Hello" rel="mw:WikiLink">Hello</a>'
,
'No redlink'
],
[
'<a href="./Hello?action=edit&redlink=1" rel="mw:WikiLink" class="new">Hello</a>'
,
'<a href="./Hello" rel="mw:WikiLink" class="new">Hello</a>'
,
'Redlink with ./ title syntax'
],
[
'<a href="/w/index.php?title=Hello&action=edit&redlink=1" rel="mw:WikiLink" class="new">Hello</a>'
,
'<a href="/w/index.php?title=Hello" rel="mw:WikiLink" class="new">Hello</a>'
,
'Redlink with index.php? title syntax'
],
[
'<a href="/w/index.php?action=edit&redlink=1&title=Hello" rel="mw:WikiLink" class="new">Hello</a>'
,
'<a href="/w/index.php?title=Hello" rel="mw:WikiLink" class="new">Hello</a>'
,
'Redlink with index.php? title syntax in another order'
],
[
'<a href="./Hello?action=edit&redlink=1" rel="mw:WikiLink" class="new">Hello</a>'
,
'<a href="./Hello" rel="mw:WikiLink" class="new">Hello</a>'
,
'Redlink with ./ title syntax'
],
[
'<a href="./Hello?action=edit&redlink=1" class="new">Hello</a>'
,
'<a href="./Hello?action=edit&redlink=1" class="new">Hello</a>'
,
'Not a wikilink'
],
[
'<p><a href="./Hello?action=edit&redlink=1" rel="mw:WikiLink" class="new">Hello</a></p>'
.
'<p><a href="./Hello2?action=edit&redlink=1" rel="mw:WikiLink" class="new">Hello2</a></p>'
,
'<p><a href="./Hello" rel="mw:WikiLink" class="new">Hello</a></p>'
.
'<p><a href="./Hello2" rel="mw:WikiLink" class="new">Hello2</a></p>'
,
'Two redlinks'
],
[
'<a href="./Hello?action=edit&redlink=1#fragment" rel="mw:WikiLink" class="new">Hello</a>'
,
'<a href="./Hello#fragment" rel="mw:WikiLink" class="new">Hello</a>'
,
'Redlink with fragment'
],
[
'<a href="./Hello?action=edit&redlink=1#fragment?" rel="mw:WikiLink" class="new">Hello</a>'
,
'<a href="./Hello#fragment?" rel="mw:WikiLink" class="new">Hello</a>'
,
'Redlink with fragment with a question mark'
],
[
'<a href="./Hello#fragment?" rel="mw:WikiLink" class="new">Hello</a>'
,
'<a href="./Hello#fragment?" rel="mw:WikiLink" class="new">Hello</a>'
,
'Not a redlink, with fragment with a question mark'
],
// The code that allows for the creation of such an URL should be fixed; in the
// meantime we still want to avoid breaking links that may still cached.
[
'<a href="./Hello#fragment?action=edit&redlink=1" rel="mw:WikiLink" class="new">Hello</a>'
,
'<a href="./Hello#fragment" rel="mw:WikiLink" class="new">Hello</a>'
,
'Redlink with buggy fragment'
],
[
'<a href="./Hello?action=edit&redlink=1#fragment?action=edit&redlink=1" '
.
'rel="mw:WikiLink" class="new">Hello</a>'
,
'<a href="./Hello#fragment?action=edit&redlink=1" rel="mw:WikiLink" class="new">Hello</a>'
,
'Redlink with a fragment containing action=edit&redlink=1'
],
[
'<a href="./Hello?action=edit&redlink=1" rel="mw:WikiLink" class="new">Hello</a>'
,
'<a href="./Hello" rel="mw:WikiLink" class="new">Hello</a>'
,
'Redlink with escaped &'
],
];
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sat, Nov 21, 19:14 (1 d, 1 h)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
dc/54/f758019866982bb07ae3b797d817
Default Alt Text
RemoveRedLinksTest.php (3 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment