[RecentChangeTest] Refactor unit test to test better test the issue
authorKrinkle <krinkle@users.mediawiki.org>
Tue, 28 Feb 2012 00:39:01 +0000 (00:39 +0000)
committerKrinkle <krinkle@users.mediawiki.org>
Tue, 28 Feb 2012 00:39:01 +0000 (00:39 +0000)
* assert used message-keys/variables instead of hardcoded values
* Pass $comment to the assertion helper instead of using it by default so that actions that don't use a comment (such as patrol) don't get forced a comment, to better replicate the IRC behavior
* Adding placeholder for Auto-Edit-Summary things that should also be checked in here, not sure how to do those yet
* Adding tests for block/* and protect/*

tests/phpunit/includes/RecentChangeTest.php

index 67a0b37..c769776 100644 (file)
@@ -26,72 +26,133 @@ class RecentChangeTest extends MediaWikiTestCase {
         * a message like what happened when we deployed 1.19. $1 became the user
         * performing the action which broke basically all bots around.
         *
-        * Need to cover the various switches cases:
-        *   move: move, move_redir, move-noredirect, move_redir-noredirect
-        *   delete: delete, restore
-        *   patrol: patrol
-        *   newusers: newusers, create, create2, autocreate
-        *   upload: upload, overwrite
-        *   suppress
-        *   and default case
+        * Should cover the following log actions (which are most commonly used by bots):
+        * - block/block
+        * - block/unblock
+        * - delete/delete
+        * - delete/restore
+        * - newusers/create
+        * - newusers/create2
+        * - newusers/autocreate
+        * - move/move
+        * - move/move_redir
+        * - protect/protect
+        * - protect/modifyprotect
+        * - protect/unprotect
+        * - upload/upload
+        *
+        * As well as the following Auto Edit Summaries:
+        * - blank
+        * - replace
+        * - rollback
+        * - undo
         */
 
        /**
         * @covers LogFormatter::getIRCActionText
         */
