7865ed24b68c6af3860986bd721bc552a11b5a8b
2 class RecentChangeTest
extends MediaWikiTestCase
{
6 protected $user_comment;
9 function __construct() {
10 parent
::__construct();
12 $this->title
= Title
::newFromText( 'SomeTitle' );
13 $this->target
= Title
::newFromText( 'TestTarget' );
14 $this->user
= User
::newFromName( 'UserName' );
16 $this->user_comment
= '<User comment about action>';
17 $this->context
= RequestContext
::newExtraneousContext( $this->title
);
21 * The testIrcMsgForAction* tests are supposed to cover the hacky
22 * LogFormatter::getIRCActionText / bug 34508
24 * Third parties bots listen to those messages. They are clever enough
25 * to fetch the i18n messages from the wiki and then analyze the IRC feed
26 * to reverse engineer the $1, $2 messages.
27 * One thing bots can not detect is when MediaWiki change the meaning of
28 * a message like what happened when we deployed 1.19. $1 became the user
29 * performing the action which broke basically all bots around.
31 * Should cover the following log actions (which are most commonly used by bots):
38 * - newusers/autocreate
42 * - protect/modifyprotect
46 * As well as the following Auto Edit Summaries:
54 * @covers LogFormatter::getIRCActionText
56 function testIrcMsgForLogTypeBlock() {
58 $this->assertIRCComment(
59 $this->context
->msg( 'blocklogentry', 'SomeTitle' )->plain() . ': ' . $this->user_comment
,
65 $this->assertIRCComment(
66 $this->context
->msg( 'unblocklogentry', 'SomeTitle' )->plain() . ': ' . $this->user_comment
,
74 * @covers LogFormatter::getIRCActionText
76 function testIrcMsgForLogTypeDelete() {
78 $this->assertIRCComment(
79 $this->context
->msg( 'deletedarticle', 'SomeTitle' )->plain() . ': ' . $this->user_comment
,
86 $this->assertIRCComment(
87 $this->context
->msg( 'undeletedarticle', 'SomeTitle' )->plain() . ': ' . $this->user_comment
,
95 * @covers LogFormatter::getIRCActionText
97 function testIrcMsgForLogTypeNewusers() {
98 $this->assertIRCComment(
100 'newusers', 'newusers',
103 $this->assertIRCComment(
105 'newusers', 'create',
108 $this->assertIRCComment(
109 'created new account SomeTitle',
110 'newusers', 'create2',
113 $this->assertIRCComment(
114 'Account created automatically',
115 'newusers', 'autocreate',
121 * @covers LogFormatter::getIRCActionText
123 function testIrcMsgForLogTypeMove() {
124 $move_params = array(
125 '4::target' => $this->target
->getPrefixedText(),
130 $this->assertIRCComment(
131 $this->context
->msg( '1movedto2', 'SomeTitle', 'TestTarget' )->plain() . ': ' . $this->user_comment
,
138 $this->assertIRCComment(
139 $this->context
->msg( '1movedto2_redir', 'SomeTitle', 'TestTarget' )->plain() . ': ' . $this->user_comment
,
140 'move', 'move_redir',
147 * @covers LogFormatter::getIRCActionText
149 function testIrcMsgForLogTypePatrol() {
151 $this->assertIRCComment(
152 $this->context
->msg( 'patrol-log-line', 'revision 777', '[[SomeTitle]]', '' )->plain(),
156 '5::previd' => '666',
163 * @covers LogFormatter::getIRCActionText
165 function testIrcMsgForLogTypeProtect() {
166 $protectParams = array(
167 '[edit=sysop] (indefinite) [move=sysop] (indefinite)'
171 $this->assertIRCComment(
172 $this->context
->msg( 'protectedarticle', 'SomeTitle ' . $protectParams[0] )->plain() . ': ' . $this->user_comment
,
173 'protect', 'protect',
179 $this->assertIRCComment(
180 $this->context
->msg( 'unprotectedarticle', 'SomeTitle' )->plain() . ': ' . $this->user_comment
,
181 'protect', 'unprotect',
187 $this->assertIRCComment(
188 $this->context
->msg( 'modifiedarticleprotection', 'SomeTitle ' . $protectParams[0] )->plain() . ': ' . $this->user_comment
,
196 * @covers LogFormatter::getIRCActionText
198 function testIrcMsgForLogTypeUpload() {
200 $this->assertIRCComment(
201 $this->context
->msg( 'uploadedimage', 'SomeTitle' )->plain() . ': ' . $this->user_comment
,
208 $this->assertIRCComment(
209 $this->context
->msg( 'overwroteimage', 'SomeTitle' )->plain() . ': ' . $this->user_comment
,
210 'upload', 'overwrite',
217 * @todo: Emulate these edits somehow and extract
218 * raw edit summary from RecentChange object
221 function testIrcMsgForBlankingAES() {
222 // $this->context->msg( 'autosumm-blank', .. );
225 function testIrcMsgForReplaceAES() {
226 // $this->context->msg( 'autosumm-replace', .. );
229 function testIrcMsgForRollbackAES() {
230 // $this->context->msg( 'revertpage', .. );
233 function testIrcMsgForUndoAES() {
234 // $this->context->msg( 'undo-summary', .. );
241 * @param $expected String Expected IRC text without colors codes
242 * @param $type String Log type (move, delete, suppress, patrol ...)
243 * @param $action String A log type action
244 * @param $comment String (optional) A comment for the log action
245 * @param $msg String (optional) A message for PHPUnit :-)
247 function assertIRCComment( $expected, $type, $action, $params, $comment = null, $msg = '' ) {
249 $logEntry = new ManualLogEntry( $type, $action );
250 $logEntry->setPerformer( $this->user
);
251 $logEntry->setTarget( $this->title
);
252 if ( $comment !== null ) {
253 $logEntry->setComment( $comment );
255 $logEntry->setParameters( $params );
257 $formatter = LogFormatter
::newFromEntry( $logEntry );
258 $formatter->setContext( $this->context
);
260 // Apply the same transformation as done in RecentChange::getIRCLine for rc_comment
261 $ircRcComment = RecentChange
::cleanupForIRC( $formatter->getIRCActionComment() );