Merge "Made pool counter better handled nested calls"
[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 'wgArticlePath' => '/wiki/$1',
95 'wgWellFormedXml' => true,
96 ) );
97
98 if ( $title === false ) {
99 // We need a page title that exists
100 $title = Title::newFromText( 'Special:BlankPage' );
101 }
102
103 $this->assertEquals(
104 $expected,
105 Linker::formatComment( $comment, $title, $local )
106 );
107 }
108
109 public static function provideCasesForFormatComment() {
110 return array(
111 // Linker::formatComment
112 array(
113 'a&lt;script&gt;b',
114 'a<script>b',
115 ),
116 array(
117 'a—b',
118 'a&mdash;b',
119 ),
120 array(
121 "&#039;&#039;&#039;not bolded&#039;&#039;&#039;",
122 "'''not bolded'''",
123 ),
124 // Linker::formatAutocomments
125 array(
126 '<a href="/wiki/Special:BlankPage#autocomment" title="Special:BlankPage">→</a>‎<span dir="auto"><span class="autocomment">autocomment</span></span>',
127 "/* autocomment */",
128 ),
129 array(
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&amp;action=edit&amp;redlink=1" class="new" title="Linkie? (page does not exist)">linkie?</a></span></span>',
131 "/* [[linkie?]] */",
132 ),
133 array(
134 '<a href="/wiki/Special:BlankPage#autocomment" title="Special:BlankPage">→</a>‎<span dir="auto"><span class="autocomment">autocomment: </span> post</span>',
135 "/* autocomment */ post",
136 ),
137 array(
138 'pre <a href="/wiki/Special:BlankPage#autocomment" title="Special:BlankPage">→</a>‎<span dir="auto"><span class="autocomment">autocomment</span></span>',
139 "pre /* autocomment */",
140 ),
141 array(
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",
144 ),
145 array(
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 */ ",
148 ),
149 array(
150 '<a href="#autocomment">→</a>‎<span dir="auto"><span class="autocomment">autocomment</span></span>',
151 "/* autocomment */",
152 false, true
153 ),
154 array(
155 '‎<span dir="auto"><span class="autocomment">autocomment</span></span>',
156 "/* autocomment */",
157 null
158 ),
159 // Linker::formatLinksInComment
160 array(
161 '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',
162 "abc [[link]] def",
163 ),
164 array(
165 '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',
166 "abc [[link|text]] def",
167 ),
168 array(
169 'abc <a href="/wiki/Special:BlankPage" title="Special:BlankPage">Special:BlankPage</a> def',
170 "abc [[Special:BlankPage|]] def",
171 ),
172 array(
173 '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',
174 "abc [[%C4%85%C5%9B%C5%BC]] def",
175 ),
176 array(
177 'abc <a href="/wiki/Special:BlankPage#section" title="Special:BlankPage">#section</a> def',
178 "abc [[#section]] def",
179 ),
180 array(
181 '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',
182 "abc [[/subpage]] def",
183 ),
184 );
185 }
186 }