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