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
54 * As well as the following Auto Edit Summaries:
62 * @covers LogFormatter::getIRCActionText
64 public function testIrcMsgForLogTypeBlock() {
65 $sep = $this->context
->msg( 'colon-separator' )->text();
68 $this->assertIRCComment(
69 $this->context
->msg( 'blocklogentry', 'SomeTitle', 'duration', '(flags)' )->plain()
70 . $sep . $this->user_comment
,
73 '5::duration' => 'duration',
74 '6::flags' => 'flags',
79 $this->assertIRCComment(
80 $this->context
->msg( 'unblocklogentry', 'SomeTitle' )->plain() . $sep . $this->user_comment
,
86 $this->assertIRCComment(
87 $this->context
->msg( 'reblock-logentry', 'SomeTitle', 'duration', '(flags)' )->plain()
88 . $sep . $this->user_comment
,
91 '5::duration' => 'duration',
92 '6::flags' => 'flags',
99 * @covers LogFormatter::getIRCActionText
101 public function testIrcMsgForLogTypeDelete() {
102 $sep = $this->context
->msg( 'colon-separator' )->text();
105 $this->assertIRCComment(
106 $this->context
->msg( 'deletedarticle', 'SomeTitle' )->plain() . $sep . $this->user_comment
,
113 $this->assertIRCComment(
114 $this->context
->msg( 'undeletedarticle', 'SomeTitle' )->plain() . $sep . $this->user_comment
,
122 * @covers LogFormatter::getIRCActionText
124 public function testIrcMsgForLogTypeNewusers() {
125 $this->assertIRCComment(
127 'newusers', 'newusers',
130 $this->assertIRCComment(
132 'newusers', 'create',
135 $this->assertIRCComment(
136 'created new account SomeTitle',
137 'newusers', 'create2',
140 $this->assertIRCComment(
141 'Account created automatically',
142 'newusers', 'autocreate',
148 * @covers LogFormatter::getIRCActionText
150 public function testIrcMsgForLogTypeMove() {
151 $move_params = array(
152 '4::target' => $this->target
->getPrefixedText(),
155 $sep = $this->context
->msg( 'colon-separator' )->text();
158 $this->assertIRCComment(
159 $this->context
->msg( '1movedto2', 'SomeTitle', 'TestTarget' )
160 ->plain() . $sep . $this->user_comment
,
167 $this->assertIRCComment(
168 $this->context
->msg( '1movedto2_redir', 'SomeTitle', 'TestTarget' )
169 ->plain() . $sep . $this->user_comment
,
170 'move', 'move_redir',
177 * @covers LogFormatter::getIRCActionText
179 public function testIrcMsgForLogTypePatrol() {
181 $this->assertIRCComment(
182 $this->context
->msg( 'patrol-log-line', 'revision 777', '[[SomeTitle]]', '' )->plain(),
186 '5::previd' => '666',
193 * @covers LogFormatter::getIRCActionText
195 public function testIrcMsgForLogTypeProtect() {
196 $protectParams = array(
197 '[edit=sysop] (indefinite) [move=sysop] (indefinite)'
199 $sep = $this->context
->msg( 'colon-separator' )->text();
202 $this->assertIRCComment(
203 $this->context
->msg( 'protectedarticle', 'SomeTitle ' . $protectParams[0] )
204 ->plain() . $sep . $this->user_comment
,
205 'protect', 'protect',
211 $this->assertIRCComment(
212 $this->context
->msg( 'unprotectedarticle', 'SomeTitle' )->plain() . $sep . $this->user_comment
,
213 'protect', 'unprotect',
219 $this->assertIRCComment(
220 $this->context
->msg( 'modifiedarticleprotection', 'SomeTitle ' . $protectParams[0] )
221 ->plain() . $sep . $this->user_comment
,
229 * @covers LogFormatter::getIRCActionText
231 public function testIrcMsgForLogTypeUpload() {
232 $sep = $this->context
->msg( 'colon-separator' )->text();
235 $this->assertIRCComment(
236 $this->context
->msg( 'uploadedimage', 'SomeTitle' )->plain() . $sep . $this->user_comment
,
243 $this->assertIRCComment(
244 $this->context
->msg( 'overwroteimage', 'SomeTitle' )->plain() . $sep . $this->user_comment
,
245 'upload', 'overwrite',
252 * @covers LogFormatter::getIRCActionText
254 public function testIrcMsgForLogTypeMerge() {
255 $sep = $this->context
->msg( 'colon-separator' )->text();
258 $this->assertIRCComment(
259 $this->context
->msg( 'pagemerge-logentry', 'SomeTitle', 'Dest', 'timestamp' )->plain()
260 . $sep . $this->user_comment
,
264 '5::mergepoint' => 'timestamp',
271 * @covers LogFormatter::getIRCActionText
273 public function testIrcMsgForLogTypeImport() {
274 $sep = $this->context
->msg( 'colon-separator' )->text();
277 $this->assertIRCComment(
278 $this->context
->msg( 'import-logentry-upload', 'SomeTitle' )->plain() . $sep . $this->user_comment
,
285 $this->assertIRCComment(
286 $this->context
->msg( 'import-logentry-interwiki', 'SomeTitle' )->plain() . $sep . $this->user_comment
,
287 'import', 'interwiki',
294 * @todo Emulate these edits somehow and extract
295 * raw edit summary from RecentChange object
299 public function testIrcMsgForBlankingAES() {
300 // $this->context->msg( 'autosumm-blank', .. );
303 public function testIrcMsgForReplaceAES() {
304 // $this->context->msg( 'autosumm-replace', .. );
307 public function testIrcMsgForRollbackAES() {
308 // $this->context->msg( 'revertpage', .. );
311 public function testIrcMsgForUndoAES() {
312 // $this->context->msg( 'undo-summary', .. );
317 * @param string $expected Expected IRC text without colors codes
318 * @param string $type Log type (move, delete, suppress, patrol ...)
319 * @param string $action A log type action
320 * @param array $params
321 * @param string $comment (optional) A comment for the log action
322 * @param string $msg (optional) A message for PHPUnit :-)
324 protected function assertIRCComment( $expected, $type, $action, $params,
325 $comment = null, $msg = ''
327 $logEntry = new ManualLogEntry( $type, $action );
328 $logEntry->setPerformer( $this->user
);
329 $logEntry->setTarget( $this->title
);
330 if ( $comment !== null ) {
331 $logEntry->setComment( $comment );
333 $logEntry->setParameters( $params );
335 $formatter = LogFormatter
::newFromEntry( $logEntry );
336 $formatter->setContext( $this->context
);
338 // Apply the same transformation as done in IRCColourfulRCFeedFormatter::getLine for rc_comment
339 $ircRcComment = IRCColourfulRCFeedFormatter
::cleanupForIRC( $formatter->getIRCActionComment() );