Remove unused 'XMPGetInfo' and 'XMPGetResults' hooks
[lhc/web/wiklou.git] / tests / phpunit / includes / changes / RecentChangeTest.php
1 <?php
2
3 /**
4 * @group Database
5 */
6 class RecentChangeTest extends MediaWikiTestCase {
7 protected $title;
8 protected $target;
9 protected $user;
10 protected $user_comment;
11 protected $context;
12
13 public function __construct() {
14 parent::__construct();
15
16 $this->title = Title::newFromText( 'SomeTitle' );
17 $this->target = Title::newFromText( 'TestTarget' );
18 $this->user = User::newFromName( 'UserName' );
19
20 $this->user_comment = '<User comment about action>';
21 $this->context = RequestContext::newExtraneousContext( $this->title );
22 }
23
24 /**
25 * The testIrcMsgForAction* tests are supposed to cover the hacky
26 * LogFormatter::getIRCActionText / bug 34508
27 *
28 * Third parties bots listen to those messages. They are clever enough
29 * to fetch the i18n messages from the wiki and then analyze the IRC feed
30 * to reverse engineer the $1, $2 messages.
31 * One thing bots can not detect is when MediaWiki change the meaning of
32 * a message like what happened when we deployed 1.19. $1 became the user
33 * performing the action which broke basically all bots around.
34 *
35 * Should cover the following log actions (which are most commonly used by bots):
36 * - block/block
37 * - block/unblock
38 * - block/reblock
39 * - delete/delete
40 * - delete/restore
41 * - newusers/create
42 * - newusers/create2
43 * - newusers/autocreate
44 * - move/move
45 * - move/move_redir
46 * - protect/protect
47 * - protect/modifyprotect
48 * - protect/unprotect
49 * - protect/move_prot
50 * - upload/upload
51 * - merge/merge
52 * - import/upload
53 * - import/interwiki
54 *
55 * As well as the following Auto Edit Summaries:
56 * - blank
57 * - replace
58 * - rollback
59 * - undo
60 */
61
62 /**
63 * @covers LogFormatter::getIRCActionText
64 */
65 public function testIrcMsgForLogTypeBlock() {
66 $sep = $this->context->msg( 'colon-separator' )->text();
67
68 # block/block
69 $this->assertIRCComment(
70 $this->context->msg( 'blocklogentry', 'SomeTitle', 'duration', '(flags)' )->plain()
71 . $sep . $this->user_comment,
72 'block', 'block',
73 array(
74 '5::duration' => 'duration',
75 '6::flags' => 'flags',
76 ),
77 $this->user_comment
78 );
79 # block/unblock
80 $this->assertIRCComment(
81 $this->context->msg( 'unblocklogentry', 'SomeTitle' )->plain() . $sep . $this->user_comment,
82 'block', 'unblock',
83 array(),
84 $this->user_comment
85 );
86 # block/reblock
87 $this->assertIRCComment(
88 $this->context->msg( 'reblock-logentry', 'SomeTitle', 'duration', '(flags)' )->plain()
89 . $sep . $this->user_comment,
90 'block', 'reblock',
91 array(
92 '5::duration' => 'duration',
93 '6::flags' => 'flags',
94 ),
95 $this->user_comment
96 );
97 }
98
99 /**
100 * @covers LogFormatter::getIRCActionText
101 */
102 public function testIrcMsgForLogTypeDelete() {
103 $sep = $this->context->msg( 'colon-separator' )->text();
104
105 # delete/delete
106 $this->assertIRCComment(
107 $this->context->msg( 'deletedarticle', 'SomeTitle' )->plain() . $sep . $this->user_comment,
108 'delete', 'delete',
109 array(),
110 $this->user_comment
111 );
112
113 # delete/restore
114 $this->assertIRCComment(
115 $this->context->msg( 'undeletedarticle', 'SomeTitle' )->plain() . $sep . $this->user_comment,
116 'delete', 'restore',
117 array(),
118 $this->user_comment
119 );
120 }
121
122 /**
123 * @covers LogFormatter::getIRCActionText
124 */
125 public function testIrcMsgForLogTypeNewusers() {
126 $this->assertIRCComment(
127 'New user account',
128 'newusers', 'newusers',
129 array()
130 );
131 $this->assertIRCComment(
132 'New user account',
133 'newusers', 'create',
134 array()
135 );
136 $this->assertIRCComment(
137 'created new account SomeTitle',
138 'newusers', 'create2',
139 array()
140 );
141 $this->assertIRCComment(
142 'Account created automatically',
143 'newusers', 'autocreate',
144 array()
145 );
146 }
147
148 /**
149 * @covers LogFormatter::getIRCActionText
150 */
151 public function testIrcMsgForLogTypeMove() {
152 $move_params = array(
153 '4::target' => $this->target->getPrefixedText(),
154 '5::noredir' => 0,
155 );
156 $sep = $this->context->msg( 'colon-separator' )->text();
157
158 # move/move
159 $this->assertIRCComment(
160 $this->context->msg( '1movedto2', 'SomeTitle', 'TestTarget' )
161 ->plain() . $sep . $this->user_comment,
162 'move', 'move',
163 $move_params,
164 $this->user_comment
165 );
166
167 # move/move_redir
168 $this->assertIRCComment(
169 $this->context->msg( '1movedto2_redir', 'SomeTitle', 'TestTarget' )
170 ->plain() . $sep . $this->user_comment,
171 'move', 'move_redir',
172 $move_params,
173 $this->user_comment
174 );
175 }
176
177 /**
178 * @covers LogFormatter::getIRCActionText
179 */
180 public function testIrcMsgForLogTypePatrol() {
181 # patrol/patrol
182 $this->assertIRCComment(
183 $this->context->msg( 'patrol-log-line', 'revision 777', '[[SomeTitle]]', '' )->plain(),
184 'patrol', 'patrol',
185 array(
186 '4::curid' => '777',
187 '5::previd' => '666',
188 '6::auto' => 0,
189 )
190 );
191 }
192
193 /**
194 * @covers LogFormatter::getIRCActionText
195 */
196 public function testIrcMsgForLogTypeProtect() {
197 $protectParams = array(
198 '[edit=sysop] (indefinite) ‎[move=sysop] (indefinite)'
199 );
200 $sep = $this->context->msg( 'colon-separator' )->text();
201
202 # protect/protect
203 $this->assertIRCComment(
204 $this->context->msg( 'protectedarticle', 'SomeTitle ' . $protectParams[0] )
205 ->plain() . $sep . $this->user_comment,
206 'protect', 'protect',
207 $protectParams,
208 $this->user_comment
209 );
210
211 # protect/unprotect
212 $this->assertIRCComment(
213 $this->context->msg( 'unprotectedarticle', 'SomeTitle' )->plain() . $sep . $this->user_comment,
214 'protect', 'unprotect',
215 array(),
216 $this->user_comment
217 );
218
219 # protect/modify
220 $this->assertIRCComment(
221 $this->context->msg( 'modifiedarticleprotection', 'SomeTitle ' . $protectParams[0] )
222 ->plain() . $sep . $this->user_comment,
223 'protect', 'modify',
224 $protectParams,
225 $this->user_comment
226 );
227
228 # protect/move_prot
229 $this->assertIRCComment(
230 $this->context->msg( 'movedarticleprotection', 'SomeTitle', 'OldTitle' )
231 ->plain() . $sep . $this->user_comment,
232 'protect', 'move_prot',
233 array( 'OldTitle' ),
234 $this->user_comment
235 );
236 }
237
238 /**
239 * @covers LogFormatter::getIRCActionText
240 */
241 public function testIrcMsgForLogTypeUpload() {
242 $sep = $this->context->msg( 'colon-separator' )->text();
243
244 # upload/upload
245 $this->assertIRCComment(
246 $this->context->msg( 'uploadedimage', 'SomeTitle' )->plain() . $sep . $this->user_comment,
247 'upload', 'upload',
248 array(),
249 $this->user_comment
250 );
251
252 # upload/overwrite
253 $this->assertIRCComment(
254 $this->context->msg( 'overwroteimage', 'SomeTitle' )->plain() . $sep . $this->user_comment,
255 'upload', 'overwrite',
256 array(),
257 $this->user_comment
258 );
259 }
260
261 /**
262 * @covers LogFormatter::getIRCActionText
263 */
264 public function testIrcMsgForLogTypeMerge() {
265 $sep = $this->context->msg( 'colon-separator' )->text();
266
267 # merge/merge
268 $this->assertIRCComment(
269 $this->context->msg( 'pagemerge-logentry', 'SomeTitle', 'Dest', 'timestamp' )->plain()
270 . $sep . $this->user_comment,
271 'merge', 'merge',
272 array(
273 '4::dest' => 'Dest',
274 '5::mergepoint' => 'timestamp',
275 ),
276 $this->user_comment
277 );
278 }
279
280 /**
281 * @covers LogFormatter::getIRCActionText
282 */
283 public function testIrcMsgForLogTypeImport() {
284 $sep = $this->context->msg( 'colon-separator' )->text();
285
286 # import/upload
287 $this->assertIRCComment(
288 $this->context->msg( 'import-logentry-upload', 'SomeTitle' )->plain() . $sep . $this->user_comment,
289 'import', 'upload',
290 array(),
291 $this->user_comment
292 );
293
294 # import/interwiki
295 $this->assertIRCComment(
296 $this->context->msg( 'import-logentry-interwiki', 'SomeTitle' )->plain() . $sep . $this->user_comment,
297 'import', 'interwiki',
298 array(),
299 $this->user_comment
300 );
301 }
302
303 /**
304 * @todo Emulate these edits somehow and extract
305 * raw edit summary from RecentChange object
306 * --
307 */
308 /*
309 public function testIrcMsgForBlankingAES() {
310 // $this->context->msg( 'autosumm-blank', .. );
311 }
312
313 public function testIrcMsgForReplaceAES() {
314 // $this->context->msg( 'autosumm-replace', .. );
315 }
316
317 public function testIrcMsgForRollbackAES() {
318 // $this->context->msg( 'revertpage', .. );
319 }
320
321 public function testIrcMsgForUndoAES() {
322 // $this->context->msg( 'undo-summary', .. );
323 }
324 */
325
326 /**
327 * @param string $expected Expected IRC text without colors codes
328 * @param string $type Log type (move, delete, suppress, patrol ...)
329 * @param string $action A log type action
330 * @param array $params
331 * @param string $comment (optional) A comment for the log action
332 * @param string $msg (optional) A message for PHPUnit :-)
333 */
334 protected function assertIRCComment( $expected, $type, $action, $params,
335 $comment = null, $msg = ''
336 ) {
337 $logEntry = new ManualLogEntry( $type, $action );
338 $logEntry->setPerformer( $this->user );
339 $logEntry->setTarget( $this->title );
340 if ( $comment !== null ) {
341 $logEntry->setComment( $comment );
342 }
343 $logEntry->setParameters( $params );
344
345 $formatter = LogFormatter::newFromEntry( $logEntry );
346 $formatter->setContext( $this->context );
347
348 // Apply the same transformation as done in IRCColourfulRCFeedFormatter::getLine for rc_comment
349 $ircRcComment = IRCColourfulRCFeedFormatter::cleanupForIRC( $formatter->getIRCActionComment() );
350
351 $this->assertEquals(
352 $expected,
353 $ircRcComment,
354 $msg
355 );
356 }
357 }