MediaWiki
REL1_20
|
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 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 function testIrcMsgForLogTypeBlock() { 00060 # block/block 00061 $this->assertIRCComment( 00062 $this->context->msg( 'blocklogentry', 'SomeTitle' )->plain() . ': ' . $this->user_comment, 00063 'block', 'block', 00064 array(), 00065 $this->user_comment 00066 ); 00067 # block/unblock 00068 $this->assertIRCComment( 00069 $this->context->msg( 'unblocklogentry', 'SomeTitle' )->plain() . ': ' . $this->user_comment, 00070 'block', 'unblock', 00071 array(), 00072 $this->user_comment 00073 ); 00074 } 00075 00079 function testIrcMsgForLogTypeDelete() { 00080 # delete/delete 00081 $this->assertIRCComment( 00082 $this->context->msg( 'deletedarticle', 'SomeTitle' )->plain() . ': ' . $this->user_comment, 00083 'delete', 'delete', 00084 array(), 00085 $this->user_comment 00086 ); 00087 00088 # delete/restore 00089 $this->assertIRCComment( 00090 $this->context->msg( 'undeletedarticle', 'SomeTitle' )->plain() . ': ' . $this->user_comment, 00091 'delete', 'restore', 00092 array(), 00093 $this->user_comment 00094 ); 00095 } 00096 00100 function testIrcMsgForLogTypeNewusers() { 00101 $this->assertIRCComment( 00102 'New user account', 00103 'newusers', 'newusers', 00104 array() 00105 ); 00106 $this->assertIRCComment( 00107 'New user account', 00108 'newusers', 'create', 00109 array() 00110 ); 00111 $this->assertIRCComment( 00112 'created new account SomeTitle', 00113 'newusers', 'create2', 00114 array() 00115 ); 00116 $this->assertIRCComment( 00117 'Account created automatically', 00118 'newusers', 'autocreate', 00119 array() 00120 ); 00121 } 00122 00126 function testIrcMsgForLogTypeMove() { 00127 $move_params = array( 00128 '4::target' => $this->target->getPrefixedText(), 00129 '5::noredir' => 0, 00130 ); 00131 00132 # move/move 00133 $this->assertIRCComment( 00134 $this->context->msg( '1movedto2', 'SomeTitle', 'TestTarget' )->plain() . ': ' . $this->user_comment, 00135 'move', 'move', 00136 $move_params, 00137 $this->user_comment 00138 ); 00139 00140 # move/move_redir 00141 $this->assertIRCComment( 00142 $this->context->msg( '1movedto2_redir', 'SomeTitle', 'TestTarget' )->plain() . ': ' . $this->user_comment, 00143 'move', 'move_redir', 00144 $move_params, 00145 $this->user_comment 00146 ); 00147 } 00148 00152 function testIrcMsgForLogTypePatrol() { 00153 # patrol/patrol 00154 $this->assertIRCComment( 00155 $this->context->msg( 'patrol-log-line', 'revision 777', '[[SomeTitle]]', '' )->plain(), 00156 'patrol', 'patrol', 00157 array( 00158 '4::curid' => '777', 00159 '5::previd' => '666', 00160 '6::auto' => 0, 00161 ) 00162 ); 00163 } 00164 00168 function testIrcMsgForLogTypeProtect() { 00169 $protectParams = array( 00170 '[edit=sysop] (indefinite) [move=sysop] (indefinite)' 00171 ); 00172 00173 # protect/protect 00174 $this->assertIRCComment( 00175 $this->context->msg( 'protectedarticle', 'SomeTitle ' . $protectParams[0] )->plain() . ': ' . $this->user_comment, 00176 'protect', 'protect', 00177 $protectParams, 00178 $this->user_comment 00179 ); 00180 00181 # protect/unprotect 00182 $this->assertIRCComment( 00183 $this->context->msg( 'unprotectedarticle', 'SomeTitle' )->plain() . ': ' . $this->user_comment, 00184 'protect', 'unprotect', 00185 array(), 00186 $this->user_comment 00187 ); 00188 00189 # protect/modify 00190 $this->assertIRCComment( 00191 $this->context->msg( 'modifiedarticleprotection', 'SomeTitle ' . $protectParams[0] )->plain() . ': ' . $this->user_comment, 00192 'protect', 'modify', 00193 $protectParams, 00194 $this->user_comment 00195 ); 00196 } 00197 00201 function testIrcMsgForLogTypeUpload() { 00202 # upload/upload 00203 $this->assertIRCComment( 00204 $this->context->msg( 'uploadedimage', 'SomeTitle' )->plain() . ': ' . $this->user_comment, 00205 'upload', 'upload', 00206 array(), 00207 $this->user_comment 00208 ); 00209 00210 # upload/overwrite 00211 $this->assertIRCComment( 00212 $this->context->msg( 'overwroteimage', 'SomeTitle' )->plain() . ': ' . $this->user_comment, 00213 'upload', 'overwrite', 00214 array(), 00215 $this->user_comment 00216 ); 00217 } 00218 00250 function assertIRCComment( $expected, $type, $action, $params, $comment = null, $msg = '' ) { 00251 00252 $logEntry = new ManualLogEntry( $type, $action ); 00253 $logEntry->setPerformer( $this->user ); 00254 $logEntry->setTarget( $this->title ); 00255 if ( $comment !== null ) { 00256 $logEntry->setComment( $comment ); 00257 } 00258 $logEntry->setParameters( $params ); 00259 00260 $formatter = LogFormatter::newFromEntry( $logEntry ); 00261 $formatter->setContext( $this->context ); 00262 00263 // Apply the same transformation as done in RecentChange::getIRCLine for rc_comment 00264 $ircRcComment = RecentChange::cleanupForIRC( $formatter->getIRCActionComment() ); 00265 00266 $this->assertEquals( 00267 $expected, 00268 $ircRcComment, 00269 $msg 00270 ); 00271 } 00272 00273 }