wiki.techinc.nl/tests/phpunit/includes/changes/RecentChangeTest.php

372 lines
9.3 KiB
PHP
Raw Normal View History

2012-02-25 21:22:49 +00:00
<?php
/**
* @group Database
*/
2012-02-25 21:22:49 +00:00
class RecentChangeTest extends MediaWikiTestCase {
protected $title;
protected $target;
protected $user;
protected $user_comment;
protected $context;
2012-02-25 21:22:49 +00:00
public function __construct() {
2012-02-25 21:22:49 +00:00
parent::__construct();
$this->title = Title::newFromText( 'SomeTitle' );
2012-02-25 21:22:49 +00:00
$this->target = Title::newFromText( 'TestTarget' );
$this->user = User::newFromName( 'UserName' );
2012-02-25 21:22:49 +00:00
$this->user_comment = '<User comment about action>';
$this->context = RequestContext::newExtraneousContext( $this->title );
2012-02-25 21:22:49 +00:00
}
/**
* The testIrcMsgForAction* tests are supposed to cover the hacky
* LogFormatter::getIRCActionText / bug 34508
*
* Third parties bots listen to those messages. They are clever enough
* to fetch the i18n messages from the wiki and then analyze the IRC feed
* to reverse engineer the $1, $2 messages.
* One thing bots can not detect is when MediaWiki change the meaning of
* a message like what happened when we deployed 1.19. $1 became the user
* performing the action which broke basically all bots around.
*
* Should cover the following log actions (which are most commonly used by bots):
* - block/block
* - block/unblock
* - block/reblock
* - delete/delete
* - delete/restore
* - newusers/create
* - newusers/create2
* - newusers/autocreate
* - move/move
* - move/move_redir
* - protect/protect
* - protect/modifyprotect
* - protect/unprotect
* - protect/move_prot
* - upload/upload
* - merge/merge
* - import/upload
* - import/interwiki
*
* As well as the following Auto Edit Summaries:
* - blank
* - replace
* - rollback
* - undo
2012-02-25 21:22:49 +00:00
*/
/**
* @covers LogFormatter::getIRCActionText
*/
public function testIrcMsgForLogTypeBlock() {
$sep = $this->context->msg( 'colon-separator' )->text();
# block/block
$this->assertIRCComment(
$this->context->msg( 'blocklogentry', 'SomeTitle', 'duration', '(flags)' )->plain()
. $sep . $this->user_comment,
'block', 'block',
array(
'5::duration' => 'duration',
'6::flags' => 'flags',
),
$this->user_comment
);
# block/block - legacy
$this->assertIRCComment(
$this->context->msg( 'blocklogentry', 'SomeTitle', 'duration', '(flags)' )->plain()
. $sep . $this->user_comment,
'block', 'block',
array(
'duration',
'flags',
),
$this->user_comment,
'',
true
);
# block/unblock
$this->assertIRCComment(
$this->context->msg( 'unblocklogentry', 'SomeTitle' )->plain() . $sep . $this->user_comment,
'block', 'unblock',
array(),
$this->user_comment
2012-02-25 21:22:49 +00:00
);
# block/reblock
$this->assertIRCComment(
$this->context->msg( 'reblock-logentry', 'SomeTitle', 'duration', '(flags)' )->plain()
. $sep . $this->user_comment,
'block', 'reblock',
array(
'5::duration' => 'duration',
'6::flags' => 'flags',
),
$this->user_comment
);
}
2012-02-25 21:22:49 +00:00
/**
* @covers LogFormatter::getIRCActionText
*/
public function testIrcMsgForLogTypeDelete() {
$sep = $this->context->msg( 'colon-separator' )->text();
# delete/delete
2012-02-25 21:22:49 +00:00
$this->assertIRCComment(
$this->context->msg( 'deletedarticle', 'SomeTitle' )->plain() . $sep . $this->user_comment,
'delete', 'delete',
array(),
$this->user_comment
2012-02-25 21:22:49 +00:00
);
# delete/restore
2012-02-25 21:22:49 +00:00
$this->assertIRCComment(
$this->context->msg( 'undeletedarticle', 'SomeTitle' )->plain() . $sep . $this->user_comment,
'delete', 'restore',
array(),
$this->user_comment
2012-02-25 21:22:49 +00:00
);
}
/**
* @covers LogFormatter::getIRCActionText
*/
public function testIrcMsgForLogTypeNewusers() {
$this->assertIRCComment(
'New user account',
'newusers', 'newusers',
array()
);
$this->assertIRCComment(
'New user account',
'newusers', 'create',
array()
);
$this->assertIRCComment(
'created new account SomeTitle',
'newusers', 'create2',
array()
);
2012-02-25 21:22:49 +00:00
$this->assertIRCComment(
'Account created automatically',
'newusers', 'autocreate',
array()
2012-02-25 21:22:49 +00:00
);
}
2012-02-25 21:22:49 +00:00
/**
* @covers LogFormatter::getIRCActionText
*/
public function testIrcMsgForLogTypeMove() {
$move_params = array(
'4::target' => $this->target->getPrefixedText(),
'5::noredir' => 0,
);
$sep = $this->context->msg( 'colon-separator' )->text();
# move/move
$this->assertIRCComment(
$this->context->msg( '1movedto2', 'SomeTitle', 'TestTarget' )
->plain() . $sep . $this->user_comment,
'move', 'move',
$move_params,
$this->user_comment
);
# move/move_redir
2012-02-25 21:22:49 +00:00
$this->assertIRCComment(
$this->context->msg( '1movedto2_redir', 'SomeTitle', 'TestTarget' )
->plain() . $sep . $this->user_comment,
'move', 'move_redir',
$move_params,
$this->user_comment
2012-02-25 21:22:49 +00:00
);
}
/**
* @covers LogFormatter::getIRCActionText
*/
public function testIrcMsgForLogTypePatrol() {
2012-02-25 21:22:49 +00:00
# patrol/patrol
$this->assertIRCComment(
$this->context->msg( 'patrol-log-line', 'revision 777', '[[SomeTitle]]', '' )->plain(),
'patrol', 'patrol',
array(
'4::curid' => '777',
2012-02-25 21:22:49 +00:00
'5::previd' => '666',
'6::auto' => 0,
2012-02-25 21:22:49 +00:00
)
);
}
/**
* @covers LogFormatter::getIRCActionText
*/
public function testIrcMsgForLogTypeProtect() {
$protectParams = array(
'[edit=sysop] (indefinite) [move=sysop] (indefinite)'
);
$sep = $this->context->msg( 'colon-separator' )->text();
# protect/protect
2012-02-25 21:22:49 +00:00
$this->assertIRCComment(
$this->context->msg( 'protectedarticle', 'SomeTitle ' . $protectParams[0] )
->plain() . $sep . $this->user_comment,
'protect', 'protect',
$protectParams,
$this->user_comment
2012-02-25 21:22:49 +00:00
);
# protect/unprotect
2012-02-25 21:22:49 +00:00
$this->assertIRCComment(
$this->context->msg( 'unprotectedarticle', 'SomeTitle' )->plain() . $sep . $this->user_comment,
'protect', 'unprotect',
array(),
$this->user_comment
2012-02-25 21:22:49 +00:00
);
# protect/modify
2012-02-25 21:22:49 +00:00
$this->assertIRCComment(
$this->context->msg( 'modifiedarticleprotection', 'SomeTitle ' . $protectParams[0] )
->plain() . $sep . $this->user_comment,
'protect', 'modify',
$protectParams,
$this->user_comment
2012-02-25 21:22:49 +00:00
);
# protect/move_prot
$this->assertIRCComment(
$this->context->msg( 'movedarticleprotection', 'SomeTitle', 'OldTitle' )
->plain() . $sep . $this->user_comment,
'protect', 'move_prot',
array( 'OldTitle' ),
$this->user_comment
);
2012-02-25 21:22:49 +00:00
}
/**
* @covers LogFormatter::getIRCActionText
*/
public function testIrcMsgForLogTypeUpload() {
$sep = $this->context->msg( 'colon-separator' )->text();
2012-02-25 21:22:49 +00:00
# upload/upload
$this->assertIRCComment(
$this->context->msg( 'uploadedimage', 'SomeTitle' )->plain() . $sep . $this->user_comment,
'upload', 'upload',
array(),
$this->user_comment
2012-02-25 21:22:49 +00:00
);
# upload/overwrite
$this->assertIRCComment(
$this->context->msg( 'overwroteimage', 'SomeTitle' )->plain() . $sep . $this->user_comment,
'upload', 'overwrite',
array(),
$this->user_comment
2012-02-25 21:22:49 +00:00
);
}
/**
* @covers LogFormatter::getIRCActionText
*/
public function testIrcMsgForLogTypeMerge() {
$sep = $this->context->msg( 'colon-separator' )->text();
# merge/merge
$this->assertIRCComment(
$this->context->msg( 'pagemerge-logentry', 'SomeTitle', 'Dest', 'timestamp' )->plain()
. $sep . $this->user_comment,
'merge', 'merge',
array(
'4::dest' => 'Dest',
'5::mergepoint' => 'timestamp',
),
$this->user_comment
);
}
/**
* @covers LogFormatter::getIRCActionText
*/
public function testIrcMsgForLogTypeImport() {
$sep = $this->context->msg( 'colon-separator' )->text();
# import/upload
$this->assertIRCComment(
$this->context->msg( 'import-logentry-upload', 'SomeTitle' )->plain() . $sep . $this->user_comment,
'import', 'upload',
array(),
$this->user_comment
);
# import/interwiki
$this->assertIRCComment(
$this->context->msg( 'import-logentry-interwiki', 'SomeTitle' )->plain() . $sep . $this->user_comment,
'import', 'interwiki',
array(),
$this->user_comment
);
}
2012-02-25 21:22:49 +00:00
/**
* @todo Emulate these edits somehow and extract
* raw edit summary from RecentChange object
* --
Clean and repair many phpunit tests (+ fix implied configuration) This commit depends on the introduction of MediaWikiTestCase::setMwGlobals in change Iccf6ea81f4. Various tests already set their globals, but forgot to restore them afterwards, or forgot to call the parent setUp, tearDown... Either way they won't have to anymore with setMwGlobals. Consistent use of function characteristics: * protected function setUp * protected function tearDown * public static function (provide..) (Matching the function signature with PHPUnit/Framework/TestCase.php) Replaces: * public function (setUp|tearDown)\( * protected function $1( * \tfunction (setUp|tearDown)\( * \tprotected function $1( * \tfunction (data|provide)\( * \tpublic static function $1\( Also renamed a few "data#", "provider#" and "provides#" functions to "provide#" for consistency. This also removes confusion where the /media tests had a few private methods called dataFile(), which were sometimes expected to be data providers. Fixes: TimestampTest often failed due to a previous test setting a different language (it tests "1 hour ago" so need to make sure it is set to English). MWNamespaceTest became a lot cleaner now that it executes with a known context. Though the now-redundant code that was removed didn't work anyway because wgContentNamespaces isn't keyed by namespace id, it had them was values... FileBackendTest: * Fixed: "PHP Fatal: Using $this when not in object context" HttpTest * Added comment about: "PHP Fatal: Call to protected MWHttpRequest::__construct()" (too much unrelated code to fix in this commit) ExternalStoreTest * Add an assertTrue as well, without it the test is useless because regardless of whether wgExternalStores is true or false it only uses it if it is an array. Change-Id: I9d2b148e57bada64afeb7d5a99bec0e58f8e1561
2012-10-08 10:56:20 +00:00
*/
/*
public function testIrcMsgForBlankingAES() {
// $this->context->msg( 'autosumm-blank', .. );
}
public function testIrcMsgForReplaceAES() {
// $this->context->msg( 'autosumm-replace', .. );
2012-02-25 21:22:49 +00:00
}
public function testIrcMsgForRollbackAES() {
// $this->context->msg( 'revertpage', .. );
}
public function testIrcMsgForUndoAES() {
// $this->context->msg( 'undo-summary', .. );
}
*/
2012-02-25 21:22:49 +00:00
/**
* @param string $expected Expected IRC text without colors codes
* @param string $type Log type (move, delete, suppress, patrol ...)
* @param string $action A log type action
* @param array $params
* @param string $comment (optional) A comment for the log action
* @param string $msg (optional) A message for PHPUnit :-)
2012-02-25 21:22:49 +00:00
*/
protected function assertIRCComment( $expected, $type, $action, $params,
$comment = null, $msg = '', $legacy = false
) {
2012-02-25 21:22:49 +00:00
$logEntry = new ManualLogEntry( $type, $action );
$logEntry->setPerformer( $this->user );
$logEntry->setTarget( $this->title );
if ( $comment !== null ) {
$logEntry->setComment( $comment );
}
2012-02-25 21:22:49 +00:00
$logEntry->setParameters( $params );
$logEntry->setLegacy( $legacy );
2012-02-25 21:22:49 +00:00
$formatter = LogFormatter::newFromEntry( $logEntry );
$formatter->setContext( $this->context );
2012-02-25 21:22:49 +00:00
// Apply the same transformation as done in IRCColourfulRCFeedFormatter::getLine for rc_comment
$ircRcComment = IRCColourfulRCFeedFormatter::cleanupForIRC( $formatter->getIRCActionComment() );
$this->assertEquals(
$expected,
$ircRcComment,
2012-02-25 21:22:49 +00:00
$msg
);
}
}