7 class LinkerTest
extends MediaWikiLangTestCase
{
10 * @dataProvider provideCasesForUserLink
11 * @covers Linker::userLink
13 public function testUserLink( $expected, $userId, $userName, $altUserName = false, $msg = '' ) {
14 $this->setMwGlobals( array(
15 'wgArticlePath' => '/wiki/$1',
16 'wgWellFormedXml' => true,
19 $this->assertEquals( $expected,
20 Linker
::userLink( $userId, $userName, $altUserName, $msg )
24 public static function provideCasesForUserLink() {
29 # - optional altUserName
33 ### ANONYMOUS USER ########################################
35 '<a href="/wiki/Special:Contributions/JohnDoe" '
36 . 'title="Special:Contributions/JohnDoe" '
37 . 'class="mw-userlink mw-anonuserlink">JohnDoe</a>',
41 '<a href="/wiki/Special:Contributions/::1" '
42 . 'title="Special:Contributions/::1" '
43 . 'class="mw-userlink mw-anonuserlink">::1</a>',
45 'Anonymous with pretty IPv6'
48 '<a href="/wiki/Special:Contributions/0:0:0:0:0:0:0:1" '
49 . 'title="Special:Contributions/0:0:0:0:0:0:0:1" '
50 . 'class="mw-userlink mw-anonuserlink">::1</a>',
51 0, '0:0:0:0:0:0:0:1', false,
52 'Anonymous with almost pretty IPv6'
55 '<a href="/wiki/Special:Contributions/0000:0000:0000:0000:0000:0000:0000:0001" '
56 . 'title="Special:Contributions/0000:0000:0000:0000:0000:0000:0000:0001" '
57 . 'class="mw-userlink mw-anonuserlink">::1</a>',
58 0, '0000:0000:0000:0000:0000:0000:0000:0001', false,
59 'Anonymous with full IPv6'
62 '<a href="/wiki/Special:Contributions/::1" '
63 . 'title="Special:Contributions/::1" '
64 . 'class="mw-userlink mw-anonuserlink">AlternativeUsername</a>',
65 0, '::1', 'AlternativeUsername',
66 'Anonymous with pretty IPv6 and an alternative username'
71 '<a href="/wiki/Special:Contributions/127.0.0.1" '
72 . 'title="Special:Contributions/127.0.0.1" '
73 . 'class="mw-userlink mw-anonuserlink">127.0.0.1</a>',
74 0, '127.0.0.1', false,
78 '<a href="/wiki/Special:Contributions/127.0.0.1" '
79 . 'title="Special:Contributions/127.0.0.1" '
80 . 'class="mw-userlink mw-anonuserlink">AlternativeUsername</a>',
81 0, '127.0.0.1', 'AlternativeUsername',
82 'Anonymous with IPv4 and an alternative username'
85 ### Regular user ##########################################
91 * @dataProvider provideCasesForFormatComment
92 * @covers Linker::formatComment
93 * @covers Linker::formatAutocomments
94 * @covers Linker::formatLinksInComment
96 public function testFormatComment( $expected, $comment, $title = false, $local = false, $wikiId = null ) {
97 $conf = new SiteConfiguration();
98 $conf->settings
= array(
100 'enwiki' => '//en.example.org',
101 'dewiki' => '//de.example.org',
103 'wgArticlePath' => array(
108 $conf->suffixes
= array( 'wiki' );
110 $this->setMwGlobals( array(
111 'wgScript' => '/wiki/index.php',
112 'wgArticlePath' => '/wiki/$1',
113 'wgWellFormedXml' => true,
114 'wgCapitalLinks' => true,
118 if ( $title === false ) {
119 // We need a page title that exists
120 $title = Title
::newFromText( 'Special:BlankPage' );
125 Linker
::formatComment( $comment, $title, $local, $wikiId )
129 public function provideCasesForFormatComment() {
130 $wikiId = 'enwiki'; // $wgConf has a fake entry for this
133 // Linker::formatComment
143 "'''not bolded'''",
147 "try <script>evil</scipt> things",
148 "try <script>evil</scipt> things",
150 // Linker::formatAutocomments
152 '<a href="/wiki/Special:BlankPage#autocomment" title="Special:BlankPage">→</a><span dir="auto"><span class="autocomment">autocomment</span></span>',
156 '<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>',
160 '<a href="/wiki/Special:BlankPage#autocomment" title="Special:BlankPage">→</a><span dir="auto"><span class="autocomment">autocomment: </span> post</span>',
161 "/* autocomment */ post",
164 'pre <a href="/wiki/Special:BlankPage#autocomment" title="Special:BlankPage">→</a><span dir="auto"><span class="autocomment">autocomment</span></span>',
165 "pre /* autocomment */",
168 'pre <a href="/wiki/Special:BlankPage#autocomment" title="Special:BlankPage">→</a><span dir="auto"><span class="autocomment">autocomment: </span> post</span>',
169 "pre /* autocomment */ post",
172 '<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>',
173 "/* autocomment */ multiple? /* autocomment2 */ ",
176 '<a href="/wiki/Special:BlankPage#autocomment_containing_.2F.2A" title="Special:BlankPage">→</a><span dir="auto"><span class="autocomment">autocomment containing /*: </span> T70361</span>',
177 "/* autocomment containing /* */ T70361"
180 '<a href="/wiki/Special:BlankPage#autocomment_containing_.22quotes.22" title="Special:BlankPage">→</a><span dir="auto"><span class="autocomment">autocomment containing "quotes"</span></span>',
181 "/* autocomment containing \"quotes\" */"
184 '<a href="/wiki/Special:BlankPage#autocomment_containing_.3Cscript.3Etags.3C.2Fscript.3E" title="Special:BlankPage">→</a><span dir="auto"><span class="autocomment">autocomment containing <script>tags</script></span></span>',
185 "/* autocomment containing <script>tags</script> */"
188 '<a href="#autocomment">→</a><span dir="auto"><span class="autocomment">autocomment</span></span>',
193 '<span dir="auto"><span class="autocomment">autocomment</span></span>',
198 '<a href="/wiki/Special:BlankPage#autocomment" title="Special:BlankPage">→</a><span dir="auto"><span class="autocomment">autocomment</span></span>',
203 '<a class="external" rel="nofollow" href="//en.example.org/w/Special:BlankPage#autocomment">→</a><span dir="auto"><span class="autocomment">autocomment</span></span>',
205 false, false, $wikiId
207 // Linker::formatLinksInComment
209 'abc <a href="/wiki/index.php?title=Link&action=edit&redlink=1" class="new" title="Link (page does not exist)">link</a> def',
213 'abc <a href="/wiki/index.php?title=Link&action=edit&redlink=1" class="new" title="Link (page does not exist)">text</a> def',
214 "abc [[link|text]] def",
217 'abc <a href="/wiki/Special:BlankPage" title="Special:BlankPage">Special:BlankPage</a> def',
218 "abc [[Special:BlankPage|]] def",
221 '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',
222 "abc [[%C4%85%C5%9B%C5%BC]] def",
225 'abc <a href="/wiki/Special:BlankPage#section" title="Special:BlankPage">#section</a> def',
226 "abc [[#section]] def",
229 'abc <a href="/wiki/index.php?title=/subpage&action=edit&redlink=1" class="new" title="/subpage (page does not exist)">/subpage</a> def',
230 "abc [[/subpage]] def",
233 'abc <a href="/wiki/index.php?title=%22evil!%22&action=edit&redlink=1" class="new" title=""evil!" (page does not exist)">"evil!"</a> def',
234 "abc [[\"evil!\"]] def",
237 'abc [[<script>very evil</script>]] def',
238 "abc [[<script>very evil</script>]] def",
245 'abc <a href="/wiki/index.php?title=Link&action=edit&redlink=1" class="new" title="Link (page does not exist)">link</a> def',
250 'abc <a class="external" rel="nofollow" href="//en.example.org/w/Link">link</a> def',
252 false, false, $wikiId
258 * @covers Linker::formatLinksInComment
259 * @dataProvider provideCasesForFormatLinksInComment
261 public function testFormatLinksInComment( $expected, $input, $wiki ) {
263 $conf = new SiteConfiguration();
264 $conf->settings
= array(
266 'enwiki' => '//en.example.org'
268 'wgArticlePath' => array(
272 $conf->suffixes
= array( 'wiki' );
273 $this->setMwGlobals( array(
274 'wgScript' => '/wiki/index.php',
275 'wgArticlePath' => '/wiki/$1',
276 'wgWellFormedXml' => true,
277 'wgCapitalLinks' => true,
283 Linker
::formatLinksInComment( $input, Title
::newFromText( 'Special:BlankPage' ), false, $wiki )
287 public static function provideCasesForFormatLinksInComment() {
290 'foo bar <a href="/wiki/Special:BlankPage" title="Special:BlankPage">Special:BlankPage</a>',
291 'foo bar [[Special:BlankPage]]',
295 '<a class="external" rel="nofollow" href="//en.example.org/w/Foo%27bar">Foo\'bar</a>',
300 'foo bar <a class="external" rel="nofollow" href="//en.example.org/w/Special:BlankPage">Special:BlankPage</a>',
301 'foo bar [[Special:BlankPage]]',