3 class LinkerTest
extends MediaWikiLangTestCase
{
6 * @dataProvider provideCasesForUserLink
7 * @covers Linker::userLink
9 public function testUserLink( $expected, $userId, $userName, $altUserName = false, $msg = '' ) {
10 $this->setMwGlobals( array(
11 'wgArticlePath' => '/wiki/$1',
12 'wgWellFormedXml' => true,
15 $this->assertEquals( $expected,
16 Linker
::userLink( $userId, $userName, $altUserName, $msg )
20 public static function provideCasesForUserLink() {
25 # - optional altUserName
29 ### ANONYMOUS USER ########################################
31 '<a href="/wiki/Special:Contributions/JohnDoe" '
32 . 'title="Special:Contributions/JohnDoe" '
33 . 'class="mw-userlink mw-anonuserlink">JohnDoe</a>',
37 '<a href="/wiki/Special:Contributions/::1" '
38 . 'title="Special:Contributions/::1" '
39 . 'class="mw-userlink mw-anonuserlink">::1</a>',
41 'Anonymous with pretty IPv6'
44 '<a href="/wiki/Special:Contributions/0:0:0:0:0:0:0:1" '
45 . 'title="Special:Contributions/0:0:0:0:0:0:0:1" '
46 . 'class="mw-userlink mw-anonuserlink">::1</a>',
47 0, '0:0:0:0:0:0:0:1', false,
48 'Anonymous with almost pretty IPv6'
51 '<a href="/wiki/Special:Contributions/0000:0000:0000:0000:0000:0000:0000:0001" '
52 . 'title="Special:Contributions/0000:0000:0000:0000:0000:0000:0000:0001" '
53 . 'class="mw-userlink mw-anonuserlink">::1</a>',
54 0, '0000:0000:0000:0000:0000:0000:0000:0001', false,
55 'Anonymous with full IPv6'
58 '<a href="/wiki/Special:Contributions/::1" '
59 . 'title="Special:Contributions/::1" '
60 . 'class="mw-userlink mw-anonuserlink">AlternativeUsername</a>',
61 0, '::1', 'AlternativeUsername',
62 'Anonymous with pretty IPv6 and an alternative username'
67 '<a href="/wiki/Special:Contributions/127.0.0.1" '
68 . 'title="Special:Contributions/127.0.0.1" '
69 . 'class="mw-userlink mw-anonuserlink">127.0.0.1</a>',
70 0, '127.0.0.1', false,
74 '<a href="/wiki/Special:Contributions/127.0.0.1" '
75 . 'title="Special:Contributions/127.0.0.1" '
76 . 'class="mw-userlink mw-anonuserlink">AlternativeUsername</a>',
77 0, '127.0.0.1', 'AlternativeUsername',
78 'Anonymous with IPv4 and an alternative username'
81 ### Regular user ##########################################
87 * @dataProvider provideCasesForFormatComment
88 * @covers Linker::formatComment
89 * @covers Linker::formatAutocomments
90 * @covers Linker::formatLinksInComment
92 public function testFormatComment( $expected, $comment, $title = false, $local = false ) {
93 $this->setMwGlobals( array(
94 'wgArticlePath' => '/wiki/$1',
95 'wgWellFormedXml' => true,
98 if ( $title === false ) {
99 // We need a page title that exists
100 $title = Title
::newFromText( 'Special:BlankPage' );
105 Linker
::formatComment( $comment, $title, $local )
109 public static function provideCasesForFormatComment() {
111 // Linker::formatComment
121 "'''not bolded'''",
124 // Linker::formatAutocomments
126 '<a href="/wiki/Special:BlankPage#autocomment" title="Special:BlankPage">→</a><span dir="auto"><span class="autocomment">autocomment</span></span>',
130 '<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>',
134 '<a href="/wiki/Special:BlankPage#autocomment" title="Special:BlankPage">→</a><span dir="auto"><span class="autocomment">autocomment: </span> post</span>',
135 "/* autocomment */ post",
138 'pre <a href="/wiki/Special:BlankPage#autocomment" title="Special:BlankPage">→</a><span dir="auto"><span class="autocomment">autocomment</span></span>',
139 "pre /* autocomment */",
142 'pre <a href="/wiki/Special:BlankPage#autocomment" title="Special:BlankPage">→</a><span dir="auto"><span class="autocomment">autocomment: </span> post</span>',
143 "pre /* autocomment */ post",
146 '/* autocomment */ multiple? <a href="/wiki/Special:BlankPage#autocomment2" title="Special:BlankPage">→</a><span dir="auto"><span class="autocomment">autocomment2: </span> </span>',
147 "/* autocomment */ multiple? /* autocomment2 */ ",
150 '<a href="#autocomment">→</a><span dir="auto"><span class="autocomment">autocomment</span></span>',
155 '<span dir="auto"><span class="autocomment">autocomment</span></span>',
159 // Linker::formatLinksInComment
161 'abc <a href="/wiki/index.php?title=Link&action=edit&redlink=1" class="new" title="Link (page does not exist)">link</a> def',
165 'abc <a href="/wiki/index.php?title=Link&action=edit&redlink=1" class="new" title="Link (page does not exist)">text</a> def',
166 "abc [[link|text]] def",
169 'abc <a href="/wiki/Special:BlankPage" title="Special:BlankPage">Special:BlankPage</a> def',
170 "abc [[Special:BlankPage|]] def",
173 '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',
174 "abc [[%C4%85%C5%9B%C5%BC]] def",
177 'abc <a href="/wiki/Special:BlankPage#section" title="Special:BlankPage">#section</a> def',
178 "abc [[#section]] def",
181 'abc <a href="/wiki/index.php?title=/subpage&action=edit&redlink=1" class="new" title="/subpage (page does not exist)">/subpage</a> def',
182 "abc [[/subpage]] def",