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 'wgScript' => '/wiki/index.php',
95 'wgArticlePath' => '/wiki/$1',
96 'wgWellFormedXml' => true,
97 'wgCapitalLinks' => true,
100 if ( $title === false ) {
101 // We need a page title that exists
102 $title = Title
::newFromText( 'Special:BlankPage' );
107 Linker
::formatComment( $comment, $title, $local )
111 public static function provideCasesForFormatComment() {
113 // Linker::formatComment
123 "'''not bolded'''",
126 // Linker::formatAutocomments
128 '<a href="/wiki/Special:BlankPage#autocomment" title="Special:BlankPage">→</a><span dir="auto"><span class="autocomment">autocomment</span></span>',
132 '<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>',
136 '<a href="/wiki/Special:BlankPage#autocomment" title="Special:BlankPage">→</a><span dir="auto"><span class="autocomment">autocomment: </span> post</span>',
137 "/* autocomment */ post",
140 'pre <a href="/wiki/Special:BlankPage#autocomment" title="Special:BlankPage">→</a><span dir="auto"><span class="autocomment">autocomment</span></span>',
141 "pre /* autocomment */",
144 'pre <a href="/wiki/Special:BlankPage#autocomment" title="Special:BlankPage">→</a><span dir="auto"><span class="autocomment">autocomment: </span> post</span>',
145 "pre /* autocomment */ post",
148 '/* autocomment */ multiple? <a href="/wiki/Special:BlankPage#autocomment2" title="Special:BlankPage">→</a><span dir="auto"><span class="autocomment">autocomment2: </span> </span>',
149 "/* autocomment */ multiple? /* autocomment2 */ ",
152 '<a href="#autocomment">→</a><span dir="auto"><span class="autocomment">autocomment</span></span>',
157 '<span dir="auto"><span class="autocomment">autocomment</span></span>',
161 // Linker::formatLinksInComment
163 'abc <a href="/wiki/index.php?title=Link&action=edit&redlink=1" class="new" title="Link (page does not exist)">link</a> def',
167 'abc <a href="/wiki/index.php?title=Link&action=edit&redlink=1" class="new" title="Link (page does not exist)">text</a> def',
168 "abc [[link|text]] def",
171 'abc <a href="/wiki/Special:BlankPage" title="Special:BlankPage">Special:BlankPage</a> def',
172 "abc [[Special:BlankPage|]] def",
175 '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',
176 "abc [[%C4%85%C5%9B%C5%BC]] def",
179 'abc <a href="/wiki/Special:BlankPage#section" title="Special:BlankPage">#section</a> def',
180 "abc [[#section]] def",
183 'abc <a href="/wiki/index.php?title=/subpage&action=edit&redlink=1" class="new" title="/subpage (page does not exist)">/subpage</a> def',
184 "abc [[/subpage]] def",