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',
79 # block/block - legacy
80 $this->assertIRCComment(
81 $this->context
->msg( 'blocklogentry', 'SomeTitle', 'duration', '(flags)' )->plain()
82 . $sep . $this->user_comment
,
93 $this->assertIRCComment(
94 $this->context
->msg( 'unblocklogentry', 'SomeTitle' )->plain() . $sep . $this->user_comment
,
100 $this->assertIRCComment(
101 $this->context
->msg( 'reblock-logentry', 'SomeTitle', 'duration', '(flags)' )->plain()
102 . $sep . $this->user_comment
,
105 '5::duration' => 'duration',
106 '6::flags' => 'flags',
113 * @covers LogFormatter::getIRCActionText
115 public function testIrcMsgForLogTypeDelete() {
116 $sep = $this->context
->msg( 'colon-separator' )->text();
119 $this->assertIRCComment(
120 $this->context
->msg( 'deletedarticle', 'SomeTitle' )->plain() . $sep . $this->user_comment
,
127 $this->assertIRCComment(
128 $this->context
->msg( 'undeletedarticle', 'SomeTitle' )->plain() . $sep . $this->user_comment
,
136 * @covers LogFormatter::getIRCActionText
138 public function testIrcMsgForLogTypeNewusers() {
139 $this->assertIRCComment(
141 'newusers', 'newusers',
144 $this->assertIRCComment(
146 'newusers', 'create',
149 $this->assertIRCComment(
150 'created new account SomeTitle',
151 'newusers', 'create2',
154 $this->assertIRCComment(
155 'Account created automatically',
156 'newusers', 'autocreate',
162 * @covers LogFormatter::getIRCActionText
164 public function testIrcMsgForLogTypeMove() {
165 $move_params = array(
166 '4::target' => $this->target
->getPrefixedText(),
169 $sep = $this->context
->msg( 'colon-separator' )->text();
172 $this->assertIRCComment(
173 $this->context
->msg( '1movedto2', 'SomeTitle', 'TestTarget' )
174 ->plain() . $sep . $this->user_comment
,
181 $this->assertIRCComment(
182 $this->context
->msg( '1movedto2_redir', 'SomeTitle', 'TestTarget' )
183 ->plain() . $sep . $this->user_comment
,
184 'move', 'move_redir',
191 * @covers LogFormatter::getIRCActionText
193 public function testIrcMsgForLogTypePatrol() {
195 $this->assertIRCComment(
196 $this->context
->msg( 'patrol-log-line', 'revision 777', '[[SomeTitle]]', '' )->plain(),
200 '5::previd' => '666',
207 * @covers LogFormatter::getIRCActionText
209 public function testIrcMsgForLogTypeProtect() {
210 $protectParams = array(
211 '[edit=sysop] (indefinite) ‎[move=sysop] (indefinite)'
213 $sep = $this->context
->msg( 'colon-separator' )->text();
216 $this->assertIRCComment(
217 $this->context
->msg( 'protectedarticle', 'SomeTitle ' . $protectParams[0] )
218 ->plain() . $sep . $this->user_comment
,
219 'protect', 'protect',
225 $this->assertIRCComment(
226 $this->context
->msg( 'unprotectedarticle', 'SomeTitle' )->plain() . $sep . $this->user_comment
,
227 'protect', 'unprotect',
233 $this->assertIRCComment(
234 $this->context
->msg( 'modifiedarticleprotection', 'SomeTitle ' . $protectParams[0] )
235 ->plain() . $sep . $this->user_comment
,
242 $this->assertIRCComment(
243 $this->context
->msg( 'movedarticleprotection', 'SomeTitle', 'OldTitle' )
244 ->plain() . $sep . $this->user_comment
,
245 'protect', 'move_prot',
252 * @covers LogFormatter::getIRCActionText
254 public function testIrcMsgForLogTypeUpload() {
255 $sep = $this->context
->msg( 'colon-separator' )->text();
258 $this->assertIRCComment(
259 $this->context
->msg( 'uploadedimage', 'SomeTitle' )->plain() . $sep . $this->user_comment
,
266 $this->assertIRCComment(
267 $this->context
->msg( 'overwroteimage', 'SomeTitle' )->plain() . $sep . $this->user_comment
,
268 'upload', 'overwrite',
275 * @covers LogFormatter::getIRCActionText
277 public function testIrcMsgForLogTypeMerge() {
278 $sep = $this->context
->msg( 'colon-separator' )->text();
281 $this->assertIRCComment(
282 $this->context
->msg( 'pagemerge-logentry', 'SomeTitle', 'Dest', 'timestamp' )->plain()
283 . $sep . $this->user_comment
,
287 '5::mergepoint' => 'timestamp',
294 * @covers LogFormatter::getIRCActionText
296 public function testIrcMsgForLogTypeImport() {
297 $sep = $this->context
->msg( 'colon-separator' )->text();
300 $msg = $this->context
->msg( 'import-logentry-upload', 'SomeTitle' )->plain() .
303 $this->assertIRCComment(
311 $msg = $this->context
->msg( 'import-logentry-interwiki', 'SomeTitle' )->plain() .
314 $this->assertIRCComment(
316 'import', 'interwiki',
323 * @todo Emulate these edits somehow and extract
324 * raw edit summary from RecentChange object
328 public function testIrcMsgForBlankingAES() {
329 // $this->context->msg( 'autosumm-blank', .. );
332 public function testIrcMsgForReplaceAES() {
333 // $this->context->msg( 'autosumm-replace', .. );
336 public function testIrcMsgForRollbackAES() {
337 // $this->context->msg( 'revertpage', .. );
340 public function testIrcMsgForUndoAES() {
341 // $this->context->msg( 'undo-summary', .. );
346 * @covers RecentChange::parseParams
348 public function testParseParams() {
356 $this->assertParseParams(
358 'a:1:{s:4:"root";a:2:{s:1:"A";i:1;s:1:"B";s:3:"two";}}'
361 $this->assertParseParams(
366 $this->assertParseParams(
371 $this->assertParseParams(
378 * @param array $expectedParseParams
379 * @param string|null $rawRcParams
381 protected function assertParseParams( $expectedParseParams, $rawRcParams ) {
382 $rc = new RecentChange
;
383 $rc->setAttribs( array( 'rc_params' => $rawRcParams ) );
385 $actualParseParams = $rc->parseParams();
387 $this->assertEquals( $expectedParseParams, $actualParseParams );
391 * @param string $expected Expected IRC text without colors codes
392 * @param string $type Log type (move, delete, suppress, patrol ...)
393 * @param string $action A log type action
394 * @param array $params
395 * @param string $comment (optional) A comment for the log action
396 * @param string $msg (optional) A message for PHPUnit :-)
398 protected function assertIRCComment( $expected, $type, $action, $params,
399 $comment = null, $msg = '', $legacy = false
401 $logEntry = new ManualLogEntry( $type, $action );
402 $logEntry->setPerformer( $this->user
);
403 $logEntry->setTarget( $this->title
);
404 if ( $comment !== null ) {
405 $logEntry->setComment( $comment );
407 $logEntry->setParameters( $params );
408 $logEntry->setLegacy( $legacy );
410 $formatter = LogFormatter
::newFromEntry( $logEntry );
411 $formatter->setContext( $this->context
);
413 // Apply the same transformation as done in IRCColourfulRCFeedFormatter::getLine for rc_comment
414 $ircRcComment = IRCColourfulRCFeedFormatter
::cleanupForIRC( $formatter->getIRCActionComment() );