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 array( // Linker::formatComment array( 'a<script>b', 'a */" ), array( 'autocomment', "/* autocomment */", false, true ), array( '‎autocomment', "/* autocomment */", null ), array( 'autocomment', "/* autocomment */", false, false ), array( 'autocomment', "/* autocomment */", false, false, $wikiId ), // Linker::formatLinksInComment array( 'abc link def', "abc [[link]] def", ), array( 'abc text def', "abc [[link|text]] def", ), array( 'abc Special:BlankPage def', "abc [[Special:BlankPage|]] def", ), array( 'abc ąśż def', "abc [[%C4%85%C5%9B%C5%BC]] def", ), array( 'abc #section def', "abc [[#section]] def", ), array( 'abc /subpage def', "abc [[/subpage]] def", ), array( 'abc "evil!" def', "abc [[\"evil!\"]] def", ), array( 'abc [[<script>very evil</script>]] def', "abc [[]] def", ), array( 'abc [[|]] def', "abc [[|]] def", ), array( 'abc link def', "abc [[link]] def", false, false ), array( '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 array( array( 'foo bar Special:BlankPage', 'foo bar [[Special:BlankPage]]', null, ), array( 'Foo\'bar', "[[Foo'bar]]", 'enwiki', ), array( 'foo bar Special:BlankPage', 'foo bar [[Special:BlankPage]]', 'enwiki', ), ); // @codingStandardsIgnoreEnd } }