-       function testIrcMsgForActionMove() {
-               $move_params = array(
-                       '4::target'  => $this->target->getPrefixedText(),
-                       '5::noredir' => 0,
+       function testIrcMsgForLogTypeBlock() {
+               # block/block
+               $this->assertIRCComment(
+                       wfMessage( 'blocklogentry', 'SomeTitle' )->plain() . ': ' .  $this->user_comment,
+                       'block', 'block',
+                       array(),
+                       $this->user_comment
+               );
+               # block/unblock
+               $this->assertIRCComment(
+                       wfMessage( 'unblocklogentry', 'SomeTitle' )->plain() . ': ' .  $this->user_comment,
+                       'block', 'unblock',
+                       array(),
+                       $this->user_comment
                );
+       }
 
-               # move/move
+       /**
+        * @covers LogFormatter::getIRCActionText
+        */
+       function testIrcMsgForLogTypeDelete() {
+               # delete/delete
                $this->assertIRCComment(
-                       "moved [[SomeTitle]] to [[TestTarget]]: {$this->user_comment}"
-                       , 'move', 'move'
-                       , $move_params
+                       wfMessage( 'deletedarticle', 'SomeTitle' )->plain() . ': ' .  $this->user_comment,
+                       'delete', 'delete',
+                       array(),
+                       $this->user_comment
                );
 
-               # move/move_redir
+               # delete/restore
                $this->assertIRCComment(
-                       "moved [[SomeTitle]] to [[TestTarget]] over redirect: {$this->user_comment}"
-                       , 'move', 'move_redir'
-                       , $move_params
+                       wfMessage( 'undeletedarticle', 'SomeTitle' )->plain() . ': ' .  $this->user_comment,
+                       'delete', 'restore',
+                       array(),
+                       $this->user_comment
                );
        }
 
        /**
         * @covers LogFormatter::getIRCActionText
         */
-       function testIrcMsgForActionDelete() {
-               # delete/delete
+       function testIrcMsgForLogTypeNewusers() {
+               $this->assertIRCComment(
+                       'New user account',
+                       'newusers', 'newusers',
+                       array()
+               );
+               $this->assertIRCComment(
+                       'New user account',
+                       'newusers', 'create',
+                       array()
+               );
+               $this->assertIRCComment(
+                       'created new account SomeTitle',
+                       'newusers', 'create2',
+                       array()
+               );
                $this->assertIRCComment(
-                       "deleted &quot;[[SomeTitle]]&quot;: {$this->user_comment}"
-                       , 'delete', 'delete'
-                       array()
+                       'Account created automatically',
+                       'newusers', 'autocreate',
+                       array()
                );
+       }
 
-               # delete/restore
+       /**
+        * @covers LogFormatter::getIRCActionText
+        */
+       function testIrcMsgForLogTypeMove() {
+               $move_params = array(
+                       '4::target'  => $this->target->getPrefixedText(),
+                       '5::noredir' => 0,
+               );
+
+               # move/move
+               $this->assertIRCComment(
+                       wfMessage( '1movedto2', 'SomeTitle', 'TestTarget' )->plain() . ': ' .  $this->user_comment,
+                       'move', 'move',
+                       $move_params,
+                       $this->user_comment
+               );
+
+               # move/move_redir
                $this->assertIRCComment(
-                       "restored &quot;[[SomeTitle]]&quot;: {$this->user_comment}"
-                       , 'delete', 'restore'
-                       , array()
+                       wfMessage( '1movedto2_redir', 'SomeTitle', 'TestTarget' )->plain() . ': ' .  $this->user_comment,
+                       'move', 'move_redir',
+                       $move_params,
+                       $this->user_comment
                );
        }
 
        /**
         * @covers LogFormatter::getIRCActionText
         */
-       function testIrcMsgForActionPatrol() {
+       function testIrcMsgForLogTypePatrol() {
                # patrol/patrol
                $this->assertIRCComment(
-                       "marked revision 777 of [[SomeTitle]] patrolled : {$this->user_comment}"
-                       , 'patrol', 'patrol'
-                       array(
+                       wfMessage( 'patrol-log-line', 'revision 777', '[[SomeTitle]]', '' )->plain(),
+                       'patrol', 'patrol',
+                       array(
                                '4::curid'  => '777',
                                '5::previd' => '666',
                                '6::auto'   => 0,
-
                        )
                );
        }
@@ -99,78 +160,104 @@ class RecentChangeTest extends MediaWikiTestCase {
        /**
         * @covers LogFormatter::getIRCActionText
         */
-       function testIrcMsgForActionNewusers() {
-               $this->assertIRCComment(
-                       "New user account: {$this->user_comment}"
-                       , 'newusers', 'newusers'
-                       , array()
-               );
+       function testIrcMsgForLogTypeProtect() {
+
+               # protect/protect
                $this->assertIRCComment(
-                       "New user account: {$this->user_comment}"
-                       , 'newusers', 'create'
-                       , array()
+                       wfMessage( 'protectedarticle', 'SomeTitle' )->plain() . ': ' .  $this->user_comment,
+                       'protect', 'protect',
+                       array(),
+                       $this->user_comment
                );
+
+               # protect/unprotect
                $this->assertIRCComment(
-                       "created new account SomeTitle: {$this->user_comment}"
-                       , 'newusers', 'create2'
-                       , array()
+                       wfMessage( 'unprotectedarticle', 'SomeTitle' )->plain() . ': ' .  $this->user_comment,
+                       'protect', 'unprotect',
+                       array(),
+                       $this->user_comment
                );
+
+               # protect/modify
                $this->assertIRCComment(
-                       "Account created automatically: {$this->user_comment}"
-                       , 'newusers', 'autocreate'
-                       , array()
+                       wfMessage( 'modifiedarticleprotection', 'SomeTitle' )->plain() . ': ' .  $this->user_comment,
+                       'protect', 'modify',
+                       array(),
+                       $this->user_comment
                );
        }
 
        /**
         * @covers LogFormatter::getIRCActionText
         */
-       function testIrcMsgForActionUpload() {
+       function testIrcMsgForLogTypeUpload() {
                # upload/upload
                $this->assertIRCComment(
-                       "uploaded &quot;[[SomeTitle]]&quot;: {$this->user_comment}"
-                       , 'upload', 'upload'
-                       , array()
+                       wfMessage( 'uploadedimage', 'SomeTitle' )->plain() . ': ' .  $this->user_comment,
+                       'upload', 'upload',
+                       array(),
+                       $this->user_comment
                );
 
                # upload/overwrite
                $this->assertIRCComment(
-                       "uploaded a new version of &quot;[[SomeTitle]]&quot;: {$this->user_comment}"
-                       , 'upload', 'overwrite'
-                       , array()
+                       wfMessage( 'overwroteimage', 'SomeTitle' )->plain() . ': ' .  $this->user_comment,
+                       'upload', 'overwrite',
+                       array(),
+                       $this->user_comment
                );
        }
 
        /**
-        * @covers LogFormatter::getIRCActionText
-        */
-       function testIrcMsgForActionSuppress() {
-               $this->assertIRCComment(
-                       "{$this->user_comment}"
-                       , 'suppress', ''
-                       , array()
-               );
+        * @todo: Emulate these edits somehow and extract
+        * raw edit summary from RecentChange object
+        * --
+
+       function testIrcMsgForBlankingAES() {
+               // wfMessage( 'autosumm-blank', .. );
+       }
+
+       function testIrcMsgForReplaceAES() {
+               // wfMessage( 'autosumm-replace', .. );
        }
 
+       function testIrcMsgForRollbackAES() {
+               // wfMessage( 'revertpage', .. );
+       }
+
+       function testIrcMsgForUndoAES() {
+               // wfMessage( 'undo-summary', .. );
+       }
+
+        * --
+        */
+
        /**
         * @param $expected String Expected IRC text without colors codes
         * @param $type String Log type (move, delete, suppress, patrol ...)
         * @param $action String A log type action
+        * @param $comment String (optional) A comment for the log action
         * @param $msg String (optional) A message for PHPUnit :-)
         */
-       function assertIRCComment( $expected, $type, $action, $params, $msg = '' ) {
+       function assertIRCComment( $expected, $type, $action, $params, $comment = null, $msg = '' ) {
 
                $logEntry = new ManualLogEntry( $type, $action );
-               $logEntry->setPerformer( $this->user         );
-               $logEntry->setTarget   ( $this->title        );
-               $logEntry->setComment  ( $this->user_comment );
+               $logEntry->setPerformer( $this->user );
+               $logEntry->setTarget( $this->title );
+               if ( $comment !== null ) {
+                       $logEntry->setComment( $comment );
+               }
                $logEntry->setParameters( $params );
 
                $formatter = LogFormatter::newFromEntry( $logEntry );
                $formatter->setContext( RequestContext::newExtraneousContext( $this->title ) );
 
-               $this->assertEquals( $expected,
-                       $formatter->getIRCActionComment( ),
+               // Apply the same transformation as done in RecentChange::getIRCLine for rc_comment
+               $ircRcComment = RecentChange::cleanupForIRC( $formatter->getIRCActionComment() );
+
+               $this->assertEquals(
+                       $expected,
+                       $ircRcComment,
                        $msg
                );
        }