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() {
60 $sep = $this->context
->msg( 'colon-separator' )->text();
63 $this->assertIRCComment(
64 $this->context
->msg( 'blocklogentry', 'SomeTitle' )->plain() . $sep . $this->user_comment
,
70 $this->assertIRCComment(
71 $this->context
->msg( 'unblocklogentry', 'SomeTitle' )->plain() . $sep . $this->user_comment
,
79 * @covers LogFormatter::getIRCActionText
81 function testIrcMsgForLogTypeDelete() {
82 $sep = $this->context
->msg( 'colon-separator' )->text();
85 $this->assertIRCComment(
86 $this->context
->msg( 'deletedarticle', 'SomeTitle' )->plain() . $sep . $this->user_comment
,
93 $this->assertIRCComment(
94 $this->context
->msg( 'undeletedarticle', 'SomeTitle' )->plain() . $sep . $this->user_comment
,
102 * @covers LogFormatter::getIRCActionText
104 function testIrcMsgForLogTypeNewusers() {
105 $this->assertIRCComment(
107 'newusers', 'newusers',
110 $this->assertIRCComment(
112 'newusers', 'create',
115 $this->assertIRCComment(
116 'created new account SomeTitle',
117 'newusers', 'create2',
120 $this->assertIRCComment(
121 'Account created automatically',
122 'newusers', 'autocreate',
128 * @covers LogFormatter::getIRCActionText
130 function testIrcMsgForLogTypeMove() {
131 $move_params = array(
132 '4::target' => $this->target
->getPrefixedText(),
135 $sep = $this->context
->msg( 'colon-separator' )->text();
138 $this->assertIRCComment(
139 $this->context
->msg( '1movedto2', 'SomeTitle', 'TestTarget' )->plain() . $sep . $this->user_comment
,
146 $this->assertIRCComment(
147 $this->context
->msg( '1movedto2_redir', 'SomeTitle', 'TestTarget' )->plain() . $sep . $this->user_comment
,
148 'move', 'move_redir',
155 * @covers LogFormatter::getIRCActionText
157 function testIrcMsgForLogTypePatrol() {
159 $this->assertIRCComment(
160 $this->context
->msg( 'patrol-log-line', 'revision 777', '[[SomeTitle]]', '' )->plain(),
164 '5::previd' => '666',
171 * @covers LogFormatter::getIRCActionText
173 function testIrcMsgForLogTypeProtect() {
174 $protectParams = array(
175 '[edit=sysop] (indefinite) [move=sysop] (indefinite)'
177 $sep = $this->context
->msg( 'colon-separator' )->text();
180 $this->assertIRCComment(
181 $this->context
->msg( 'protectedarticle', 'SomeTitle ' . $protectParams[0] )->plain() . $sep . $this->user_comment
,
182 'protect', 'protect',
188 $this->assertIRCComment(
189 $this->context
->msg( 'unprotectedarticle', 'SomeTitle' )->plain() . $sep . $this->user_comment
,
190 'protect', 'unprotect',
196 $this->assertIRCComment(
197 $this->context
->msg( 'modifiedarticleprotection', 'SomeTitle ' . $protectParams[0] )->plain() . $sep . $this->user_comment
,
205 * @covers LogFormatter::getIRCActionText
207 function testIrcMsgForLogTypeUpload() {
208 $sep = $this->context
->msg( 'colon-separator' )->text();
211 $this->assertIRCComment(
212 $this->context
->msg( 'uploadedimage', 'SomeTitle' )->plain() . $sep . $this->user_comment
,
219 $this->assertIRCComment(
220 $this->context
->msg( 'overwroteimage', 'SomeTitle' )->plain() . $sep . $this->user_comment
,
221 'upload', 'overwrite',
228 * @todo Emulate these edits somehow and extract
229 * raw edit summary from RecentChange object
233 function testIrcMsgForBlankingAES() {
234 // $this->context->msg( 'autosumm-blank', .. );
237 function testIrcMsgForReplaceAES() {
238 // $this->context->msg( 'autosumm-replace', .. );
241 function testIrcMsgForRollbackAES() {
242 // $this->context->msg( 'revertpage', .. );
245 function testIrcMsgForUndoAES() {
246 // $this->context->msg( 'undo-summary', .. );
251 * @param $expected String Expected IRC text without colors codes
252 * @param $type String Log type (move, delete, suppress, patrol ...)
253 * @param $action String A log type action
254 * @param $comment String (optional) A comment for the log action
255 * @param $msg String (optional) A message for PHPUnit :-)
257 function assertIRCComment( $expected, $type, $action, $params, $comment = null, $msg = '' ) {
259 $logEntry = new ManualLogEntry( $type, $action );
260 $logEntry->setPerformer( $this->user
);
261 $logEntry->setTarget( $this->title
);
262 if ( $comment !== null ) {
263 $logEntry->setComment( $comment );
265 $logEntry->setParameters( $params );
267 $formatter = LogFormatter
::newFromEntry( $logEntry );
268 $formatter->setContext( $this->context
);
270 // Apply the same transformation as done in RecentChange::getIRCLine for rc_comment
271 $ircRcComment = RecentChange
::cleanupForIRC( $formatter->getIRCActionComment() );