6 class RecentChangeTest
extends MediaWikiTestCase
{
10 protected $user_comment;
13 public function __construct() {
14 parent
::__construct();
16 $this->title
= Title
::newFromText( 'SomeTitle' );
17 $this->target
= Title
::newFromText( 'TestTarget' );
18 $this->user
= User
::newFromName( 'UserName' );
20 $this->user_comment
= '<User comment about action>';
21 $this->context
= RequestContext
::newExtraneousContext( $this->title
);
25 * The testIrcMsgForAction* tests are supposed to cover the hacky
26 * LogFormatter::getIRCActionText / bug 34508
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.
35 * Should cover the following log actions (which are most commonly used by bots):
43 * - newusers/autocreate
47 * - protect/modifyprotect
55 * As well as the following Auto Edit Summaries:
63 * @covers LogFormatter::getIRCActionText
65 public function testIrcMsgForLogTypeBlock() {
66 $sep = $this->context
->msg( 'colon-separator' )->text();
69 $this->assertIRCComment(
70 $this->context
->msg( 'blocklogentry', 'SomeTitle', 'duration', '(flags)' )->plain()
71 . $sep . $this->user_comment
,
74 '5::duration' => 'duration',
75 '6::flags' => 'flags',
80 $this->assertIRCComment(
81 $this->context
->msg( 'unblocklogentry', 'SomeTitle' )->plain() . $sep . $this->user_comment
,
87 $this->assertIRCComment(
88 $this->context
->msg( 'reblock-logentry', 'SomeTitle', 'duration', '(flags)' )->plain()
89 . $sep . $this->user_comment
,
92 '5::duration' => 'duration',
93 '6::flags' => 'flags',
100 * @covers LogFormatter::getIRCActionText
102 public function testIrcMsgForLogTypeDelete() {
103 $sep = $this->context
->msg( 'colon-separator' )->text();
106 $this->assertIRCComment(
107 $this->context
->msg( 'deletedarticle', 'SomeTitle' )->plain() . $sep . $this->user_comment
,
114 $this->assertIRCComment(
115 $this->context
->msg( 'undeletedarticle', 'SomeTitle' )->plain() . $sep . $this->user_comment
,
123 * @covers LogFormatter::getIRCActionText
125 public function testIrcMsgForLogTypeNewusers() {
126 $this->assertIRCComment(
128 'newusers', 'newusers',
131 $this->assertIRCComment(
133 'newusers', 'create',
136 $this->assertIRCComment(
137 'created new account SomeTitle',
138 'newusers', 'create2',
141 $this->assertIRCComment(
142 'Account created automatically',
143 'newusers', 'autocreate',
149 * @covers LogFormatter::getIRCActionText
151 public function testIrcMsgForLogTypeMove() {
152 $move_params = array(
153 '4::target' => $this->target
->getPrefixedText(),
156 $sep = $this->context
->msg( 'colon-separator' )->text();
159 $this->assertIRCComment(
160 $this->context
->msg( '1movedto2', 'SomeTitle', 'TestTarget' )
161 ->plain() . $sep . $this->user_comment
,
168 $this->assertIRCComment(
169 $this->context
->msg( '1movedto2_redir', 'SomeTitle', 'TestTarget' )
170 ->plain() . $sep . $this->user_comment
,
171 'move', 'move_redir',
178 * @covers LogFormatter::getIRCActionText
180 public function testIrcMsgForLogTypePatrol() {
182 $this->assertIRCComment(
183 $this->context
->msg( 'patrol-log-line', 'revision 777', '[[SomeTitle]]', '' )->plain(),
187 '5::previd' => '666',
194 * @covers LogFormatter::getIRCActionText
196 public function testIrcMsgForLogTypeProtect() {
197 $protectParams = array(
198 '[edit=sysop] (indefinite) [move=sysop] (indefinite)'
200 $sep = $this->context
->msg( 'colon-separator' )->text();
203 $this->assertIRCComment(
204 $this->context
->msg( 'protectedarticle', 'SomeTitle ' . $protectParams[0] )
205 ->plain() . $sep . $this->user_comment
,
206 'protect', 'protect',
212 $this->assertIRCComment(
213 $this->context
->msg( 'unprotectedarticle', 'SomeTitle' )->plain() . $sep . $this->user_comment
,
214 'protect', 'unprotect',
220 $this->assertIRCComment(
221 $this->context
->msg( 'modifiedarticleprotection', 'SomeTitle ' . $protectParams[0] )
222 ->plain() . $sep . $this->user_comment
,
229 $this->assertIRCComment(
230 $this->context
->msg( 'movedarticleprotection', 'SomeTitle', 'OldTitle' )
231 ->plain() . $sep . $this->user_comment
,
232 'protect', 'move_prot',
239 * @covers LogFormatter::getIRCActionText
241 public function testIrcMsgForLogTypeUpload() {
242 $sep = $this->context
->msg( 'colon-separator' )->text();
245 $this->assertIRCComment(
246 $this->context
->msg( 'uploadedimage', 'SomeTitle' )->plain() . $sep . $this->user_comment
,
253 $this->assertIRCComment(
254 $this->context
->msg( 'overwroteimage', 'SomeTitle' )->plain() . $sep . $this->user_comment
,
255 'upload', 'overwrite',
262 * @covers LogFormatter::getIRCActionText
264 public function testIrcMsgForLogTypeMerge() {
265 $sep = $this->context
->msg( 'colon-separator' )->text();
268 $this->assertIRCComment(
269 $this->context
->msg( 'pagemerge-logentry', 'SomeTitle', 'Dest', 'timestamp' )->plain()
270 . $sep . $this->user_comment
,
274 '5::mergepoint' => 'timestamp',
281 * @covers LogFormatter::getIRCActionText
283 public function testIrcMsgForLogTypeImport() {
284 $sep = $this->context
->msg( 'colon-separator' )->text();
287 $this->assertIRCComment(
288 $this->context
->msg( 'import-logentry-upload', 'SomeTitle' )->plain() . $sep . $this->user_comment
,
295 $this->assertIRCComment(
296 $this->context
->msg( 'import-logentry-interwiki', 'SomeTitle' )->plain() . $sep . $this->user_comment
,
297 'import', 'interwiki',
304 * @todo Emulate these edits somehow and extract
305 * raw edit summary from RecentChange object
309 public function testIrcMsgForBlankingAES() {
310 // $this->context->msg( 'autosumm-blank', .. );
313 public function testIrcMsgForReplaceAES() {
314 // $this->context->msg( 'autosumm-replace', .. );
317 public function testIrcMsgForRollbackAES() {
318 // $this->context->msg( 'revertpage', .. );
321 public function testIrcMsgForUndoAES() {
322 // $this->context->msg( 'undo-summary', .. );
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 :-)
334 protected function assertIRCComment( $expected, $type, $action, $params,
335 $comment = null, $msg = ''
337 $logEntry = new ManualLogEntry( $type, $action );
338 $logEntry->setPerformer( $this->user
);
339 $logEntry->setTarget( $this->title
);
340 if ( $comment !== null ) {
341 $logEntry->setComment( $comment );
343 $logEntry->setParameters( $params );
345 $formatter = LogFormatter
::newFromEntry( $logEntry );
346 $formatter->setContext( $this->context
);
348 // Apply the same transformation as done in IRCColourfulRCFeedFormatter::getLine for rc_comment
349 $ircRcComment = IRCColourfulRCFeedFormatter
::cleanupForIRC( $formatter->getIRCActionComment() );