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):
42 * - newusers/autocreate
46 * - protect/modifyprotect
51 * As well as the following Auto Edit Summaries:
59 * @covers LogFormatter::getIRCActionText
61 public function testIrcMsgForLogTypeBlock() {
62 $sep = $this->context
->msg( 'colon-separator' )->text();
65 $this->assertIRCComment(
66 $this->context
->msg( 'blocklogentry', 'SomeTitle' )->plain() . $sep . $this->user_comment
,
72 $this->assertIRCComment(
73 $this->context
->msg( 'unblocklogentry', 'SomeTitle' )->plain() . $sep . $this->user_comment
,
81 * @covers LogFormatter::getIRCActionText
83 public function testIrcMsgForLogTypeDelete() {
84 $sep = $this->context
->msg( 'colon-separator' )->text();
87 $this->assertIRCComment(
88 $this->context
->msg( 'deletedarticle', 'SomeTitle' )->plain() . $sep . $this->user_comment
,
95 $this->assertIRCComment(
96 $this->context
->msg( 'undeletedarticle', 'SomeTitle' )->plain() . $sep . $this->user_comment
,
104 * @covers LogFormatter::getIRCActionText
106 public function testIrcMsgForLogTypeNewusers() {
107 $this->assertIRCComment(
109 'newusers', 'newusers',
112 $this->assertIRCComment(
114 'newusers', 'create',
117 $this->assertIRCComment(
118 'created new account SomeTitle',
119 'newusers', 'create2',
122 $this->assertIRCComment(
123 'Account created automatically',
124 'newusers', 'autocreate',
130 * @covers LogFormatter::getIRCActionText
132 public function testIrcMsgForLogTypeMove() {
133 $move_params = array(
134 '4::target' => $this->target
->getPrefixedText(),
137 $sep = $this->context
->msg( 'colon-separator' )->text();
140 $this->assertIRCComment(
141 $this->context
->msg( '1movedto2', 'SomeTitle', 'TestTarget' )
142 ->plain() . $sep . $this->user_comment
,
149 $this->assertIRCComment(
150 $this->context
->msg( '1movedto2_redir', 'SomeTitle', 'TestTarget' )
151 ->plain() . $sep . $this->user_comment
,
152 'move', 'move_redir',
159 * @covers LogFormatter::getIRCActionText
161 public function testIrcMsgForLogTypePatrol() {
163 $this->assertIRCComment(
164 $this->context
->msg( 'patrol-log-line', 'revision 777', '[[SomeTitle]]', '' )->plain(),
168 '5::previd' => '666',
175 * @covers LogFormatter::getIRCActionText
177 public function testIrcMsgForLogTypeProtect() {
178 $protectParams = array(
179 '[edit=sysop] (indefinite) [move=sysop] (indefinite)'
181 $sep = $this->context
->msg( 'colon-separator' )->text();
184 $this->assertIRCComment(
185 $this->context
->msg( 'protectedarticle', 'SomeTitle ' . $protectParams[0] )
186 ->plain() . $sep . $this->user_comment
,
187 'protect', 'protect',
193 $this->assertIRCComment(
194 $this->context
->msg( 'unprotectedarticle', 'SomeTitle' )->plain() . $sep . $this->user_comment
,
195 'protect', 'unprotect',
201 $this->assertIRCComment(
202 $this->context
->msg( 'modifiedarticleprotection', 'SomeTitle ' . $protectParams[0] )
203 ->plain() . $sep . $this->user_comment
,
211 * @covers LogFormatter::getIRCActionText
213 public function testIrcMsgForLogTypeUpload() {
214 $sep = $this->context
->msg( 'colon-separator' )->text();
217 $this->assertIRCComment(
218 $this->context
->msg( 'uploadedimage', 'SomeTitle' )->plain() . $sep . $this->user_comment
,
225 $this->assertIRCComment(
226 $this->context
->msg( 'overwroteimage', 'SomeTitle' )->plain() . $sep . $this->user_comment
,
227 'upload', 'overwrite',
234 * @covers LogFormatter::getIRCActionText
236 public function testIrcMsgForLogTypeMerge() {
237 $sep = $this->context
->msg( 'colon-separator' )->text();
240 $this->assertIRCComment(
241 $this->context
->msg( 'pagemerge-logentry', 'SomeTitle', 'Dest', 'timestamp' )->plain()
242 . $sep . $this->user_comment
,
246 '5::mergepoint' => 'timestamp',
253 * @todo Emulate these edits somehow and extract
254 * raw edit summary from RecentChange object
258 public function testIrcMsgForBlankingAES() {
259 // $this->context->msg( 'autosumm-blank', .. );
262 public function testIrcMsgForReplaceAES() {
263 // $this->context->msg( 'autosumm-replace', .. );
266 public function testIrcMsgForRollbackAES() {
267 // $this->context->msg( 'revertpage', .. );
270 public function testIrcMsgForUndoAES() {
271 // $this->context->msg( 'undo-summary', .. );
276 * @param string $expected Expected IRC text without colors codes
277 * @param string $type Log type (move, delete, suppress, patrol ...)
278 * @param string $action A log type action
279 * @param array $params
280 * @param string $comment (optional) A comment for the log action
281 * @param string $msg (optional) A message for PHPUnit :-)
283 protected function assertIRCComment( $expected, $type, $action, $params,
284 $comment = null, $msg = ''
286 $logEntry = new ManualLogEntry( $type, $action );
287 $logEntry->setPerformer( $this->user
);
288 $logEntry->setTarget( $this->title
);
289 if ( $comment !== null ) {
290 $logEntry->setComment( $comment );
292 $logEntry->setParameters( $params );
294 $formatter = LogFormatter
::newFromEntry( $logEntry );
295 $formatter->setContext( $this->context
);
297 // Apply the same transformation as done in IRCColourfulRCFeedFormatter::getLine for rc_comment
298 $ircRcComment = IRCColourfulRCFeedFormatter
::cleanupForIRC( $formatter->getIRCActionComment() );