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):
43 * - newusers/autocreate
47 * - protect/modifyprotect
52 * As well as the following Auto Edit Summaries:
60 * @covers LogFormatter::getIRCActionText
62 public function testIrcMsgForLogTypeBlock() {
63 $sep = $this->context
->msg( 'colon-separator' )->text();
66 $this->assertIRCComment(
67 $this->context
->msg( 'blocklogentry', 'SomeTitle', 'duration', '(flags)' )->plain()
68 . $sep . $this->user_comment
,
71 '5::duration' => 'duration',
72 '6::flags' => 'flags',
77 $this->assertIRCComment(
78 $this->context
->msg( 'unblocklogentry', 'SomeTitle' )->plain() . $sep . $this->user_comment
,
84 $this->assertIRCComment(
85 $this->context
->msg( 'reblock-logentry', 'SomeTitle', 'duration', '(flags)' )->plain()
86 . $sep . $this->user_comment
,
89 '5::duration' => 'duration',
90 '6::flags' => 'flags',
97 * @covers LogFormatter::getIRCActionText
99 public function testIrcMsgForLogTypeDelete() {
100 $sep = $this->context
->msg( 'colon-separator' )->text();
103 $this->assertIRCComment(
104 $this->context
->msg( 'deletedarticle', 'SomeTitle' )->plain() . $sep . $this->user_comment
,
111 $this->assertIRCComment(
112 $this->context
->msg( 'undeletedarticle', 'SomeTitle' )->plain() . $sep . $this->user_comment
,
120 * @covers LogFormatter::getIRCActionText
122 public function testIrcMsgForLogTypeNewusers() {
123 $this->assertIRCComment(
125 'newusers', 'newusers',
128 $this->assertIRCComment(
130 'newusers', 'create',
133 $this->assertIRCComment(
134 'created new account SomeTitle',
135 'newusers', 'create2',
138 $this->assertIRCComment(
139 'Account created automatically',
140 'newusers', 'autocreate',
146 * @covers LogFormatter::getIRCActionText
148 public function testIrcMsgForLogTypeMove() {
149 $move_params = array(
150 '4::target' => $this->target
->getPrefixedText(),
153 $sep = $this->context
->msg( 'colon-separator' )->text();
156 $this->assertIRCComment(
157 $this->context
->msg( '1movedto2', 'SomeTitle', 'TestTarget' )
158 ->plain() . $sep . $this->user_comment
,
165 $this->assertIRCComment(
166 $this->context
->msg( '1movedto2_redir', 'SomeTitle', 'TestTarget' )
167 ->plain() . $sep . $this->user_comment
,
168 'move', 'move_redir',
175 * @covers LogFormatter::getIRCActionText
177 public function testIrcMsgForLogTypePatrol() {
179 $this->assertIRCComment(
180 $this->context
->msg( 'patrol-log-line', 'revision 777', '[[SomeTitle]]', '' )->plain(),
184 '5::previd' => '666',
191 * @covers LogFormatter::getIRCActionText
193 public function testIrcMsgForLogTypeProtect() {
194 $protectParams = array(
195 '[edit=sysop] (indefinite) [move=sysop] (indefinite)'
197 $sep = $this->context
->msg( 'colon-separator' )->text();
200 $this->assertIRCComment(
201 $this->context
->msg( 'protectedarticle', 'SomeTitle ' . $protectParams[0] )
202 ->plain() . $sep . $this->user_comment
,
203 'protect', 'protect',
209 $this->assertIRCComment(
210 $this->context
->msg( 'unprotectedarticle', 'SomeTitle' )->plain() . $sep . $this->user_comment
,
211 'protect', 'unprotect',
217 $this->assertIRCComment(
218 $this->context
->msg( 'modifiedarticleprotection', 'SomeTitle ' . $protectParams[0] )
219 ->plain() . $sep . $this->user_comment
,
227 * @covers LogFormatter::getIRCActionText
229 public function testIrcMsgForLogTypeUpload() {
230 $sep = $this->context
->msg( 'colon-separator' )->text();
233 $this->assertIRCComment(
234 $this->context
->msg( 'uploadedimage', 'SomeTitle' )->plain() . $sep . $this->user_comment
,
241 $this->assertIRCComment(
242 $this->context
->msg( 'overwroteimage', 'SomeTitle' )->plain() . $sep . $this->user_comment
,
243 'upload', 'overwrite',
250 * @covers LogFormatter::getIRCActionText
252 public function testIrcMsgForLogTypeMerge() {
253 $sep = $this->context
->msg( 'colon-separator' )->text();
256 $this->assertIRCComment(
257 $this->context
->msg( 'pagemerge-logentry', 'SomeTitle', 'Dest', 'timestamp' )->plain()
258 . $sep . $this->user_comment
,
262 '5::mergepoint' => 'timestamp',
269 * @todo Emulate these edits somehow and extract
270 * raw edit summary from RecentChange object
274 public function testIrcMsgForBlankingAES() {
275 // $this->context->msg( 'autosumm-blank', .. );
278 public function testIrcMsgForReplaceAES() {
279 // $this->context->msg( 'autosumm-replace', .. );
282 public function testIrcMsgForRollbackAES() {
283 // $this->context->msg( 'revertpage', .. );
286 public function testIrcMsgForUndoAES() {
287 // $this->context->msg( 'undo-summary', .. );
292 * @param string $expected Expected IRC text without colors codes
293 * @param string $type Log type (move, delete, suppress, patrol ...)
294 * @param string $action A log type action
295 * @param array $params
296 * @param string $comment (optional) A comment for the log action
297 * @param string $msg (optional) A message for PHPUnit :-)
299 protected function assertIRCComment( $expected, $type, $action, $params,
300 $comment = null, $msg = ''
302 $logEntry = new ManualLogEntry( $type, $action );
303 $logEntry->setPerformer( $this->user
);
304 $logEntry->setTarget( $this->title
);
305 if ( $comment !== null ) {
306 $logEntry->setComment( $comment );
308 $logEntry->setParameters( $params );
310 $formatter = LogFormatter
::newFromEntry( $logEntry );
311 $formatter->setContext( $this->context
);
313 // Apply the same transformation as done in IRCColourfulRCFeedFormatter::getLine for rc_comment
314 $ircRcComment = IRCColourfulRCFeedFormatter
::cleanupForIRC( $formatter->getIRCActionComment() );