Allow to set stub read buffer size for TextPassDumper
[lhc/web/wiklou.git] / tests / phpunit / includes / changes / RecentChangeTest.php
1 <?php
2
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;
12
13 public function __construct() {
14 parent::__construct();
15
16 $this->title = Title::newFromText( 'SomeTitle' );
17 $this->target = Title::newFromText( 'TestTarget' );
18 $this->user = User::newFromName( 'UserName' );
19
20 $this->user_comment = '<User comment about action>';
21 $this->context = RequestContext::newExtraneousContext( $this->title );
22 }
23
24 /**
25 * The testIrcMsgForAction* tests are supposed to cover the hacky
26 * LogFormatter::getIRCActionText / bug 34508
27 *
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.
34 *
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
50 *
51 * As well as the following Auto Edit Summaries:
52 * - blank
53 * - replace
54 * - rollback
55 * - undo
56 */
57
58 /**
59 * @covers LogFormatter::getIRCActionText
60 */
61 public function testIrcMsgForLogTypeBlock() {
62 $sep = $this->context->msg( 'colon-separator' )->text();
63
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
70 );
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
77 );
78 }
79
80 /**
81 * @covers LogFormatter::getIRCActionText
82 */
83 public function testIrcMsgForLogTypeDelete() {
84 $sep = $this->context->msg( 'colon-separator' )->text();
85
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
92 );
93
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
100 );
101 }
102
103 /**
104 * @covers LogFormatter::getIRCActionText
105 */
106 public function testIrcMsgForLogTypeNewusers() {
107 $this->assertIRCComment(
108 'New user account',
109 'newusers', 'newusers',
110 array()
111 );
112 $this->assertIRCComment(
113 'New user account',
114 'newusers', 'create',
115 array()
116 );
117 $this->assertIRCComment(
118 'created new account SomeTitle',
119 'newusers', 'create2',
120 array()
121 );
122 $this->assertIRCComment(
123 'Account created automatically',
124 'newusers', 'autocreate',
125 array()
126 );
127 }
128
129 /**
130 * @covers LogFormatter::getIRCActionText
131 */
132 public function testIrcMsgForLogTypeMove() {
133 $move_params = array(
134 '4::target' => $this->target->getPrefixedText(),
135 '5::noredir' => 0,
136 );
137 $sep = $this->context->msg( 'colon-separator' )->text();
138
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
146 );
147
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
155 );
156 }
157
158 /**
159 * @covers LogFormatter::getIRCActionText
160 */
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,
170 )
171 );
172 }
173
174 /**
175 * @covers LogFormatter::getIRCActionText
176 */
177 public function testIrcMsgForLogTypeProtect() {
178 $protectParams = array(
179 '[edit=sysop] (indefinite) ‎[move=sysop] (indefinite)'
180 );
181 $sep = $this->context->msg( 'colon-separator' )->text();
182
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
190 );
191
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
198 );
199
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
207 );
208 }
209
210 /**
211 * @covers LogFormatter::getIRCActionText
212 */
213 public function testIrcMsgForLogTypeUpload() {
214 $sep = $this->context->msg( 'colon-separator' )->text();
215
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
222 );
223
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
230 );
231 }
232
233 /**
234 * @covers LogFormatter::getIRCActionText
235 */
236 public function testIrcMsgForLogTypeMerge() {
237 $sep = $this->context->msg( 'colon-separator' )->text();
238
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',
247 ),
248 $this->user_comment
249 );
250 }
251
252 /**
253 * @todo Emulate these edits somehow and extract
254 * raw edit summary from RecentChange object
255 * --
256 */
257 /*
258 public function testIrcMsgForBlankingAES() {
259 // $this->context->msg( 'autosumm-blank', .. );
260 }
261
262 public function testIrcMsgForReplaceAES() {
263 // $this->context->msg( 'autosumm-replace', .. );
264 }
265
266 public function testIrcMsgForRollbackAES() {
267 // $this->context->msg( 'revertpage', .. );
268 }
269
270 public function testIrcMsgForUndoAES() {
271 // $this->context->msg( 'undo-summary', .. );
272 }
273 */
274
275 /**
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 :-)
282 */
283 protected function assertIRCComment( $expected, $type, $action, $params,
284 $comment = null, $msg = ''
285 ) {
286 $logEntry = new ManualLogEntry( $type, $action );
287 $logEntry->setPerformer( $this->user );
288 $logEntry->setTarget( $this->title );
289 if ( $comment !== null ) {
290 $logEntry->setComment( $comment );
291 }
292 $logEntry->setParameters( $params );
293
294 $formatter = LogFormatter::newFromEntry( $logEntry );
295 $formatter->setContext( $this->context );
296
297 // Apply the same transformation as done in IRCColourfulRCFeedFormatter::getLine for rc_comment
298 $ircRcComment = IRCColourfulRCFeedFormatter::cleanupForIRC( $formatter->getIRCActionComment() );
299
300 $this->assertEquals(
301 $expected,
302 $ircRcComment,
303 $msg
304 );
305 }
306 }