Index: trunk/phase3/tests/phpunit/includes/RecentChange.php |
— | — | @@ -0,0 +1,178 @@ |
| 2 | +<?php |
| 3 | +class RecentChangeTest extends MediaWikiTestCase { |
| 4 | + protected $title; |
| 5 | + protected $target; |
| 6 | + protected $user; |
| 7 | + protected $user_comment; |
| 8 | + |
| 9 | + function __construct() { |
| 10 | + parent::__construct(); |
| 11 | + |
| 12 | + $this->title = Title::newFromText( 'SomeTitle' ); |
| 13 | + $this->target = Title::newFromText( 'TestTarget' ); |
| 14 | + $this->user = User::newFromName( 'UserName' ); |
| 15 | + |
| 16 | + $this->user_comment = '<User comment about action>'; |
| 17 | + } |
| 18 | + |
| 19 | + /** |
| 20 | + * The testIrcMsgForAction* tests are supposed to cover the hacky |
| 21 | + * LogFormatter::getIRCActionText / bug 34508 |
| 22 | + * |
| 23 | + * Third parties bots listen to those messages. They are clever enough |
| 24 | + * to fetch the i18n messages from the wiki and then analyze the IRC feed |
| 25 | + * to reverse engineer the $1, $2 messages. |
| 26 | + * One thing bots can not detect is when MediaWiki change the meaning of |
| 27 | + * a message like what happened when we deployed 1.19. $1 became the user |
| 28 | + * performing the action which broke basically all bots around. |
| 29 | + * |
| 30 | + * Need to cover the various switches cases: |
| 31 | + * move: move, move_redir, move-noredirect, move_redir-noredirect |
| 32 | + * delete: delete, restore |
| 33 | + * patrol: patrol |
| 34 | + * newusers: newusers, create, create2, autocreate |
| 35 | + * upload: upload, overwrite |
| 36 | + * suppress |
| 37 | + * and default case |
| 38 | + */ |
| 39 | + |
| 40 | + /** |
| 41 | + * @covers LogFormatter::getIRCActionText |
| 42 | + */ |
| 43 | + function testIrcMsgForActionMove() { |
| 44 | + $move_params = array( |
| 45 | + '4::target' => $this->target->getPrefixedText(), |
| 46 | + '5::noredir' => 0, |
| 47 | + ); |
| 48 | + |
| 49 | + # move/move |
| 50 | + $this->assertIRCComment( |
| 51 | + "moved [[SomeTitle]] to [[TestTarget]]: {$this->user_comment}" |
| 52 | + , 'move', 'move' |
| 53 | + , $move_params |
| 54 | + ); |
| 55 | + |
| 56 | + # move/move_redir |
| 57 | + $this->assertIRCComment( |
| 58 | + "moved [[SomeTitle]] to [[TestTarget]] over redirect: {$this->user_comment}" |
| 59 | + , 'move', 'move_redir' |
| 60 | + , $move_params |
| 61 | + ); |
| 62 | + } |
| 63 | + |
| 64 | + /** |
| 65 | + * @covers LogFormatter::getIRCActionText |
| 66 | + */ |
| 67 | + function testIrcMsgForActionDelete() { |
| 68 | + # delete/delete |
| 69 | + $this->assertIRCComment( |
| 70 | + "deleted "[[SomeTitle]]": {$this->user_comment}" |
| 71 | + , 'delete', 'delete' |
| 72 | + , array() |
| 73 | + ); |
| 74 | + |
| 75 | + # delete/restore |
| 76 | + $this->assertIRCComment( |
| 77 | + "restored "[[SomeTitle]]": {$this->user_comment}" |
| 78 | + , 'delete', 'restore' |
| 79 | + , array() |
| 80 | + ); |
| 81 | + } |
| 82 | + |
| 83 | + /** |
| 84 | + * @covers LogFormatter::getIRCActionText |
| 85 | + */ |
| 86 | + function testIrcMsgForActionPatrol() { |
| 87 | + # patrol/patrol |
| 88 | + $this->assertIRCComment( |
| 89 | + "marked revision 777 of [[SomeTitle]] patrolled : {$this->user_comment}" |
| 90 | + , 'patrol', 'patrol' |
| 91 | + , array( |
| 92 | + '4::curid' => '777', |
| 93 | + '5::previd' => '666', |
| 94 | + '6::auto' => 0, |
| 95 | + |
| 96 | + ) |
| 97 | + ); |
| 98 | + } |
| 99 | + |
| 100 | + /** |
| 101 | + * @covers LogFormatter::getIRCActionText |
| 102 | + */ |
| 103 | + function testIrcMsgForActionNewusers() { |
| 104 | + $this->assertIRCComment( |
| 105 | + "New user account: {$this->user_comment}" |
| 106 | + , 'newusers', 'newusers' |
| 107 | + , array() |
| 108 | + ); |
| 109 | + $this->assertIRCComment( |
| 110 | + "New user account: {$this->user_comment}" |
| 111 | + , 'newusers', 'create' |
| 112 | + , array() |
| 113 | + ); |
| 114 | + $this->assertIRCComment( |
| 115 | + "created new account SomeTitle: {$this->user_comment}" |
| 116 | + , 'newusers', 'create2' |
| 117 | + , array() |
| 118 | + ); |
| 119 | + $this->assertIRCComment( |
| 120 | + "Account created automatically: {$this->user_comment}" |
| 121 | + , 'newusers', 'autocreate' |
| 122 | + , array() |
| 123 | + ); |
| 124 | + } |
| 125 | + |
| 126 | + /** |
| 127 | + * @covers LogFormatter::getIRCActionText |
| 128 | + */ |
| 129 | + function testIrcMsgForActionUpload() { |
| 130 | + # upload/upload |
| 131 | + $this->assertIRCComment( |
| 132 | + "uploaded "[[SomeTitle]]": {$this->user_comment}" |
| 133 | + , 'upload', 'upload' |
| 134 | + , array() |
| 135 | + ); |
| 136 | + |
| 137 | + # upload/overwrite |
| 138 | + $this->assertIRCComment( |
| 139 | + "uploaded a new version of "[[SomeTitle]]": {$this->user_comment}" |
| 140 | + , 'upload', 'overwrite' |
| 141 | + , array() |
| 142 | + ); |
| 143 | + } |
| 144 | + |
| 145 | + /** |
| 146 | + * @covers LogFormatter::getIRCActionText |
| 147 | + */ |
| 148 | + function testIrcMsgForActionSuppress() { |
| 149 | + $this->assertIRCComment( |
| 150 | + "{$this->user_comment}" |
| 151 | + , 'suppress', '' |
| 152 | + , array() |
| 153 | + ); |
| 154 | + } |
| 155 | + |
| 156 | + /** |
| 157 | + * @param $expected String Expected IRC text without colors codes |
| 158 | + * @param $type String Log type (move, delete, suppress, patrol ...) |
| 159 | + * @param $action String A log type action |
| 160 | + * @param $msg String (optional) A message for PHPUnit :-) |
| 161 | + */ |
| 162 | + function assertIRCComment( $expected, $type, $action, $params, $msg = '' ) { |
| 163 | + |
| 164 | + $logEntry = new ManualLogEntry( $type, $action ); |
| 165 | + $logEntry->setPerformer( $this->user ); |
| 166 | + $logEntry->setTarget ( $this->title ); |
| 167 | + $logEntry->setComment ( $this->user_comment ); |
| 168 | + $logEntry->setParameters( $params ); |
| 169 | + |
| 170 | + $formatter = LogFormatter::newFromEntry( $logEntry ); |
| 171 | + $formatter->setContext( RequestContext::newExtraneousContext( $this->title ) ); |
| 172 | + |
| 173 | + $this->assertEquals( $expected, |
| 174 | + $formatter->getIRCActionComment( ), |
| 175 | + $msg |
| 176 | + ); |
| 177 | + } |
| 178 | + |
| 179 | +} |
Property changes on: trunk/phase3/tests/phpunit/includes/RecentChange.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 180 | + native |