Cleanup RecentChangeTest, move things out that don't belong
authoraddshore <addshorewiki@gmail.com>
Mon, 21 Sep 2015 08:50:04 +0000 (09:50 +0100)
committeraddshore <addshorewiki@gmail.com>
Mon, 21 Sep 2015 13:33:10 +0000 (14:33 +0100)
This moves out a bunch of stuff that doesnt
seem to test anything in RecentChange....

This also shows us how few tests RecentChange
actually has!

Change-Id: Ia5016c82c00dd7c35a6f1253d6e385b587ec485e

tests/phpunit/includes/changes/RecentChangeTest.php
tests/phpunit/includes/logging/LogFormatterTest.php

index 60235b8..49ac574 100644 (file)
@@ -59,291 +59,6 @@ class RecentChangeTest extends MediaWikiTestCase {
         * - undo
         */
 
-       /**
-        * @covers LogFormatter::getIRCActionText
-        */
-       public function testIrcMsgForLogTypeBlock() {
-               $sep = $this->context->msg( 'colon-separator' )->text();
-
-               # block/block
-               $this->assertIRCComment(
-                       $this->context->msg( 'blocklogentry', 'SomeTitle', 'duration', '(flags)' )->plain()
-                               . $sep . $this->user_comment,
-                       'block', 'block',
-                       array(
-                               '5::duration' => 'duration',
-                               '6::flags' => 'flags',
-                       ),
-                       $this->user_comment
-               );
-               # block/block - legacy
-               $this->assertIRCComment(
-                       $this->context->msg( 'blocklogentry', 'SomeTitle', 'duration', '(flags)' )->plain()
-                               . $sep . $this->user_comment,
-                       'block', 'block',
-                       array(
-                               'duration',
-                               'flags',
-                       ),
-                       $this->user_comment,
-                       '',
-                       true
-               );
-               # block/unblock
-               $this->assertIRCComment(
-                       $this->context->msg( 'unblocklogentry', 'SomeTitle' )->plain() . $sep . $this->user_comment,
-                       'block', 'unblock',
-                       array(),
-                       $this->user_comment
-               );
-               # block/reblock
-               $this->assertIRCComment(
-                       $this->context->msg( 'reblock-logentry', 'SomeTitle', 'duration', '(flags)' )->plain()
-                               . $sep . $this->user_comment,
-                       'block', 'reblock',
-                       array(
-                               '5::duration' => 'duration',
-                               '6::flags' => 'flags',
-                       ),
-                       $this->user_comment
-               );
-       }
-
-       /**
-        * @covers LogFormatter::getIRCActionText
-        */
-       public function testIrcMsgForLogTypeDelete() {
-               $sep = $this->context->msg( 'colon-separator' )->text();
-
-               # delete/delete
-               $this->assertIRCComment(
-                       $this->context->msg( 'deletedarticle', 'SomeTitle' )->plain() . $sep . $this->user_comment,
-                       'delete', 'delete',
-                       array(),
-                       $this->user_comment
-               );
-
-               # delete/restore
-               $this->assertIRCComment(
-                       $this->context->msg( 'undeletedarticle', 'SomeTitle' )->plain() . $sep . $this->user_comment,
-                       'delete', 'restore',
-                       array(),
-                       $this->user_comment
-               );
-       }
-
-       /**
-        * @covers LogFormatter::getIRCActionText
-        */
-       public 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(
-                       'Account created automatically',
-                       'newusers', 'autocreate',
-                       array()
-               );
-       }
-
-       /**
-        * @covers LogFormatter::getIRCActionText
-        */
-       public function testIrcMsgForLogTypeMove() {
-               $move_params = array(
-                       '4::target' => $this->target->getPrefixedText(),
-                       '5::noredir' => 0,
-               );
-               $sep = $this->context->msg( 'colon-separator' )->text();
-
-               # move/move
-               $this->assertIRCComment(
-                       $this->context->msg( '1movedto2', 'SomeTitle', 'TestTarget' )
-                               ->plain() . $sep . $this->user_comment,
-                       'move', 'move',
-                       $move_params,
-                       $this->user_comment
-               );
-
-               # move/move_redir
-               $this->assertIRCComment(
-                       $this->context->msg( '1movedto2_redir', 'SomeTitle', 'TestTarget' )
-                               ->plain() . $sep . $this->user_comment,
-                       'move', 'move_redir',
-                       $move_params,
-                       $this->user_comment
-               );
-       }
-
-       /**
-        * @covers LogFormatter::getIRCActionText
-        */
-       public function testIrcMsgForLogTypePatrol() {
-               # patrol/patrol
-               $this->assertIRCComment(
-                       $this->context->msg( 'patrol-log-line', 'revision 777', '[[SomeTitle]]', '' )->plain(),
-                       'patrol', 'patrol',
-                       array(
-                               '4::curid' => '777',
-                               '5::previd' => '666',
-                               '6::auto' => 0,
-                       )
-               );
-       }
-
-       /**
-        * @covers LogFormatter::getIRCActionText
-        */
-       public function testIrcMsgForLogTypeProtect() {
-               $protectParams = array(
-                       '[edit=sysop] (indefinite) ‎[move=sysop] (indefinite)'
-               );
-               $sep = $this->context->msg( 'colon-separator' )->text();
-
-               # protect/protect
-               $this->assertIRCComment(
-                       $this->context->msg( 'protectedarticle', 'SomeTitle ' . $protectParams[0] )
-                               ->plain() . $sep . $this->user_comment,
-                       'protect', 'protect',
-                       $protectParams,
-                       $this->user_comment
-               );
-
-               # protect/unprotect
-               $this->assertIRCComment(
-                       $this->context->msg( 'unprotectedarticle', 'SomeTitle' )->plain() . $sep . $this->user_comment,
-                       'protect', 'unprotect',
-                       array(),
-                       $this->user_comment
-               );
-
-               # protect/modify
-               $this->assertIRCComment(
-                       $this->context->msg( 'modifiedarticleprotection', 'SomeTitle ' . $protectParams[0] )
-                               ->plain() . $sep . $this->user_comment,
-                       'protect', 'modify',
-                       $protectParams,
-                       $this->user_comment
-               );
-
-               # protect/move_prot
-               $this->assertIRCComment(
-                       $this->context->msg( 'movedarticleprotection', 'SomeTitle', 'OldTitle' )
-                               ->plain() . $sep . $this->user_comment,
-                       'protect', 'move_prot',
-                       array(
-                               '4::oldtitle' => 'OldTitle'
-                       ),
-                       $this->user_comment
-               );
-       }
-
-       /**
-        * @covers LogFormatter::getIRCActionText
-        */
-       public function testIrcMsgForLogTypeUpload() {
-               $sep = $this->context->msg( 'colon-separator' )->text();
-
-               # upload/upload
-               $this->assertIRCComment(
-                       $this->context->msg( 'uploadedimage', 'SomeTitle' )->plain() . $sep . $this->user_comment,
-                       'upload', 'upload',
-                       array(),
-                       $this->user_comment
-               );
-
-               # upload/overwrite
-               $this->assertIRCComment(
-                       $this->context->msg( 'overwroteimage', 'SomeTitle' )->plain() . $sep . $this->user_comment,
-                       'upload', 'overwrite',
-                       array(),
-                       $this->user_comment
-               );
-       }
-
-       /**
-        * @covers LogFormatter::getIRCActionText
-        */
-       public function testIrcMsgForLogTypeMerge() {
-               $sep = $this->context->msg( 'colon-separator' )->text();
-
-               # merge/merge
-               $this->assertIRCComment(
-                       $this->context->msg( 'pagemerge-logentry', 'SomeTitle', 'Dest', 'timestamp' )->plain()
-                               . $sep . $this->user_comment,
-                       'merge', 'merge',
-                       array(
-                               '4::dest' => 'Dest',
-                               '5::mergepoint' => 'timestamp',
-                       ),
-                       $this->user_comment
-               );
-       }
-
-       /**
-        * @covers LogFormatter::getIRCActionText
-        */
-       public function testIrcMsgForLogTypeImport() {
-               $sep = $this->context->msg( 'colon-separator' )->text();
-
-               # import/upload
-               $msg = $this->context->msg( 'import-logentry-upload', 'SomeTitle' )->plain() .
-                       $sep .
-                       $this->user_comment;
-               $this->assertIRCComment(
-                       $msg,
-                       'import', 'upload',
-                       array(),
-                       $this->user_comment
-               );
-
-               # import/interwiki
-               $msg = $this->context->msg( 'import-logentry-interwiki', 'SomeTitle' )->plain() .
-                       $sep .
-                       $this->user_comment;
-               $this->assertIRCComment(
-                       $msg,
-                       'import', 'interwiki',
-                       array(),
-                       $this->user_comment
-               );
-       }
-
-       /**
-        * @todo Emulate these edits somehow and extract
-        * raw edit summary from RecentChange object
-        * --
-        */
-       /*
-       public function testIrcMsgForBlankingAES() {
-               // $this->context->msg( 'autosumm-blank', .. );
-       }
-
-       public function testIrcMsgForReplaceAES() {
-               // $this->context->msg( 'autosumm-replace', .. );
-       }
-
-       public function testIrcMsgForRollbackAES() {
-               // $this->context->msg( 'revertpage', .. );
-       }
-
-       public function testIrcMsgForUndoAES() {
-               // $this->context->msg( 'undo-summary', .. );
-       }
-       */
-
        /**
         * @covers RecentChange::parseParams
         */
