Merge "Set relevant title on Special:RecentChangesLinked"
[lhc/web/wiklou.git] / tests / phpunit / includes / LinkerTest.php
1 <?php
2
3 class LinkerTest extends MediaWikiLangTestCase {
4
5 /**
6 * @dataProvider provideCasesForUserLink
7 * @covers Linker::userLink
8 */
9 public function testUserLink( $expected, $userId, $userName, $altUserName = false, $msg = '' ) {
10 $this->setMwGlobals( array(
11 'wgArticlePath' => '/wiki/$1',
12 'wgWellFormedXml' => true,
13 ) );
14
15 $this->assertEquals( $expected,
16 Linker::userLink( $userId, $userName, $altUserName, $msg )
17 );
18 }
19
20 public static function provideCasesForUserLink() {
21 # Format:
22 # - expected
23 # - userid
24 # - username
25 # - optional altUserName
26 # - optional message
27 return array(
28
29 ### ANONYMOUS USER ########################################
30 array(
31 '<a href="/wiki/Special:Contributions/JohnDoe" '
32 . 'title="Special:Contributions/JohnDoe" '
33 . 'class="mw-userlink mw-anonuserlink">JohnDoe</a>',
34 0, 'JohnDoe', false,
35 ),
36 array(
37 '<a href="/wiki/Special:Contributions/::1" '
38 . 'title="Special:Contributions/::1" '
39 . 'class="mw-userlink mw-anonuserlink">::1</a>',
40 0, '::1', false,
41 'Anonymous with pretty IPv6'
42 ),
43 array(
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'
49 ),
50 array(
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'
56 ),
57 array(
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'
63 ),
64
65 # IPV4
66 array(
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,
71 'Anonymous with IPv4'
72 ),
73 array(
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'
79 ),
80
81 ### Regular user ##########################################
82 # TODO!
83 );
84 }
85
86 /**
87 * @dataProvider provideCasesForFormatComment
88 * @covers Linker::formatComment
89 * @covers Linker::formatAutocomments
90 * @covers Linker::formatLinksInComment
91 */
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,
98 ) );
99
100 if ( $title === false ) {
101 // We need a page title that exists
102 $title = Title::newFromText( 'Special:BlankPage' );
103 }
104
105 $this->assertEquals(
106 $expected,
107 Linker::formatComment( $comment, $title, $local )
108 );
109 }
110
111 public static function provideCasesForFormatComment() {
112 return array(
113 // Linker::formatComment
114 array(
115 'a&lt;script&gt;b',
116 'a<script>b',
117 ),
118 array(
119 'a—b',
120 'a&mdash;b',
121 ),
122 array(
123 "&#039;&#039;&#039;not bolded&#039;&#039;&#039;",
124 "'''not bolded'''",
125 ),
126 // Linker::formatAutocomments
127 array(
128 '<a href="/wiki/Special:BlankPage#autocomment" title="Special:BlankPage">→</a>‎<span dir="auto"><span class="autocomment">autocomment</span></span>',
129 "/* autocomment */",
130 ),
131 array(
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&amp;action=edit&amp;redlink=1" class="new" title="Linkie? (page does not exist)">linkie?</a></span></span>',
133 "/* [[linkie?]] */",
134 ),
135 array(
136 '<a href="/wiki/Special:BlankPage#autocomment" title="Special:BlankPage">→</a>‎<span dir="auto"><span class="autocomment">autocomment: </span> post</span>',
137 "/* autocomment */ post",
138 ),
139 array(
140 'pre <a href="/wiki/Special:BlankPage#autocomment" title="Special:BlankPage">→</a>‎<span dir="auto"><span class="autocomment">autocomment</span></span>',
141 "pre /* autocomment */",
142 ),
143 array(
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",
146 ),
147 array(
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 */ ",
150 ),
151 array(
152 '<a href="#autocomment">→</a>‎<span dir="auto"><span class="autocomment">autocomment</span></span>',
153 "/* autocomment */",
154 false, true
155 ),
156 array(
157 '‎<span dir="auto"><span class="autocomment">autocomment</span></span>',
158 "/* autocomment */",
159 null
160 ),
161 // Linker::formatLinksInComment
162 array(
163 'abc <a href="/wiki/index.php?title=Link&amp;action=edit&amp;redlink=1" class="new" title="Link (page does not exist)">link</a> def',
164 "abc [[link]] def",
165 ),
166 array(
167 'abc <a href="/wiki/index.php?title=Link&amp;action=edit&amp;redlink=1" class="new" title="Link (page does not exist)">text</a> def',
168 "abc [[link|text]] def",
169 ),
170 array(
171 'abc <a href="/wiki/Special:BlankPage" title="Special:BlankPage">Special:BlankPage</a> def',
172 "abc [[Special:BlankPage|]] def",
173 ),
174 array(
175 'abc <a href="/wiki/index.php?title=%C4%84%C5%9B%C5%BC&amp;action=edit&amp;redlink=1" class="new" title="Ąśż (page does not exist)">ąśż</a> def',
176 "abc [[%C4%85%C5%9B%C5%BC]] def",
177 ),
178 array(
179 'abc <a href="/wiki/Special:BlankPage#section" title="Special:BlankPage">#section</a> def',
180 "abc [[#section]] def",
181 ),
182 array(
183 'abc <a href="/wiki/index.php?title=/subpage&amp;action=edit&amp;redlink=1" class="new" title="/subpage (page does not exist)">/subpage</a> def',
184 "abc [[/subpage]] def",
185 ),
186 );
187 }
188 }