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
50 * As well as the following Auto Edit Summaries:
58 * @covers LogFormatter::getIRCActionText
60 public function testIrcMsgForLogTypeBlock() {
61 $sep = $this->context
->msg( 'colon-separator' )->text();
64 $this->assertIRCComment(
65 $this->context
->msg( 'blocklogentry', 'SomeTitle' )->plain() . $sep . $this->user_comment
,
71 $this->assertIRCComment(
72 $this->context
->msg( 'unblocklogentry', 'SomeTitle' )->plain() . $sep . $this->user_comment
,
80 * @covers LogFormatter::getIRCActionText
82 public function testIrcMsgForLogTypeDelete() {
83 $sep = $this->context
->msg( 'colon-separator' )->text();
86 $this->assertIRCComment(
87 $this->context
->msg( 'deletedarticle', 'SomeTitle' )->plain() . $sep . $this->user_comment
,
94 $this->assertIRCComment(
95 $this->context
->msg( 'undeletedarticle', 'SomeTitle' )->plain() . $sep . $this->user_comment
,
103 * @covers LogFormatter::getIRCActionText
105 public function testIrcMsgForLogTypeNewusers() {
106 $this->assertIRCComment(
108 'newusers', 'newusers',
111 $this->assertIRCComment(
113 'newusers', 'create',
116 $this->assertIRCComment(
117 'created new account SomeTitle',
118 'newusers', 'create2',
121 $this->assertIRCComment(
122 'Account created automatically',
123 'newusers', 'autocreate',
129 * @covers LogFormatter::getIRCActionText
131 public function testIrcMsgForLogTypeMove() {
132 $move_params = array(
133 '4::target' => $this->target
->getPrefixedText(),
136 $sep = $this->context
->msg( 'colon-separator' )->text();
139 $this->assertIRCComment(
140 $this->context
->msg( '1movedto2', 'SomeTitle', 'TestTarget' )
141 ->plain() . $sep . $this->user_comment
,
148 $this->assertIRCComment(
149 $this->context
->msg( '1movedto2_redir', 'SomeTitle', 'TestTarget' )
150 ->plain() . $sep . $this->user_comment
,
151 'move', 'move_redir',
158 * @covers LogFormatter::getIRCActionText
160 public function testIrcMsgForLogTypePatrol() {
162 $this->assertIRCComment(
163 $this->context
->msg( 'patrol-log-line', 'revision 777', '[[SomeTitle]]', '' )->plain(),
167 '5::previd' => '666',
174 * @covers LogFormatter::getIRCActionText
176 public function testIrcMsgForLogTypeProtect() {
177 $protectParams = array(
178 '[edit=sysop] (indefinite) [move=sysop] (indefinite)'
180 $sep = $this->context
->msg( 'colon-separator' )->text();
183 $this->assertIRCComment(
184 $this->context
->msg( 'protectedarticle', 'SomeTitle ' . $protectParams[0] )
185 ->plain() . $sep . $this->user_comment
,
186 'protect', 'protect',
192 $this->assertIRCComment(
193 $this->context
->msg( 'unprotectedarticle', 'SomeTitle' )->plain() . $sep . $this->user_comment
,
194 'protect', 'unprotect',
200 $this->assertIRCComment(
201 $this->context
->msg( 'modifiedarticleprotection', 'SomeTitle ' . $protectParams[0] )
202 ->plain() . $sep . $this->user_comment
,
210 * @covers LogFormatter::getIRCActionText
212 public function testIrcMsgForLogTypeUpload() {
213 $sep = $this->context
->msg( 'colon-separator' )->text();
216 $this->assertIRCComment(
217 $this->context
->msg( 'uploadedimage', 'SomeTitle' )->plain() . $sep . $this->user_comment
,
224 $this->assertIRCComment(
225 $this->context
->msg( 'overwroteimage', 'SomeTitle' )->plain() . $sep . $this->user_comment
,
226 'upload', 'overwrite',
233 * @todo Emulate these edits somehow and extract
234 * raw edit summary from RecentChange object
238 public function testIrcMsgForBlankingAES() {
239 // $this->context->msg( 'autosumm-blank', .. );
242 public function testIrcMsgForReplaceAES() {
243 // $this->context->msg( 'autosumm-replace', .. );
246 public function testIrcMsgForRollbackAES() {
247 // $this->context->msg( 'revertpage', .. );
250 public function testIrcMsgForUndoAES() {
251 // $this->context->msg( 'undo-summary', .. );
256 * @param $expected String Expected IRC text without colors codes
257 * @param $type String Log type (move, delete, suppress, patrol ...)
258 * @param $action String A log type action
260 * @param $comment String (optional) A comment for the log action
261 * @param $msg String (optional) A message for PHPUnit :-)
263 protected function assertIRCComment( $expected, $type, $action, $params,
264 $comment = null, $msg = ''
266 $logEntry = new ManualLogEntry( $type, $action );
267 $logEntry->setPerformer( $this->user
);
268 $logEntry->setTarget( $this->title
);
269 if ( $comment !== null ) {
270 $logEntry->setComment( $comment );
272 $logEntry->setParameters( $params );
274 $formatter = LogFormatter
::newFromEntry( $logEntry );
275 $formatter->setContext( $this->context
);
277 // Apply the same transformation as done in IRCColourfulRCFeedFormatter::getLine for rc_comment
278 $ircRcComment = IRCColourfulRCFeedFormatter
::cleanupForIRC( $formatter->getIRCActionComment() );