2 class RecentChangeTest
extends MediaWikiTestCase
{
6 protected $user_comment;
8 function __construct() {
11 $this->title
= Title
::newFromText( 'SomeTitle' );
12 $this->target
= Title
::newFromText( 'TestTarget' );
13 $this->user
= User
::newFromName( 'UserName' );
15 $this->user_comment
= '<User comment about action>';
19 * The testIrcMsgForAction* tests are supposed to cover the hacky
20 * LogFormatter::getIRCActionText / bug 34508
22 * Third parties bots listen to those messages. They are clever enough
23 * to fetch the i18n messages from the wiki and then analyze the IRC feed
24 * to reverse engineer the $1, $2 messages.
25 * One thing bots can not detect is when MediaWiki change the meaning of
26 * a message like what happened when we deployed 1.19. $1 became the user
27 * performing the action which broke basically all bots around.
29 * Need to cover the various switches cases:
30 * move: move, move_redir, move-noredirect, move_redir-noredirect
31 * delete: delete, restore
33 * newusers: newusers, create, create2, autocreate
34 * upload: upload, overwrite
40 * @covers LogFormatter::getIRCActionText
42 function testIrcMsgForActionMove() {
44 '4::target' => $this->target
->getPrefixedText(),
49 $this->assertIRCComment(
50 "moved [[SomeTitle]] to [[TestTarget]]: {$this->user_comment}"
56 $this->assertIRCComment(
57 "moved [[SomeTitle]] to [[TestTarget]] over redirect: {$this->user_comment}"
58 , 'move', 'move_redir'
64 * @covers LogFormatter::getIRCActionText
66 function testIrcMsgForActionDelete() {
68 $this->assertIRCComment(
69 "deleted "[[SomeTitle]]": {$this->user_comment}"
75 $this->assertIRCComment(
76 "restored "[[SomeTitle]]": {$this->user_comment}"
83 * @covers LogFormatter::getIRCActionText
85 function testIrcMsgForActionPatrol() {
87 $this->assertIRCComment(
88 "marked revision 777 of [[SomeTitle]] patrolled : {$this->user_comment}"
100 * @covers LogFormatter::getIRCActionText
102 function testIrcMsgForActionNewusers() {
103 $this->assertIRCComment(
104 "New user account: {$this->user_comment}"
105 , 'newusers', 'newusers'
108 $this->assertIRCComment(
109 "New user account: {$this->user_comment}"
110 , 'newusers', 'create'
113 $this->assertIRCComment(
114 "created new account SomeTitle: {$this->user_comment}"
115 , 'newusers', 'create2'
118 $this->assertIRCComment(
119 "Account created automatically: {$this->user_comment}"
120 , 'newusers', 'autocreate'
126 * @covers LogFormatter::getIRCActionText
128 function testIrcMsgForActionUpload() {
130 $this->assertIRCComment(
131 "uploaded "[[SomeTitle]]": {$this->user_comment}"
137 $this->assertIRCComment(
138 "uploaded a new version of "[[SomeTitle]]": {$this->user_comment}"
139 , 'upload', 'overwrite'
145 * @covers LogFormatter::getIRCActionText
147 function testIrcMsgForActionSuppress() {
148 $this->assertIRCComment(
149 "{$this->user_comment}"
156 * @param $expected String Expected IRC text without colors codes
157 * @param $type String Log type (move, delete, suppress, patrol ...)
158 * @param $action String A log type action
159 * @param $msg String (optional) A message for PHPUnit :-)
161 function assertIRCComment( $expected, $type, $action, $params, $msg = '' ) {
163 $logEntry = new ManualLogEntry( $type, $action );
164 $logEntry->setPerformer( $this->user
);
165 $logEntry->setTarget ( $this->title
);
166 $logEntry->setComment ( $this->user_comment
);
167 $logEntry->setParameters( $params );
169 $formatter = LogFormatter
::newFromEntry( $logEntry );
170 $formatter->setContext( RequestContext
::newExtraneousContext( $this->title
) );
172 $this->assertEquals( $expected,
173 $formatter->getIRCActionComment( ),