2012-05-22 23:30:07 +00:00
|
|
|
|
<?php
|
|
|
|
|
|
|
2014-08-15 21:11:26 +00:00
|
|
|
|
/**
|
|
|
|
|
|
* @group Database
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2012-12-06 17:53:43 +00:00
|
|
|
|
class LinkerTest extends MediaWikiLangTestCase {
|
2012-05-22 23:30:07 +00:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @dataProvider provideCasesForUserLink
|
2013-03-11 03:16:28 +00:00
|
|
|
|
* @covers Linker::userLink
|
2012-05-22 23:30:07 +00:00
|
|
|
|
*/
|
2013-10-23 22:51:31 +00:00
|
|
|
|
public function testUserLink( $expected, $userId, $userName, $altUserName = false, $msg = '' ) {
|
2012-05-22 23:30:07 +00:00
|
|
|
|
$this->setMwGlobals( array(
|
|
|
|
|
|
'wgArticlePath' => '/wiki/$1',
|
2012-12-09 10:56:45 +00:00
|
|
|
|
'wgWellFormedXml' => true,
|
2013-02-14 11:22:13 +00:00
|
|
|
|
) );
|
2012-05-22 23:30:07 +00:00
|
|
|
|
|
|
|
|
|
|
$this->assertEquals( $expected,
|
|
|
|
|
|
Linker::userLink( $userId, $userName, $altUserName, $msg )
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2013-03-22 02:12:37 +00:00
|
|
|
|
public static function provideCasesForUserLink() {
|
2012-05-22 23:30:07 +00:00
|
|
|
|
# Format:
|
|
|
|
|
|
# - expected
|
|
|
|
|
|
# - userid
|
|
|
|
|
|
# - username
|
|
|
|
|
|
# - optional altUserName
|
|
|
|
|
|
# - optional message
|
|
|
|
|
|
return array(
|
|
|
|
|
|
|
|
|
|
|
|
### ANONYMOUS USER ########################################
|
|
|
|
|
|
array(
|
2014-04-24 10:05:52 +00:00
|
|
|
|
'<a href="/wiki/Special:Contributions/JohnDoe" '
|
|
|
|
|
|
. 'title="Special:Contributions/JohnDoe" '
|
|
|
|
|
|
. 'class="mw-userlink mw-anonuserlink">JohnDoe</a>',
|
2012-05-22 23:30:07 +00:00
|
|
|
|
0, 'JohnDoe', false,
|
|
|
|
|
|
),
|
|
|
|
|
|
array(
|
2014-04-24 10:05:52 +00:00
|
|
|
|
'<a href="/wiki/Special:Contributions/::1" '
|
|
|
|
|
|
. 'title="Special:Contributions/::1" '
|
|
|
|
|
|
. 'class="mw-userlink mw-anonuserlink">::1</a>',
|
2012-05-22 23:30:07 +00:00
|
|
|
|
0, '::1', false,
|
|
|
|
|
|
'Anonymous with pretty IPv6'
|
|
|
|
|
|
),
|
|
|
|
|
|
array(
|
2014-04-24 10:05:52 +00:00
|
|
|
|
'<a href="/wiki/Special:Contributions/0:0:0:0:0:0:0:1" '
|
|
|
|
|
|
. 'title="Special:Contributions/0:0:0:0:0:0:0:1" '
|
|
|
|
|
|
. 'class="mw-userlink mw-anonuserlink">::1</a>',
|
2012-05-22 23:30:07 +00:00
|
|
|
|
0, '0:0:0:0:0:0:0:1', false,
|
|
|
|
|
|
'Anonymous with almost pretty IPv6'
|
|
|
|
|
|
),
|
|
|
|
|
|
array(
|
2014-04-24 10:05:52 +00:00
|
|
|
|
'<a href="/wiki/Special:Contributions/0000:0000:0000:0000:0000:0000:0000:0001" '
|
|
|
|
|
|
. 'title="Special:Contributions/0000:0000:0000:0000:0000:0000:0000:0001" '
|
|
|
|
|
|
. 'class="mw-userlink mw-anonuserlink">::1</a>',
|
2012-05-22 23:30:07 +00:00
|
|
|
|
0, '0000:0000:0000:0000:0000:0000:0000:0001', false,
|
|
|
|
|
|
'Anonymous with full IPv6'
|
|
|
|
|
|
),
|
|
|
|
|
|
array(
|
2014-04-24 10:05:52 +00:00
|
|
|
|
'<a href="/wiki/Special:Contributions/::1" '
|
|
|
|
|
|
. 'title="Special:Contributions/::1" '
|
|
|
|
|
|
. 'class="mw-userlink mw-anonuserlink">AlternativeUsername</a>',
|
2012-05-22 23:30:07 +00:00
|
|
|
|
0, '::1', 'AlternativeUsername',
|
|
|
|
|
|
'Anonymous with pretty IPv6 and an alternative username'
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
|
|
# IPV4
|
|
|
|
|
|
array(
|
2014-04-24 10:05:52 +00:00
|
|
|
|
'<a href="/wiki/Special:Contributions/127.0.0.1" '
|
|
|
|
|
|
. 'title="Special:Contributions/127.0.0.1" '
|
|
|
|
|
|
. 'class="mw-userlink mw-anonuserlink">127.0.0.1</a>',
|
2012-05-22 23:30:07 +00:00
|
|
|
|
0, '127.0.0.1', false,
|
|
|
|
|
|
'Anonymous with IPv4'
|
|
|
|
|
|
),
|
|
|
|
|
|
array(
|
2014-04-24 10:05:52 +00:00
|
|
|
|
'<a href="/wiki/Special:Contributions/127.0.0.1" '
|
|
|
|
|
|
. 'title="Special:Contributions/127.0.0.1" '
|
|
|
|
|
|
. 'class="mw-userlink mw-anonuserlink">AlternativeUsername</a>',
|
2012-05-22 23:30:07 +00:00
|
|
|
|
0, '127.0.0.1', 'AlternativeUsername',
|
|
|
|
|
|
'Anonymous with IPv4 and an alternative username'
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
|
|
### Regular user ##########################################
|
|
|
|
|
|
# TODO!
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
2014-06-10 19:37:37 +00:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @dataProvider provideCasesForFormatComment
|
|
|
|
|
|
* @covers Linker::formatComment
|
|
|
|
|
|
* @covers Linker::formatAutocomments
|
|
|
|
|
|
* @covers Linker::formatLinksInComment
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function testFormatComment( $expected, $comment, $title = false, $local = false ) {
|
|
|
|
|
|
$this->setMwGlobals( array(
|
2014-06-24 07:39:17 +00:00
|
|
|
|
'wgScript' => '/wiki/index.php',
|
2014-06-10 19:37:37 +00:00
|
|
|
|
'wgArticlePath' => '/wiki/$1',
|
|
|
|
|
|
'wgWellFormedXml' => true,
|
2014-07-07 23:21:09 +00:00
|
|
|
|
'wgCapitalLinks' => true,
|
2014-06-10 19:37:37 +00:00
|
|
|
|
) );
|
|
|
|
|
|
|
|
|
|
|
|
if ( $title === false ) {
|
|
|
|
|
|
// We need a page title that exists
|
|
|
|
|
|
$title = Title::newFromText( 'Special:BlankPage' );
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
|
$expected,
|
|
|
|
|
|
Linker::formatComment( $comment, $title, $local )
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static function provideCasesForFormatComment() {
|
|
|
|
|
|
return array(
|
|
|
|
|
|
// Linker::formatComment
|
|
|
|
|
|
array(
|
|
|
|
|
|
'a<script>b',
|
|
|
|
|
|
'a<script>b',
|
|
|
|
|
|
),
|
|
|
|
|
|
array(
|
|
|
|
|
|
'a—b',
|
|
|
|
|
|
'a—b',
|
|
|
|
|
|
),
|
|
|
|
|
|
array(
|
|
|
|
|
|
"'''not bolded'''",
|
|
|
|
|
|
"'''not bolded'''",
|
|
|
|
|
|
),
|
|
|
|
|
|
// Linker::formatAutocomments
|
|
|
|
|
|
array(
|
|
|
|
|
|
'<a href="/wiki/Special:BlankPage#autocomment" title="Special:BlankPage">→</a><span dir="auto"><span class="autocomment">autocomment</span></span>',
|
|
|
|
|
|
"/* autocomment */",
|
|
|
|
|
|
),
|
|
|
|
|
|
array(
|
|
|
|
|
|
'<a href="/wiki/Special:BlankPage#linkie.3F" title="Special:BlankPage">→</a><span dir="auto"><span class="autocomment"><a href="/wiki/index.php?title=Linkie%3F&action=edit&redlink=1" class="new" title="Linkie? (page does not exist)">linkie?</a></span></span>',
|
|
|
|
|
|
"/* [[linkie?]] */",
|
|
|
|
|
|
),
|
|
|
|
|
|
array(
|
|
|
|
|
|
'<a href="/wiki/Special:BlankPage#autocomment" title="Special:BlankPage">→</a><span dir="auto"><span class="autocomment">autocomment: </span> post</span>',
|
|
|
|
|
|
"/* autocomment */ post",
|
|
|
|
|
|
),
|
|
|
|
|
|
array(
|
|
|
|
|
|
'pre <a href="/wiki/Special:BlankPage#autocomment" title="Special:BlankPage">→</a><span dir="auto"><span class="autocomment">autocomment</span></span>',
|
|
|
|
|
|
"pre /* autocomment */",
|
|
|
|
|
|
),
|
|
|
|
|
|
array(
|
|
|
|
|
|
'pre <a href="/wiki/Special:BlankPage#autocomment" title="Special:BlankPage">→</a><span dir="auto"><span class="autocomment">autocomment: </span> post</span>',
|
|
|
|
|
|
"pre /* autocomment */ post",
|
|
|
|
|
|
),
|
|
|
|
|
|
array(
|
2014-09-09 15:25:10 +00:00
|
|
|
|
'<a href="/wiki/Special:BlankPage#autocomment" title="Special:BlankPage">→</a><span dir="auto"><span class="autocomment">autocomment: </span> multiple? <a href="/wiki/Special:BlankPage#autocomment2" title="Special:BlankPage">→</a><span dir="auto"><span class="autocomment">autocomment2: </span> </span></span>',
|
2014-06-10 19:37:37 +00:00
|
|
|
|
"/* autocomment */ multiple? /* autocomment2 */ ",
|
|
|
|
|
|
),
|
2014-09-09 15:25:10 +00:00
|
|
|
|
array(
|
|
|
|
|
|
'<a href="/wiki/Special:BlankPage#autocomment_containing_.2F.2A" title="Special:BlankPage">→</a><span dir="auto"><span class="autocomment">autocomment containing /*: </span> T70361</span>',
|
|
|
|
|
|
"/* autocomment containing /* */ T70361"
|
|
|
|
|
|
),
|
2014-06-10 19:37:37 +00:00
|
|
|
|
array(
|
|
|
|
|
|
'<a href="#autocomment">→</a><span dir="auto"><span class="autocomment">autocomment</span></span>',
|
|
|
|
|
|
"/* autocomment */",
|
|
|
|
|
|
false, true
|
|
|
|
|
|
),
|
|
|
|
|
|
array(
|
|
|
|
|
|
'<span dir="auto"><span class="autocomment">autocomment</span></span>',
|
|
|
|
|
|
"/* autocomment */",
|
|
|
|
|
|
null
|
|
|
|
|
|
),
|
|
|
|
|
|
// Linker::formatLinksInComment
|
|
|
|
|
|
array(
|
|
|
|
|
|
'abc <a href="/wiki/index.php?title=Link&action=edit&redlink=1" class="new" title="Link (page does not exist)">link</a> def',
|
|
|
|
|
|
"abc [[link]] def",
|
|
|
|
|
|
),
|
|
|
|
|
|
array(
|
|
|
|
|
|
'abc <a href="/wiki/index.php?title=Link&action=edit&redlink=1" class="new" title="Link (page does not exist)">text</a> def',
|
|
|
|
|
|
"abc [[link|text]] def",
|
|
|
|
|
|
),
|
|
|
|
|
|
array(
|
|
|
|
|
|
'abc <a href="/wiki/Special:BlankPage" title="Special:BlankPage">Special:BlankPage</a> def',
|
|
|
|
|
|
"abc [[Special:BlankPage|]] def",
|
|
|
|
|
|
),
|
|
|
|
|
|
array(
|
|
|
|
|
|
'abc <a href="/wiki/index.php?title=%C4%84%C5%9B%C5%BC&action=edit&redlink=1" class="new" title="Ąśż (page does not exist)">ąśż</a> def',
|
|
|
|
|
|
"abc [[%C4%85%C5%9B%C5%BC]] def",
|
|
|
|
|
|
),
|
|
|
|
|
|
array(
|
|
|
|
|
|
'abc <a href="/wiki/Special:BlankPage#section" title="Special:BlankPage">#section</a> def',
|
|
|
|
|
|
"abc [[#section]] def",
|
|
|
|
|
|
),
|
|
|
|
|
|
array(
|
|
|
|
|
|
'abc <a href="/wiki/index.php?title=/subpage&action=edit&redlink=1" class="new" title="/subpage (page does not exist)">/subpage</a> def',
|
|
|
|
|
|
"abc [[/subpage]] def",
|
|
|
|
|
|
),
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
2012-05-22 23:30:07 +00:00
|
|
|
|
}
|