Implement extension registration from an extension.json file
[mediawiki.git] / tests / phpunit / includes / changes / RecentChangeTest.php
blob7c2ba1a9958fcd7f06ed2263f1101af31c5865cd
1 <?php
3 /**
4 * @group Database
5 */
6 class RecentChangeTest extends MediaWikiTestCase {
7 protected $title;
8 protected $target;
9 protected $user;
10 protected $user_comment;
11 protected $context;
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 );
24 /**
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):
36 * - block/block
37 * - block/unblock
38 * - delete/delete
39 * - delete/restore
40 * - newusers/create
41 * - newusers/create2
42 * - newusers/autocreate
43 * - move/move
44 * - move/move_redir
45 * - protect/protect
46 * - protect/modifyprotect
47 * - protect/unprotect
48 * - upload/upload
49 * - merge/merge
51 * As well as the following Auto Edit Summaries:
52 * - blank
53 * - replace
54 * - rollback
55 * - undo
58 /**
59 * @covers LogFormatter::getIRCActionText
61 public function testIrcMsgForLogTypeBlock() {
62 $sep = $this->context->msg( 'colon-separator' )->text();
64 # block/block
65 $this->assertIRCComment(
66 $this->context->msg( 'blocklogentry', 'SomeTitle' )->plain() . $sep . $this->user_comment,
67 'block', 'block',
68 array(),
69 $this->user_comment
71 # block/unblock
72 $this->assertIRCComment(
73 $this->context->msg( 'unblocklogentry', 'SomeTitle' )->plain() . $sep . $this->user_comment,
74 'block', 'unblock',
75 array(),
76 $this->user_comment
80 /**
81 * @covers LogFormatter::getIRCActionText
83 public function testIrcMsgForLogTypeDelete() {
84 $sep = $this->context->msg( 'colon-separator' )->text();
86 # delete/delete
87 $this->assertIRCComment(
88 $this->context->msg( 'deletedarticle', 'SomeTitle' )->plain() . $sep . $this->user_comment,
89 'delete', 'delete',
90 array(),
91 $this->user_comment
94 # delete/restore
95 $this->assertIRCComment(
96 $this->context->msg( 'undeletedarticle', 'SomeTitle' )->plain() . $sep . $this->user_comment,
97 'delete', 'restore',
98 array(),
99 $this->user_comment
104 * @covers LogFormatter::getIRCActionText
106 public function testIrcMsgForLogTypeNewusers() {
107 $this->assertIRCComment(
108 'New user account',
109 'newusers', 'newusers',
110 array()
112 $this->assertIRCComment(
113 'New user account',
114 'newusers', 'create',
115 array()
117 $this->assertIRCComment(
118 'created new account SomeTitle',
119 'newusers', 'create2',
120 array()
122 $this->assertIRCComment(
123 'Account created automatically',
124 'newusers', 'autocreate',
125 array()
130 * @covers LogFormatter::getIRCActionText
132 public function testIrcMsgForLogTypeMove() {
133 $move_params = array(
134 '4::target' => $this->target->getPrefixedText(),
135 '5::noredir' => 0,
137 $sep = $this->context->msg( 'colon-separator' )->text();
139 # move/move
140 $this->assertIRCComment(
141 $this->context->msg( '1movedto2', 'SomeTitle', 'TestTarget' )
142 ->plain() . $sep . $this->user_comment,
143 'move', 'move',
144 $move_params,
145 $this->user_comment
148 # move/move_redir
149 $this->assertIRCComment(
150 $this->context->msg( '1movedto2_redir', 'SomeTitle', 'TestTarget' )
151 ->plain() . $sep . $this->user_comment,
152 'move', 'move_redir',
153 $move_params,
154 $this->user_comment
159 * @covers LogFormatter::getIRCActionText
161 public function testIrcMsgForLogTypePatrol() {
162 # patrol/patrol
163 $this->assertIRCComment(
164 $this->context->msg( 'patrol-log-line', 'revision 777', '[[SomeTitle]]', '' )->plain(),
165 'patrol', 'patrol',
166 array(
167 '4::curid' => '777',
168 '5::previd' => '666',
169 '6::auto' => 0,
175 * @covers LogFormatter::getIRCActionText
177 public function testIrcMsgForLogTypeProtect() {
178 $protectParams = array(
179 '[edit=sysop] (indefinite) ‎[move=sysop] (indefinite)'
181 $sep = $this->context->msg( 'colon-separator' )->text();
183 # protect/protect
184 $this->assertIRCComment(
185 $this->context->msg( 'protectedarticle', 'SomeTitle ' . $protectParams[0] )
186 ->plain() . $sep . $this->user_comment,
187 'protect', 'protect',
188 $protectParams,
189 $this->user_comment
192 # protect/unprotect
193 $this->assertIRCComment(
194 $this->context->msg( 'unprotectedarticle', 'SomeTitle' )->plain() . $sep . $this->user_comment,
195 'protect', 'unprotect',
196 array(),
197 $this->user_comment
200 # protect/modify
201 $this->assertIRCComment(
202 $this->context->msg( 'modifiedarticleprotection', 'SomeTitle ' . $protectParams[0] )
203 ->plain() . $sep . $this->user_comment,
204 'protect', 'modify',
205 $protectParams,
206 $this->user_comment
211 * @covers LogFormatter::getIRCActionText
213 public function testIrcMsgForLogTypeUpload() {
214 $sep = $this->context->msg( 'colon-separator' )->text();
216 # upload/upload
217 $this->assertIRCComment(
218 $this->context->msg( 'uploadedimage', 'SomeTitle' )->plain() . $sep . $this->user_comment,
219 'upload', 'upload',
220 array(),
221 $this->user_comment
224 # upload/overwrite
225 $this->assertIRCComment(
226 $this->context->msg( 'overwroteimage', 'SomeTitle' )->plain() . $sep . $this->user_comment,
227 'upload', 'overwrite',
228 array(),
229 $this->user_comment
234 * @covers LogFormatter::getIRCActionText
236 public function testIrcMsgForLogTypeMerge() {
237 $sep = $this->context->msg( 'colon-separator' )->text();
239 # merge/merge
240 $this->assertIRCComment(
241 $this->context->msg( 'pagemerge-logentry', 'SomeTitle', 'Dest', 'timestamp' )->plain()
242 . $sep . $this->user_comment,
243 'merge', 'merge',
244 array(
245 '4::dest' => 'Dest',
246 '5::mergepoint' => 'timestamp',
248 $this->user_comment
253 * @todo Emulate these edits somehow and extract
254 * raw edit summary from RecentChange object
255 * --
258 public function testIrcMsgForBlankingAES() {
259 // $this->context->msg( 'autosumm-blank', .. );
262 public function testIrcMsgForReplaceAES() {
263 // $this->context->msg( 'autosumm-replace', .. );
266 public function testIrcMsgForRollbackAES() {
267 // $this->context->msg( 'revertpage', .. );
270 public function testIrcMsgForUndoAES() {
271 // $this->context->msg( 'undo-summary', .. );
276 * @param string $expected Expected IRC text without colors codes
277 * @param string $type Log type (move, delete, suppress, patrol ...)
278 * @param string $action A log type action
279 * @param array $params
280 * @param string $comment (optional) A comment for the log action
281 * @param string $msg (optional) A message for PHPUnit :-)
283 protected function assertIRCComment( $expected, $type, $action, $params,
284 $comment = null, $msg = ''
286 $logEntry = new ManualLogEntry( $type, $action );
287 $logEntry->setPerformer( $this->user );
288 $logEntry->setTarget( $this->title );
289 if ( $comment !== null ) {
290 $logEntry->setComment( $comment );
292 $logEntry->setParameters( $params );
294 $formatter = LogFormatter::newFromEntry( $logEntry );
295 $formatter->setContext( $this->context );
297 // Apply the same transformation as done in IRCColourfulRCFeedFormatter::getLine for rc_comment
298 $ircRcComment = IRCColourfulRCFeedFormatter::cleanupForIRC( $formatter->getIRCActionComment() );
300 $this->assertEquals(
301 $expected,
302 $ircRcComment,
303 $msg