setMwGlobals( [
'wgArticlePath' => '/wiki/$1',
'wgWellFormedXml' => true,
] );
$this->assertEquals( $expected,
Linker::userLink( $userId, $userName, $altUserName, $msg )
);
}
public static function provideCasesForUserLink() {
# Format:
# - expected
# - userid
# - username
# - optional altUserName
# - optional message
return [
# ## ANONYMOUS USER ########################################
[
'JohnDoe',
0, 'JohnDoe', false,
],
[
'::1',
0, '::1', false,
'Anonymous with pretty IPv6'
],
[
'::1',
0, '0:0:0:0:0:0:0:1', false,
'Anonymous with almost pretty IPv6'
],
[
'::1',
0, '0000:0000:0000:0000:0000:0000:0000:0001', false,
'Anonymous with full IPv6'
],
[
'AlternativeUsername',
0, '::1', 'AlternativeUsername',
'Anonymous with pretty IPv6 and an alternative username'
],
# IPV4
[
'127.0.0.1',
0, '127.0.0.1', false,
'Anonymous with IPv4'
],
[
'AlternativeUsername',
0, '127.0.0.1', 'AlternativeUsername',
'Anonymous with IPv4 and an alternative username'
],
# ## Regular user ##########################################
# TODO!
];
}
/**
* @dataProvider provideCasesForFormatComment
* @covers Linker::formatComment
* @covers Linker::formatAutocomments
* @covers Linker::formatLinksInComment
*/
public function testFormatComment(
$expected, $comment, $title = false, $local = false, $wikiId = null
) {
$conf = new SiteConfiguration();
$conf->settings = [
'wgServer' => [
'enwiki' => '//en.example.org',
'dewiki' => '//de.example.org',
],
'wgArticlePath' => [
'enwiki' => '/w/$1',
'dewiki' => '/w/$1',
],
];
$conf->suffixes = [ 'wiki' ];
$this->setMwGlobals( [
'wgScript' => '/wiki/index.php',
'wgArticlePath' => '/wiki/$1',
'wgWellFormedXml' => true,
'wgCapitalLinks' => true,
'wgConf' => $conf,
] );
if ( $title === false ) {
// We need a page title that exists
$title = Title::newFromText( 'Special:BlankPage' );
}
$this->assertEquals(
$expected,
Linker::formatComment( $comment, $title, $local, $wikiId )
);
}
public function provideCasesForFormatComment() {
$wikiId = 'enwiki'; // $wgConf has a fake entry for this
// @codingStandardsIgnoreStart Generic.Files.LineLength
return [
// Linker::formatComment
[
'a<script>b',
'a */"
],
[
'→',
"/* autocomment */",
false, true
],
[
'',
"/* autocomment */",
null
],
[
'→',
"/* autocomment */",
false, false
],
[
'→',
"/* autocomment */",
false, false, $wikiId
],
// Linker::formatLinksInComment
[
'abc link def',
"abc [[link]] def",
],
[
'abc text def',
"abc [[link|text]] def",
],
[
'abc Special:BlankPage def',
"abc [[Special:BlankPage|]] def",
],
[
'abc ąśż def',
"abc [[%C4%85%C5%9B%C5%BC]] def",
],
[
'abc #section def',
"abc [[#section]] def",
],
[
'abc /subpage def',
"abc [[/subpage]] def",
],
[
'abc "evil!" def',
"abc [[\"evil!\"]] def",
],
[
'abc [[<script>very evil</script>]] def',
"abc [[]] def",
],
[
'abc [[|]] def',
"abc [[|]] def",
],
[
'abc link def',
"abc [[link]] def",
false, false
],
[
'abc link def',
"abc [[link]] def",
false, false, $wikiId
],
];
// @codingStandardsIgnoreEnd
}
/**
* @covers Linker::formatLinksInComment
* @dataProvider provideCasesForFormatLinksInComment
*/
public function testFormatLinksInComment( $expected, $input, $wiki ) {
$conf = new SiteConfiguration();
$conf->settings = [
'wgServer' => [
'enwiki' => '//en.example.org'
],
'wgArticlePath' => [
'enwiki' => '/w/$1',
],
];
$conf->suffixes = [ 'wiki' ];
$this->setMwGlobals( [
'wgScript' => '/wiki/index.php',
'wgArticlePath' => '/wiki/$1',
'wgWellFormedXml' => true,
'wgCapitalLinks' => true,
'wgConf' => $conf,
] );
$this->assertEquals(
$expected,
Linker::formatLinksInComment( $input, Title::newFromText( 'Special:BlankPage' ), false, $wiki )
);
}
public static function provideCasesForFormatLinksInComment() {
// @codingStandardsIgnoreStart Generic.Files.LineLength
return [
[
'foo bar Special:BlankPage',
'foo bar [[Special:BlankPage]]',
null,
],
[
'Foo\'bar',
"[[Foo'bar]]",
'enwiki',
],
[
'foo bar Special:BlankPage',
'foo bar [[Special:BlankPage]]',
'enwiki',
],
];
// @codingStandardsIgnoreEnd
}
}