@@ -389,36 +104,4 @@ class RecentChangeTest extends MediaWikiTestCase {
                $this->assertEquals( $expectedParseParams, $actualParseParams );
        }
 
-       /**
-        * @param string $expected Expected IRC text without colors codes
-        * @param string $type Log type (move, delete, suppress, patrol ...)
-        * @param string $action A log type action
-        * @param array $params
-        * @param string $comment (optional) A comment for the log action
-        * @param string $msg (optional) A message for PHPUnit :-)
-        */
-       protected function assertIRCComment( $expected, $type, $action, $params,
-               $comment = null, $msg = '', $legacy = false
-       ) {
-               $logEntry = new ManualLogEntry( $type, $action );
-               $logEntry->setPerformer( $this->user );
-               $logEntry->setTarget( $this->title );
-               if ( $comment !== null ) {
-                       $logEntry->setComment( $comment );
-               }
-               $logEntry->setParameters( $params );
-               $logEntry->setLegacy( $legacy );
-
-               $formatter = LogFormatter::newFromEntry( $logEntry );
-               $formatter->setContext( $this->context );
-
-               // Apply the same transformation as done in IRCColourfulRCFeedFormatter::getLine for rc_comment
-               $ircRcComment = IRCColourfulRCFeedFormatter::cleanupForIRC( $formatter->getIRCActionComment() );
-
-               $this->assertEquals(
-                       $expected,
-                       $ircRcComment,
-                       $msg
-               );
-       }
 }
