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