test: coverage recording now needs to be explicit
[mediawiki.git] / tests / phpunit / includes / RecentChangeTest.php
blob8e476b31b0786d80321692e645b915ff9080dea7
1 <?php
2 /**
3 * @group Database
4 */
5 class RecentChangeTest extends MediaWikiTestCase {
6 protected $title;
7 protected $target;
8 protected $user;
9 protected $user_comment;
10 protected $context;
12 function __construct() {
13 parent::__construct();
15 $this->title = Title::newFromText( 'SomeTitle' );
16 $this->target = Title::newFromText( 'TestTarget' );
17 $this->user = User::newFromName( 'UserName' );
19 $this->user_comment = '<User comment about action>';
20 $this->context = RequestContext::newExtraneousContext( $this->title );
23 /**
24 * The testIrcMsgForAction* tests are supposed to cover the hacky
25 * LogFormatter::getIRCActionText / bug 34508
27 * Third parties bots listen to those messages. They are clever enough
28 * to fetch the i18n messages from the wiki and then analyze the IRC feed
29 * to reverse engineer the $1, $2 messages.
30 * One thing bots can not detect is when MediaWiki change the meaning of
31 * a message like what happened when we deployed 1.19. $1 became the user
32 * performing the action which broke basically all bots around.
34 * Should cover the following log actions (which are most commonly used by bots):
35 * - block/block
36 * - block/unblock
37 * - delete/delete
38 * - delete/restore
39 * - newusers/create
40 * - newusers/create2
41 * - newusers/autocreate
42 * - move/move
43 * - move/move_redir
44 * - protect/protect
45 * - protect/modifyprotect
46 * - protect/unprotect
47 * - upload/upload
49 * As well as the following Auto Edit Summaries:
50 * - blank
51 * - replace
52 * - rollback
53 * - undo
56 /**
57 * @covers LogFormatter::getIRCActionText
59 function testIrcMsgForLogTypeBlock() {
60 $sep = $this->context->msg( 'colon-separator' )->text();
62 # block/block
63 $this->assertIRCComment(
64 $this->context->msg( 'blocklogentry', 'SomeTitle' )->plain() . $sep . $this->user_comment,
65 'block', 'block',
66 array(),
67 $this->user_comment
69 # block/unblock
70 $this->assertIRCComment(
71 $this->context->msg( 'unblocklogentry', 'SomeTitle' )->plain() . $sep . $this->user_comment,
72 'block', 'unblock',
73 array(),
74 $this->user_comment
78 /**
79 * @covers LogFormatter::getIRCActionText
81 function testIrcMsgForLogTypeDelete() {
82 $sep = $this->context->msg( 'colon-separator' )->text();
84 # delete/delete
85 $this->assertIRCComment(
86 $this->context->msg( 'deletedarticle', 'SomeTitle' )->plain() . $sep . $this->user_comment,
87 'delete', 'delete',
88 array(),
89 $this->user_comment
92 # delete/restore
93 $this->assertIRCComment(
94 $this->context->msg( 'undeletedarticle', 'SomeTitle' )->plain() . $sep . $this->user_comment,
95 'delete', 'restore',
96 array(),
97 $this->user_comment
102 * @covers LogFormatter::getIRCActionText
104 function testIrcMsgForLogTypeNewusers() {
105 $this->assertIRCComment(
106 'New user account',
107 'newusers', 'newusers',
108 array()
110 $this->assertIRCComment(
111 'New user account',
112 'newusers', 'create',
113 array()
115 $this->assertIRCComment(
116 'created new account SomeTitle',
117 'newusers', 'create2',
118 array()
120 $this->assertIRCComment(
121 'Account created automatically',
122 'newusers', 'autocreate',
123 array()
128 * @covers LogFormatter::getIRCActionText
130 function testIrcMsgForLogTypeMove() {
131 $move_params = array(
132 '4::target' => $this->target->getPrefixedText(),
133 '5::noredir' => 0,
135 $sep = $this->context->msg( 'colon-separator' )->text();
137 # move/move
138 $this->assertIRCComment(
139 $this->context->msg( '1movedto2', 'SomeTitle', 'TestTarget' )->plain() . $sep . $this->user_comment,
140 'move', 'move',
141 $move_params,
142 $this->user_comment
145 # move/move_redir
146 $this->assertIRCComment(
147 $this->context->msg( '1movedto2_redir', 'SomeTitle', 'TestTarget' )->plain() . $sep . $this->user_comment,
148 'move', 'move_redir',
149 $move_params,
150 $this->user_comment
155 * @covers LogFormatter::getIRCActionText
157 function testIrcMsgForLogTypePatrol() {
158 # patrol/patrol
159 $this->assertIRCComment(
160 $this->context->msg( 'patrol-log-line', 'revision 777', '[[SomeTitle]]', '' )->plain(),
161 'patrol', 'patrol',
162 array(
163 '4::curid' => '777',
164 '5::previd' => '666',
165 '6::auto' => 0,
171 * @covers LogFormatter::getIRCActionText
173 function testIrcMsgForLogTypeProtect() {
174 $protectParams = array(
175 '[edit=sysop] (indefinite) ‎[move=sysop] (indefinite)'
177 $sep = $this->context->msg( 'colon-separator' )->text();
179 # protect/protect
180 $this->assertIRCComment(
181 $this->context->msg( 'protectedarticle', 'SomeTitle ' . $protectParams[0] )->plain() . $sep . $this->user_comment,
182 'protect', 'protect',
183 $protectParams,
184 $this->user_comment
187 # protect/unprotect
188 $this->assertIRCComment(
189 $this->context->msg( 'unprotectedarticle', 'SomeTitle' )->plain() . $sep . $this->user_comment,
190 'protect', 'unprotect',
191 array(),
192 $this->user_comment
195 # protect/modify
196 $this->assertIRCComment(
197 $this->context->msg( 'modifiedarticleprotection', 'SomeTitle ' . $protectParams[0] )->plain() . $sep . $this->user_comment,
198 'protect', 'modify',
199 $protectParams,
200 $this->user_comment
205 * @covers LogFormatter::getIRCActionText
207 function testIrcMsgForLogTypeUpload() {
208 $sep = $this->context->msg( 'colon-separator' )->text();
210 # upload/upload
211 $this->assertIRCComment(
212 $this->context->msg( 'uploadedimage', 'SomeTitle' )->plain() . $sep . $this->user_comment,
213 'upload', 'upload',
214 array(),
215 $this->user_comment
218 # upload/overwrite
219 $this->assertIRCComment(
220 $this->context->msg( 'overwroteimage', 'SomeTitle' )->plain() . $sep . $this->user_comment,
221 'upload', 'overwrite',
222 array(),
223 $this->user_comment
228 * @todo Emulate these edits somehow and extract
229 * raw edit summary from RecentChange object
230 * --
233 function testIrcMsgForBlankingAES() {
234 // $this->context->msg( 'autosumm-blank', .. );
237 function testIrcMsgForReplaceAES() {
238 // $this->context->msg( 'autosumm-replace', .. );
241 function testIrcMsgForRollbackAES() {
242 // $this->context->msg( 'revertpage', .. );
245 function testIrcMsgForUndoAES() {
246 // $this->context->msg( 'undo-summary', .. );
251 * @param $expected String Expected IRC text without colors codes
252 * @param $type String Log type (move, delete, suppress, patrol ...)
253 * @param $action String A log type action
254 * @param $comment String (optional) A comment for the log action
255 * @param $msg String (optional) A message for PHPUnit :-)
257 function assertIRCComment( $expected, $type, $action, $params, $comment = null, $msg = '' ) {
259 $logEntry = new ManualLogEntry( $type, $action );
260 $logEntry->setPerformer( $this->user );
261 $logEntry->setTarget( $this->title );
262 if ( $comment !== null ) {
263 $logEntry->setComment( $comment );
265 $logEntry->setParameters( $params );
267 $formatter = LogFormatter::newFromEntry( $logEntry );
268 $formatter->setContext( $this->context );
270 // Apply the same transformation as done in RecentChange::getIRCLine for rc_comment
271 $ircRcComment = RecentChange::cleanupForIRC( $formatter->getIRCActionComment() );
273 $this->assertEquals(
274 $expected,
275 $ircRcComment,
276 $msg