index 515990e..844c9af 100644 (file)
@@ -1,4 +1,5 @@
 <?php
+
 /**
  * @group Database
  */
@@ -19,6 +20,16 @@ class LogFormatterTest extends MediaWikiLangTestCase {
         */
        protected $context;
 
+       /**
+        * @var Title
+        */
+       protected $target;
+
+       /**
+        * @var string
+        */
+       protected $user_comment;
+
        protected function setUp() {
                parent::setUp();
 
@@ -35,12 +46,15 @@ class LogFormatterTest extends MediaWikiLangTestCase {
                Language::getLocalisationCache()->recache( $wgLang->getCode() );
 
                $this->user = User::newFromName( 'Testuser' );
-               $this->title = Title::newMainPage();
+               $this->title = Title::newFromText( 'SomeTitle' );
+               $this->target = Title::newFromText( 'TestTarget' );
 
                $this->context = new RequestContext();
                $this->context->setUser( $this->user );
                $this->context->setTitle( $this->title );
                $this->context->setLanguage( $wgLang );
+
+               $this->user_comment = '<User comment about action>';
        }
 
        protected function tearDown() {
@@ -292,4 +306,309 @@ class LogFormatterTest extends MediaWikiLangTestCase {
                        array( '4:user-link:key', 'foo', array( 'key' => 'Foo' ) ),
                );
        }
+
+       /**
+        * @covers LogFormatter::getIRCActionComment
+        * @covers LogFormatter::getIRCActionText
+        */
+       public function testIrcMsgForLogTypeBlock() {
+               $sep = $this->context->msg( 'colon-separator' )->text();
+
+               # block/block
+               $this->assertIRCComment(
+                       $this->context->msg( 'blocklogentry', 'SomeTitle', 'duration', '(flags)' )->plain()
+                       . $sep . $this->user_comment,
+                       'block', 'block',
+                       array(
+                               '5::duration' => 'duration',
+                               '6::flags' => 'flags',
+                       ),
+                       $this->user_comment
+               );
+               # block/block - legacy
+               $this->assertIRCComment(
+                       $this->context->msg( 'blocklogentry', 'SomeTitle', 'duration', '(flags)' )->plain()
+                       . $sep . $this->user_comment,
+                       'block', 'block',
+                       array(
+                               'duration',
+                               'flags',
+                       ),
+                       $this->user_comment,
+                       '',
+                       true
+               );
+               # block/unblock
+               $this->assertIRCComment(
+                       $this->context->msg( 'unblocklogentry', 'SomeTitle' )->plain() . $sep . $this->user_comment,
+                       'block', 'unblock',
+                       array(),
+                       $this->user_comment
+               );
+               # block/reblock
+               $this->assertIRCComment(
+                       $this->context->msg( 'reblock-logentry', 'SomeTitle', 'duration', '(flags)' )->plain()
+                       . $sep . $this->user_comment,
+                       'block', 'reblock',
+                       array(
+                               '5::duration' => 'duration',
+                               '6::flags' => 'flags',
+                       ),
+                       $this->user_comment
+               );
+       }
+
+       /**
+        * @covers LogFormatter::getIRCActionComment
+        * @covers LogFormatter::getIRCActionText
+        */
+       public function testIrcMsgForLogTypeDelete() {
+               $sep = $this->context->msg( 'colon-separator' )->text();
+
+               # delete/delete
+               $this->assertIRCComment(
+                       $this->context->msg( 'deletedarticle', 'SomeTitle' )->plain() . $sep . $this->user_comment,
+                       'delete', 'delete',
+                       array(),
+                       $this->user_comment
+               );
+
+               # delete/restore
+               $this->assertIRCComment(
+                       $this->context->msg( 'undeletedarticle', 'SomeTitle' )->plain() . $sep . $this->user_comment,
+                       'delete', 'restore',
+                       array(),
+                       $this->user_comment
+               );
+       }
+
+       /**
+        * @covers LogFormatter::getIRCActionComment
+        * @covers LogFormatter::getIRCActionText
+        */
+       public 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(
+                       'Account created automatically',
+                       'newusers', 'autocreate',
+                       array()
+               );
+       }
+
+       /**
+        * @covers LogFormatter::getIRCActionComment
+        * @covers LogFormatter::getIRCActionText
+        */
+       public function testIrcMsgForLogTypeMove() {
+               $move_params = array(
+                       '4::target' => $this->target->getPrefixedText(),
+                       '5::noredir' => 0,
+               );
+               $sep = $this->context->msg( 'colon-separator' )->text();
+
+               # move/move
+               $this->assertIRCComment(
+                       $this->context->msg( '1movedto2', 'SomeTitle', 'TestTarget' )
+                               ->plain() . $sep . $this->user_comment,
+                       'move', 'move',
+                       $move_params,
+                       $this->user_comment
+               );
+
+               # move/move_redir
+               $this->assertIRCComment(
+                       $this->context->msg( '1movedto2_redir', 'SomeTitle', 'TestTarget' )
+                               ->plain() . $sep . $this->user_comment,
+                       'move', 'move_redir',
+                       $move_params,
+                       $this->user_comment
+               );
+       }
+
+       /**
+        * @covers LogFormatter::getIRCActionComment
+        * @covers LogFormatter::getIRCActionText
+        */
+       public function testIrcMsgForLogTypePatrol() {
+               # patrol/patrol
+               $this->assertIRCComment(
+                       $this->context->msg( 'patrol-log-line', 'revision 777', '[[SomeTitle]]', '' )->plain(),
+                       'patrol', 'patrol',
+                       array(
+                               '4::curid' => '777',
+                               '5::previd' => '666',
+                               '6::auto' => 0,
+                       )
+               );
+       }
+
+       /**
+        * @covers LogFormatter::getIRCActionComment
+        * @covers LogFormatter::getIRCActionText
+        */
+       public function testIrcMsgForLogTypeProtect() {
+               $protectParams = array(
+                       '[edit=sysop] (indefinite) ‎[move=sysop] (indefinite)'
+               );
+               $sep = $this->context->msg( 'colon-separator' )->text();
+
+               # protect/protect
+               $this->assertIRCComment(
+                       $this->context->msg( 'protectedarticle', 'SomeTitle ' . $protectParams[0] )
+                               ->plain() . $sep . $this->user_comment,
+                       'protect', 'protect',
+                       $protectParams,
+                       $this->user_comment
+               );
+
+               # protect/unprotect
+               $this->assertIRCComment(
+                       $this->context->msg( 'unprotectedarticle', 'SomeTitle' )->plain() . $sep . $this->user_comment,
+                       'protect', 'unprotect',
+                       array(),
+                       $this->user_comment
+               );
+
+               # protect/modify
+               $this->assertIRCComment(
+                       $this->context->msg( 'modifiedarticleprotection', 'SomeTitle ' . $protectParams[0] )
+                               ->plain() . $sep . $this->user_comment,
+                       'protect', 'modify',
+                       $protectParams,
+                       $this->user_comment
+               );
+
+               # protect/move_prot
+               $this->assertIRCComment(
+                       $this->context->msg( 'movedarticleprotection', 'SomeTitle', 'OldTitle' )
+                               ->plain() . $sep . $this->user_comment,
+                       'protect', 'move_prot',
+                       array(
+                               '4::oldtitle' => 'OldTitle'
+                       ),
+                       $this->user_comment
+               );
+       }
+
+       /**
+        * @covers LogFormatter::getIRCActionComment
+        * @covers LogFormatter::getIRCActionText
+        */
+       public function testIrcMsgForLogTypeUpload() {
+               $sep = $this->context->msg( 'colon-separator' )->text();
+
+               # upload/upload
+               $this->assertIRCComment(
+                       $this->context->msg( 'uploadedimage', 'SomeTitle' )->plain() . $sep . $this->user_comment,
+                       'upload', 'upload',
+                       array(),
+                       $this->user_comment
+               );
+
+               # upload/overwrite
+               $this->assertIRCComment(
+                       $this->context->msg( 'overwroteimage', 'SomeTitle' )->plain() . $sep . $this->user_comment,
+                       'upload', 'overwrite',
+                       array(),
+                       $this->user_comment
+               );
+       }
+
+       /**
+        * @covers LogFormatter::getIRCActionComment
+        * @covers LogFormatter::getIRCActionText
+        */
+       public function testIrcMsgForLogTypeMerge() {
+               $sep = $this->context->msg( 'colon-separator' )->text();
+
+               # merge/merge
+               $this->assertIRCComment(
+                       $this->context->msg( 'pagemerge-logentry', 'SomeTitle', 'Dest', 'timestamp' )->plain()
+                       . $sep . $this->user_comment,
+                       'merge', 'merge',
+                       array(
+                               '4::dest' => 'Dest',
+                               '5::mergepoint' => 'timestamp',
+                       ),
+                       $this->user_comment
+               );
+       }
+
+       /**
+        * @covers LogFormatter::getIRCActionComment
+        * @covers LogFormatter::getIRCActionText
+        */
+       public function testIrcMsgForLogTypeImport() {
+               $sep = $this->context->msg( 'colon-separator' )->text();
+
+               # import/upload
+               $msg = $this->context->msg( 'import-logentry-upload', 'SomeTitle' )->plain() .
+                       $sep .
+                       $this->user_comment;
+               $this->assertIRCComment(
+                       $msg,
+                       'import', 'upload',
+                       array(),
+                       $this->user_comment
+               );
+
+               # import/interwiki
+               $msg = $this->context->msg( 'import-logentry-interwiki', 'SomeTitle' )->plain() .
+                       $sep .
+                       $this->user_comment;
+               $this->assertIRCComment(
+                       $msg,
+                       'import', 'interwiki',
+                       array(),
+                       $this->user_comment
+               );
+       }
+
+       /**
+        * @param string $expected Expected IRC text without colors codes
+        * @param string $type Log type (move, delete, suppress, patrol ...)
+        * @param string $action A log type action
+        * @param array $params
+        * @param string $comment (optional) A comment for the log action
+        * @param string $msg (optional) A message for PHPUnit :-)
+        */
+       protected function assertIRCComment( $expected, $type, $action, $params,
+               $comment = null, $msg = '', $legacy = false
+       ) {
+               $logEntry = new ManualLogEntry( $type, $action );
+               $logEntry->setPerformer( $this->user );
+               $logEntry->setTarget( $this->title );
+               if ( $comment !== null ) {
+                       $logEntry->setComment( $comment );
+               }
+               $logEntry->setParameters( $params );
+               $logEntry->setLegacy( $legacy );
+
+               $formatter = LogFormatter::newFromEntry( $logEntry );
+               $formatter->setContext( $this->context );
+
+               // Apply the same transformation as done in IRCColourfulRCFeedFormatter::getLine for rc_comment
+               $ircRcComment = IRCColourfulRCFeedFormatter::cleanupForIRC( $formatter->getIRCActionComment() );
+
+               $this->assertEquals(
+                       $expected,
+                       $ircRcComment,
+                       $msg
+               );
+       }
+
 }