5 class RecentChangeTest
extends MediaWikiTestCase
{
9 protected $user_comment;
12 function __construct() {
13 parent
::__construct();
15 $this->title
= Title
::newFromText( 'SomeTitle' );
16 $this->target
= Title
::newFromText( 'TestTarget' );
17 $this->user
= User
::newFromName( 'UserName' );
19 $this->user_comment
= '<User comment about action>';
20 $this->context
= RequestContext
::newExtraneousContext( $this->title
);
24 * The testIrcMsgForAction* tests are supposed to cover the hacky
25 * LogFormatter::getIRCActionText / bug 34508
27 * Third parties bots listen to those messages. They are clever enough
28 * to fetch the i18n messages from the wiki and then analyze the IRC feed
29 * to reverse engineer the $1, $2 messages.
30 * One thing bots can not detect is when MediaWiki change the meaning of
31 * a message like what happened when we deployed 1.19. $1 became the user
32 * performing the action which broke basically all bots around.
34 * Should cover the following log actions (which are most commonly used by bots):
41 * - newusers/autocreate
45 * - protect/modifyprotect
49 * As well as the following Auto Edit Summaries:
57 * @covers LogFormatter::getIRCActionText
59 function testIrcMsgForLogTypeBlock() {
61 $this->assertIRCComment(
62 $this->context
->msg( 'blocklogentry', 'SomeTitle' )->plain() . ': ' . $this->user_comment
,
68 $this->assertIRCComment(
69 $this->context
->msg( 'unblocklogentry', 'SomeTitle' )->plain() . ': ' . $this->user_comment
,
77 * @covers LogFormatter::getIRCActionText
79 function testIrcMsgForLogTypeDelete() {
81 $this->assertIRCComment(
82 $this->context
->msg( 'deletedarticle', 'SomeTitle' )->plain() . ': ' . $this->user_comment
,
89 $this->assertIRCComment(
90 $this->context
->msg( 'undeletedarticle', 'SomeTitle' )->plain() . ': ' . $this->user_comment
,
98 * @covers LogFormatter::getIRCActionText
100 function testIrcMsgForLogTypeNewusers() {
101 $this->assertIRCComment(
103 'newusers', 'newusers',
106 $this->assertIRCComment(
108 'newusers', 'create',
111 $this->assertIRCComment(
112 'created new account SomeTitle',
113 'newusers', 'create2',
116 $this->assertIRCComment(
117 'Account created automatically',
118 'newusers', 'autocreate',
124 * @covers LogFormatter::getIRCActionText
126 function testIrcMsgForLogTypeMove() {
127 $move_params = array(
128 '4::target' => $this->target
->getPrefixedText(),
133 $this->assertIRCComment(
134 $this->context
->msg( '1movedto2', 'SomeTitle', 'TestTarget' )->plain() . ': ' . $this->user_comment
,
141 $this->assertIRCComment(
142 $this->context
->msg( '1movedto2_redir', 'SomeTitle', 'TestTarget' )->plain() . ': ' . $this->user_comment
,
143 'move', 'move_redir',
150 * @covers LogFormatter::getIRCActionText
152 function testIrcMsgForLogTypePatrol() {
154 $this->assertIRCComment(
155 $this->context
->msg( 'patrol-log-line', 'revision 777', '[[SomeTitle]]', '' )->plain(),
159 '5::previd' => '666',
166 * @covers LogFormatter::getIRCActionText
168 function testIrcMsgForLogTypeProtect() {
169 $protectParams = array(
170 '[edit=sysop] (indefinite) [move=sysop] (indefinite)'
174 $this->assertIRCComment(
175 $this->context
->msg( 'protectedarticle', 'SomeTitle ' . $protectParams[0] )->plain() . ': ' . $this->user_comment
,
176 'protect', 'protect',
182 $this->assertIRCComment(
183 $this->context
->msg( 'unprotectedarticle', 'SomeTitle' )->plain() . ': ' . $this->user_comment
,
184 'protect', 'unprotect',
190 $this->assertIRCComment(
191 $this->context
->msg( 'modifiedarticleprotection', 'SomeTitle ' . $protectParams[0] )->plain() . ': ' . $this->user_comment
,
199 * @covers LogFormatter::getIRCActionText
201 function testIrcMsgForLogTypeUpload() {
203 $this->assertIRCComment(
204 $this->context
->msg( 'uploadedimage', 'SomeTitle' )->plain() . ': ' . $this->user_comment
,
211 $this->assertIRCComment(
212 $this->context
->msg( 'overwroteimage', 'SomeTitle' )->plain() . ': ' . $this->user_comment
,
213 'upload', 'overwrite',
220 * @todo: Emulate these edits somehow and extract
221 * raw edit summary from RecentChange object
225 function testIrcMsgForBlankingAES() {
226 // $this->context->msg( 'autosumm-blank', .. );
229 function testIrcMsgForReplaceAES() {
230 // $this->context->msg( 'autosumm-replace', .. );
233 function testIrcMsgForRollbackAES() {
234 // $this->context->msg( 'revertpage', .. );
237 function testIrcMsgForUndoAES() {
238 // $this->context->msg( 'undo-summary', .. );
244 * @param $expected String Expected IRC text without colors codes
245 * @param $type String Log type (move, delete, suppress, patrol ...)
246 * @param $action String A log type action
247 * @param $comment String (optional) A comment for the log action
248 * @param $msg String (optional) A message for PHPUnit :-)
250 function assertIRCComment( $expected, $type, $action, $params, $comment = null, $msg = '' ) {
252 $logEntry = new ManualLogEntry( $type, $action );
253 $logEntry->setPerformer( $this->user
);
254 $logEntry->setTarget( $this->title
);
255 if ( $comment !== null ) {
256 $logEntry->setComment( $comment );
258 $logEntry->setParameters( $params );
260 $formatter = LogFormatter
::newFromEntry( $logEntry );
261 $formatter->setContext( $this->context
);
263 // Apply the same transformation as done in RecentChange::getIRCLine for rc_comment
264 $ircRcComment = RecentChange
::cleanupForIRC( $formatter->getIRCActionComment() );