Merge "Add top help link to MediaWiki.org in several pages via indicator"
[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 * - upload/upload
50 * - merge/merge
51 *
52 * As well as the following Auto Edit Summaries:
53 * - blank
54 * - replace
55 * - rollback
56 * - undo
57 */
58
59 /**
60 * @covers LogFormatter::getIRCActionText
61 */
62 public function testIrcMsgForLogTypeBlock() {
63 $sep = $this->context->msg( 'colon-separator' )->text();
64
65 # block/block
66 $this->assertIRCComment(
67 $this->context->msg( 'blocklogentry', 'SomeTitle', 'duration', '(flags)' )->plain()
68 . $sep . $this->user_comment,
69 'block', 'block',
70 array(
71 '5::duration' => 'duration',
72 '6::flags' => 'flags',
73 ),
74 $this->user_comment
75 );
76 # block/unblock
77 $this->assertIRCComment(
78 $this->context->msg( 'unblocklogentry', 'SomeTitle' )->plain() . $sep . $this->user_comment,
79 'block', 'unblock',
80 array(),
81 $this->user_comment
82 );
83 # block/reblock
84 $this->assertIRCComment(
85 $this->context->msg( 'reblock-logentry', 'SomeTitle', 'duration', '(flags)' )->plain()
86 . $sep . $this->user_comment,
87 'block', 'reblock',
88 array(
89 '5::duration' => 'duration',
90 '6::flags' => 'flags',
91 ),
92 $this->user_comment
93 );
94 }
95
96 /**
97 * @covers LogFormatter::getIRCActionText
98 */
99 public function testIrcMsgForLogTypeDelete() {
100 $sep = $this->context->msg( 'colon-separator' )->text();
101
102 # delete/delete
103 $this->assertIRCComment(
104 $this->context->msg( 'deletedarticle', 'SomeTitle' )->plain() . $sep . $this->user_comment,
105 'delete', 'delete',
106 array(),
107 $this->user_comment
108 );
109
110 # delete/restore
111 $this->assertIRCComment(
112 $this->context->msg( 'undeletedarticle', 'SomeTitle' )->plain() . $sep . $this->user_comment,
113 'delete', 'restore',
114 array(),
115 $this->user_comment
116 );
117 }
118
119 /**
120 * @covers LogFormatter::getIRCActionText
121 */
122 public function testIrcMsgForLogTypeNewusers() {
123 $this->assertIRCComment(
124 'New user account',
125 'newusers', 'newusers',
126 array()
127 );
128 $this->assertIRCComment(
129 'New user account',
130 'newusers', 'create',
131 array()
132 );
133 $this->assertIRCComment(
134 'created new account SomeTitle',
135 'newusers', 'create2',
136 array()
137 );
138 $this->assertIRCComment(
139 'Account created automatically',
140 'newusers', 'autocreate',
141 array()
142 );
143 }
144
145 /**
146 * @covers LogFormatter::getIRCActionText
147 */
148 public function testIrcMsgForLogTypeMove() {
149 $move_params = array(
150 '4::target' => $this->target->getPrefixedText(),
151 '5::noredir' => 0,
152 );
153 $sep = $this->context->msg( 'colon-separator' )->text();
154
155 # move/move
156 $this->assertIRCComment(
157 $this->context->msg( '1movedto2', 'SomeTitle', 'TestTarget' )
158 ->plain() . $sep . $this->user_comment,
159 'move', 'move',
160 $move_params,
161 $this->user_comment
162 );
163
164 # move/move_redir
165 $this->assertIRCComment(
166 $this->context->msg( '1movedto2_redir', 'SomeTitle', 'TestTarget' )
167 ->plain() . $sep . $this->user_comment,
168 'move', 'move_redir',
169 $move_params,
170 $this->user_comment
171 );
172 }
173
174 /**
175 * @covers LogFormatter::getIRCActionText
176 */
177 public function testIrcMsgForLogTypePatrol() {
178 # patrol/patrol
179 $this->assertIRCComment(
180 $this->context->msg( 'patrol-log-line', 'revision 777', '[[SomeTitle]]', '' )->plain(),
181 'patrol', 'patrol',
182 array(
183 '4::curid' => '777',
184 '5::previd' => '666',
185 '6::auto' => 0,
186 )
187 );
188 }
189
190 /**
191 * @covers LogFormatter::getIRCActionText
192 */
193 public function testIrcMsgForLogTypeProtect() {
194 $protectParams = array(
195 '[edit=sysop] (indefinite) ‎[move=sysop] (indefinite)'
196 );
197 $sep = $this->context->msg( 'colon-separator' )->text();
198
199 # protect/protect
200 $this->assertIRCComment(
201 $this->context->msg( 'protectedarticle', 'SomeTitle ' . $protectParams[0] )
202 ->plain() . $sep . $this->user_comment,
203 'protect', 'protect',
204 $protectParams,
205 $this->user_comment
206 );
207
208 # protect/unprotect
209 $this->assertIRCComment(
210 $this->context->msg( 'unprotectedarticle', 'SomeTitle' )->plain() . $sep . $this->user_comment,
211 'protect', 'unprotect',
212 array(),
213 $this->user_comment
214 );
215
216 # protect/modify
217 $this->assertIRCComment(
218 $this->context->msg( 'modifiedarticleprotection', 'SomeTitle ' . $protectParams[0] )
219 ->plain() . $sep . $this->user_comment,
220 'protect', 'modify',
221 $protectParams,
222 $this->user_comment
223 );
224 }
225
226 /**
227 * @covers LogFormatter::getIRCActionText
228 */
229 public function testIrcMsgForLogTypeUpload() {
230 $sep = $this->context->msg( 'colon-separator' )->text();
231
232 # upload/upload
233 $this->assertIRCComment(
234 $this->context->msg( 'uploadedimage', 'SomeTitle' )->plain() . $sep . $this->user_comment,
235 'upload', 'upload',
236 array(),
237 $this->user_comment
238 );
239
240 # upload/overwrite
241 $this->assertIRCComment(
242 $this->context->msg( 'overwroteimage', 'SomeTitle' )->plain() . $sep . $this->user_comment,
243 'upload', 'overwrite',
244 array(),
245 $this->user_comment
246 );
247 }
248
249 /**
250 * @covers LogFormatter::getIRCActionText
251 */
252 public function testIrcMsgForLogTypeMerge() {
253 $sep = $this->context->msg( 'colon-separator' )->text();
254
255 # merge/merge
256 $this->assertIRCComment(
257 $this->context->msg( 'pagemerge-logentry', 'SomeTitle', 'Dest', 'timestamp' )->plain()
258 . $sep . $this->user_comment,
259 'merge', 'merge',
260 array(
261 '4::dest' => 'Dest',
262 '5::mergepoint' => 'timestamp',
263 ),
264 $this->user_comment
265 );
266 }
267
268 /**
269 * @todo Emulate these edits somehow and extract
270 * raw edit summary from RecentChange object
271 * --
272 */
273 /*
274 public function testIrcMsgForBlankingAES() {
275 // $this->context->msg( 'autosumm-blank', .. );
276 }
277
278 public function testIrcMsgForReplaceAES() {
279 // $this->context->msg( 'autosumm-replace', .. );
280 }
281
282 public function testIrcMsgForRollbackAES() {
283 // $this->context->msg( 'revertpage', .. );
284 }
285
286 public function testIrcMsgForUndoAES() {
287 // $this->context->msg( 'undo-summary', .. );
288 }
289 */
290
291 /**
292 * @param string $expected Expected IRC text without colors codes
293 * @param string $type Log type (move, delete, suppress, patrol ...)
294 * @param string $action A log type action
295 * @param array $params
296 * @param string $comment (optional) A comment for the log action
297 * @param string $msg (optional) A message for PHPUnit :-)
298 */
299 protected function assertIRCComment( $expected, $type, $action, $params,
300 $comment = null, $msg = ''
301 ) {
302 $logEntry = new ManualLogEntry( $type, $action );
303 $logEntry->setPerformer( $this->user );
304 $logEntry->setTarget( $this->title );
305 if ( $comment !== null ) {
306 $logEntry->setComment( $comment );
307 }
308 $logEntry->setParameters( $params );
309
310 $formatter = LogFormatter::newFromEntry( $logEntry );
311 $formatter->setContext( $this->context );
312
313 // Apply the same transformation as done in IRCColourfulRCFeedFormatter::getLine for rc_comment
314 $ircRcComment = IRCColourfulRCFeedFormatter::cleanupForIRC( $formatter->getIRCActionComment() );
315
316 $this->assertEquals(
317 $expected,
318 $ircRcComment,
319 $msg
320 );
321 }
322 }