MediaWiki  REL1_22
RecentChangeTest.php
Go to the documentation of this file.
00001 <?php
00005 class RecentChangeTest extends MediaWikiTestCase {
00006     protected $title;
00007     protected $target;
00008     protected $user;
00009     protected $user_comment;
00010     protected $context;
00011 
00012     public function __construct() {
00013         parent::__construct();
00014 
00015         $this->title = Title::newFromText( 'SomeTitle' );
00016         $this->target = Title::newFromText( 'TestTarget' );
00017         $this->user = User::newFromName( 'UserName' );
00018 
00019         $this->user_comment = '<User comment about action>';
00020         $this->context = RequestContext::newExtraneousContext( $this->title );
00021     }
00022 
00059     public function testIrcMsgForLogTypeBlock() {
00060         $sep = $this->context->msg( 'colon-separator' )->text();
00061 
00062         # block/block
00063         $this->assertIRCComment(
00064             $this->context->msg( 'blocklogentry', 'SomeTitle' )->plain() . $sep . $this->user_comment,
00065             'block', 'block',
00066             array(),
00067             $this->user_comment
00068         );
00069         # block/unblock
00070         $this->assertIRCComment(
00071             $this->context->msg( 'unblocklogentry', 'SomeTitle' )->plain() . $sep . $this->user_comment,
00072             'block', 'unblock',
00073             array(),
00074             $this->user_comment
00075         );
00076     }
00077 
00081     public function testIrcMsgForLogTypeDelete() {
00082         $sep = $this->context->msg( 'colon-separator' )->text();
00083 
00084         # delete/delete
00085         $this->assertIRCComment(
00086             $this->context->msg( 'deletedarticle', 'SomeTitle' )->plain() . $sep . $this->user_comment,
00087             'delete', 'delete',
00088             array(),
00089             $this->user_comment
00090         );
00091 
00092         # delete/restore
00093         $this->assertIRCComment(
00094             $this->context->msg( 'undeletedarticle', 'SomeTitle' )->plain() . $sep . $this->user_comment,
00095             'delete', 'restore',
00096             array(),
00097             $this->user_comment
00098         );
00099     }
00100 
00104     public function testIrcMsgForLogTypeNewusers() {
00105         $this->assertIRCComment(
00106             'New user account',
00107             'newusers', 'newusers',
00108             array()
00109         );
00110         $this->assertIRCComment(
00111             'New user account',
00112             'newusers', 'create',
00113             array()
00114         );
00115         $this->assertIRCComment(
00116             'created new account SomeTitle',
00117             'newusers', 'create2',
00118             array()
00119         );
00120         $this->assertIRCComment(
00121             'Account created automatically',
00122             'newusers', 'autocreate',
00123             array()
00124         );
00125     }
00126 
00130     public function testIrcMsgForLogTypeMove() {
00131         $move_params = array(
00132             '4::target' => $this->target->getPrefixedText(),
00133             '5::noredir' => 0,
00134         );
00135         $sep = $this->context->msg( 'colon-separator' )->text();
00136 
00137         # move/move
00138         $this->assertIRCComment(
00139             $this->context->msg( '1movedto2', 'SomeTitle', 'TestTarget' )->plain() . $sep . $this->user_comment,
00140             'move', 'move',
00141             $move_params,
00142             $this->user_comment
00143         );
00144 
00145         # move/move_redir
00146         $this->assertIRCComment(
00147             $this->context->msg( '1movedto2_redir', 'SomeTitle', 'TestTarget' )->plain() . $sep . $this->user_comment,
00148             'move', 'move_redir',
00149             $move_params,
00150             $this->user_comment
00151         );
00152     }
00153 
00157     public function testIrcMsgForLogTypePatrol() {
00158         # patrol/patrol
00159         $this->assertIRCComment(
00160             $this->context->msg( 'patrol-log-line', 'revision 777', '[[SomeTitle]]', '' )->plain(),
00161             'patrol', 'patrol',
00162             array(
00163                 '4::curid' => '777',
00164                 '5::previd' => '666',
00165                 '6::auto' => 0,
00166             )
00167         );
00168     }
00169 
00173     public function testIrcMsgForLogTypeProtect() {
00174         $protectParams = array(
00175             '[edit=sysop] (indefinite) ‎[move=sysop] (indefinite)'
00176         );
00177         $sep = $this->context->msg( 'colon-separator' )->text();
00178 
00179         # protect/protect
00180         $this->assertIRCComment(
00181             $this->context->msg( 'protectedarticle', 'SomeTitle ' . $protectParams[0] )->plain() . $sep . $this->user_comment,
00182             'protect', 'protect',
00183             $protectParams,
00184             $this->user_comment
00185         );
00186 
00187         # protect/unprotect
00188         $this->assertIRCComment(
00189             $this->context->msg( 'unprotectedarticle', 'SomeTitle' )->plain() . $sep . $this->user_comment,
00190             'protect', 'unprotect',
00191             array(),
00192             $this->user_comment
00193         );
00194 
00195         # protect/modify
00196         $this->assertIRCComment(
00197             $this->context->msg( 'modifiedarticleprotection', 'SomeTitle ' . $protectParams[0] )->plain() . $sep . $this->user_comment,
00198             'protect', 'modify',
00199             $protectParams,
00200             $this->user_comment
00201         );
00202     }
00203 
00207     public function testIrcMsgForLogTypeUpload() {
00208         $sep = $this->context->msg( 'colon-separator' )->text();
00209 
00210         # upload/upload
00211         $this->assertIRCComment(
00212             $this->context->msg( 'uploadedimage', 'SomeTitle' )->plain() . $sep . $this->user_comment,
00213             'upload', 'upload',
00214             array(),
00215             $this->user_comment
00216         );
00217 
00218         # upload/overwrite
00219         $this->assertIRCComment(
00220             $this->context->msg( 'overwroteimage', 'SomeTitle' )->plain() . $sep . $this->user_comment,
00221             'upload', 'overwrite',
00222             array(),
00223             $this->user_comment
00224         );
00225     }
00226 
00232     /*
00233     public function testIrcMsgForBlankingAES() {
00234         // $this->context->msg( 'autosumm-blank', .. );
00235     }
00236 
00237     public function testIrcMsgForReplaceAES() {
00238         // $this->context->msg( 'autosumm-replace', .. );
00239     }
00240 
00241     public function testIrcMsgForRollbackAES() {
00242         // $this->context->msg( 'revertpage', .. );
00243     }
00244 
00245     public function testIrcMsgForUndoAES() {
00246         // $this->context->msg( 'undo-summary', .. );
00247     }
00248     */
00249 
00258     protected function assertIRCComment( $expected, $type, $action, $params, $comment = null, $msg = '' ) {
00259 
00260         $logEntry = new ManualLogEntry( $type, $action );
00261         $logEntry->setPerformer( $this->user );
00262         $logEntry->setTarget( $this->title );
00263         if ( $comment !== null ) {
00264             $logEntry->setComment( $comment );
00265         }
00266         $logEntry->setParameters( $params );
00267 
00268         $formatter = LogFormatter::newFromEntry( $logEntry );
00269         $formatter->setContext( $this->context );
00270 
00271         // Apply the same transformation as done in IRCColourfulRCFeedFormatter::getLine for rc_comment
00272         $ircRcComment = IRCColourfulRCFeedFormatter::cleanupForIRC( $formatter->getIRCActionComment() );
00273 
00274         $this->assertEquals(
00275             $expected,
00276             $ircRcComment,
00277             $msg
00278         );
00279     }
00280 }