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',
247 '4::oldtitle' => 'OldTitle'
254 * @covers LogFormatter::getIRCActionText
256 public function testIrcMsgForLogTypeUpload() {
257 $sep = $this->context
->msg( 'colon-separator' )->text();
260 $this->assertIRCComment(
261 $this->context
->msg( 'uploadedimage', 'SomeTitle' )->plain() . $sep . $this->user_comment
,
268 $this->assertIRCComment(
269 $this->context
->msg( 'overwroteimage', 'SomeTitle' )->plain() . $sep . $this->user_comment
,
270 'upload', 'overwrite',
277 * @covers LogFormatter::getIRCActionText
279 public function testIrcMsgForLogTypeMerge() {
280 $sep = $this->context
->msg( 'colon-separator' )->text();
283 $this->assertIRCComment(
284 $this->context
->msg( 'pagemerge-logentry', 'SomeTitle', 'Dest', 'timestamp' )->plain()
285 . $sep . $this->user_comment
,
289 '5::mergepoint' => 'timestamp',
296 * @covers LogFormatter::getIRCActionText
298 public function testIrcMsgForLogTypeImport() {
299 $sep = $this->context
->msg( 'colon-separator' )->text();
302 $msg = $this->context
->msg( 'import-logentry-upload', 'SomeTitle' )->plain() .
305 $this->assertIRCComment(
313 $msg = $this->context
->msg( 'import-logentry-interwiki', 'SomeTitle' )->plain() .
316 $this->assertIRCComment(
318 'import', 'interwiki',
325 * @todo Emulate these edits somehow and extract
326 * raw edit summary from RecentChange object
330 public function testIrcMsgForBlankingAES() {
331 // $this->context->msg( 'autosumm-blank', .. );
334 public function testIrcMsgForReplaceAES() {
335 // $this->context->msg( 'autosumm-replace', .. );
338 public function testIrcMsgForRollbackAES() {
339 // $this->context->msg( 'revertpage', .. );
342 public function testIrcMsgForUndoAES() {
343 // $this->context->msg( 'undo-summary', .. );
348 * @covers RecentChange::parseParams
350 public function testParseParams() {
358 $this->assertParseParams(
360 'a:1:{s:4:"root";a:2:{s:1:"A";i:1;s:1:"B";s:3:"two";}}'
363 $this->assertParseParams(
368 $this->assertParseParams(
373 $this->assertParseParams(
380 * @param array $expectedParseParams
381 * @param string|null $rawRcParams
383 protected function assertParseParams( $expectedParseParams, $rawRcParams ) {
384 $rc = new RecentChange
;
385 $rc->setAttribs( array( 'rc_params' => $rawRcParams ) );
387 $actualParseParams = $rc->parseParams();
389 $this->assertEquals( $expectedParseParams, $actualParseParams );
393 * @param string $expected Expected IRC text without colors codes
394 * @param string $type Log type (move, delete, suppress, patrol ...)
395 * @param string $action A log type action
396 * @param array $params
397 * @param string $comment (optional) A comment for the log action
398 * @param string $msg (optional) A message for PHPUnit :-)
400 protected function assertIRCComment( $expected, $type, $action, $params,
401 $comment = null, $msg = '', $legacy = false
403 $logEntry = new ManualLogEntry( $type, $action );
404 $logEntry->setPerformer( $this->user
);
405 $logEntry->setTarget( $this->title
);
406 if ( $comment !== null ) {
407 $logEntry->setComment( $comment );
409 $logEntry->setParameters( $params );
410 $logEntry->setLegacy( $legacy );
412 $formatter = LogFormatter
::newFromEntry( $logEntry );
413 $formatter->setContext( $this->context
);
415 // Apply the same transformation as done in IRCColourfulRCFeedFormatter::getLine for rc_comment
416 $ircRcComment = IRCColourfulRCFeedFormatter
::cleanupForIRC( $formatter->getIRCActionComment() );