Merge "i18n: Rename 11 messages for case-compliance"
[lhc/web/wiklou.git] / tests / phpunit / includes / LinkerTest.php
index 34e5593..2362961 100644 (file)
@@ -1,6 +1,5 @@
 <?php
 
-
 /**
  * @group Database
  */
@@ -15,11 +14,16 @@ class LinkerTest extends MediaWikiLangTestCase {
                        'wgArticlePath' => '/wiki/$1',
                ] );
 
-               $this->assertEquals(
-                       $expected,
-                       Linker::userLink( $userId, $userName, $altUserName ),
-                       $msg
-               );
+               // We'd also test the warning, but injecting a mock logger into a static method is tricky.
+               if ( $userName === '' ) {
+                       Wikimedia\suppressWarnings();
+               }
+               $actual = Linker::userLink( $userId, $userName, $altUserName );
+               if ( $userName === '' ) {
+                       Wikimedia\restoreWarnings();
+               }
+
+               $this->assertEquals( $expected, $actual, $msg );
        }
 
        public static function provideCasesForUserLink() {
@@ -30,6 +34,9 @@ class LinkerTest extends MediaWikiLangTestCase {
                # - optional altUserName
                # - optional message
                return [
+                       # Empty name (T222529)
+                       'Empty username, userid 0' => [ '(no username available)', 0, '' ],
+                       'Empty username, userid > 0' => [ '(no username available)', 73, '' ],
 
                        # ## ANONYMOUS USER ########################################
                        [
@@ -88,6 +95,118 @@ class LinkerTest extends MediaWikiLangTestCase {
                ];
        }
 
+       /**
+        * @dataProvider provideUserToolLinks
+        * @covers Linker::userToolLinks
+        * @param string $expected
+        * @param int $userId
+        * @param string $userText
+        */
+       public function testUserToolLinks( $expected, $userId, $userText ) {
+               // We'd also test the warning, but injecting a mock logger into a static method is tricky.
+               if ( $userText === '' ) {
+                       Wikimedia\suppressWarnings();
+               }
+               $actual = Linker::userToolLinks( $userId, $userText );
+               if ( $userText === '' ) {
+                       Wikimedia\restoreWarnings();
+               }
+
+               $this->assertSame( $expected, $actual );
+       }
+
+       public static function provideUserToolLinks() {
+               return [
+                       // Empty name (T222529)
+                       'Empty username, userid 0' => [ ' (no username available)', 0, '' ],
+                       'Empty username, userid > 0' => [ ' (no username available)', 73, '' ],
+               ];
+       }
+
+       /**
+        * @dataProvider provideUserTalkLink
+        * @covers Linker::userTalkLink
+        * @param string $expected
+        * @param int $userId
+        * @param string $userText
+        */
+       public function testUserTalkLink( $expected, $userId, $userText ) {
+               // We'd also test the warning, but injecting a mock logger into a static method is tricky.
+               if ( $userText === '' ) {
+                       Wikimedia\suppressWarnings();
+               }
+               $actual = Linker::userTalkLink( $userId, $userText );
+               if ( $userText === '' ) {
+                       Wikimedia\restoreWarnings();
+               }
+
+               $this->assertSame( $expected, $actual );
+       }
+
+       public static function provideUserTalkLink() {
+               return [
+                       // Empty name (T222529)
+                       'Empty username, userid 0' => [ '(no username available)', 0, '' ],
+                       'Empty username, userid > 0' => [ '(no username available)', 73, '' ],
+               ];
+       }
+
+       /**
+        * @dataProvider provideBlockLink
+        * @covers Linker::blockLink
+        * @param string $expected
+        * @param int $userId
+        * @param string $userText
+        */
+       public function testBlockLink( $expected, $userId, $userText ) {
+               // We'd also test the warning, but injecting a mock logger into a static method is tricky.
+               if ( $userText === '' ) {
+                       Wikimedia\suppressWarnings();
+               }
+               $actual = Linker::blockLink( $userId, $userText );
+               if ( $userText === '' ) {
+                       Wikimedia\restoreWarnings();
+               }
+
+               $this->assertSame( $expected, $actual );
+       }
+
+       public static function provideBlockLink() {
+               return [
+                       // Empty name (T222529)
+                       'Empty username, userid 0' => [ '(no username available)', 0, '' ],
+                       'Empty username, userid > 0' => [ '(no username available)', 73, '' ],
+               ];
+       }
+
+       /**
+        * @dataProvider provideEmailLink
+        * @covers Linker::emailLink
+        * @param string $expected
+        * @param int $userId
+        * @param string $userText
+        */
+       public function testEmailLink( $expected, $userId, $userText ) {
+               // We'd also test the warning, but injecting a mock logger into a static method is tricky.
+               if ( $userText === '' ) {
+                       Wikimedia\suppressWarnings();
+               }
+               $actual = Linker::emailLink( $userId, $userText );
+               if ( $userText === '' ) {
+                       Wikimedia\restoreWarnings();
+               }
+
+               $this->assertSame( $expected, $actual );
+       }
+
+       public static function provideEmailLink() {
+               return [
+                       // Empty name (T222529)
+                       'Empty username, userid 0' => [ '(no username available)', 0, '' ],
+                       'Empty username, userid > 0' => [ '(no username available)', 73, '' ],
+               ];
+       }
+
        /**
         * @dataProvider provideCasesForFormatComment
         * @covers Linker::formatComment
@@ -286,6 +405,48 @@ class LinkerTest extends MediaWikiLangTestCase {
                );
        }
 
+       /**
+        * @covers Linker::generateRollback
+        * @dataProvider provideCasesForRollbackGeneration
+        */
+       public function testGenerateRollback( $rollbackEnabled, $expectedModules ) {
+               $this->markTestSkippedIfDbType( 'postgres' );
+
+               $context = RequestContext::getMain();
+               $user = $context->getUser();
+               $user->setOption( 'showrollbackconfirmation', $rollbackEnabled );
+
+               $pageData = $this->insertPage( 'Rollback_Test_Page' );
+               $page = WikiPage::factory( $pageData['title'] );
+
+               $updater = $page->newPageUpdater( $user );
+               $updater->setContent( \MediaWiki\Revision\SlotRecord::MAIN,
+                       new TextContent( 'Technical Wishes 123!' )
+               );
+               $summary = CommentStoreComment::newUnsavedComment( 'Some comment!' );
+               $updater->saveRevision( $summary );
+
+               $rollbackOutput = Linker::generateRollback( $page->getRevision(), $context );
+               $modules = $context->getOutput()->getModules();
+
+               $this->assertEquals( $expectedModules, $modules );
+               $this->assertContains( 'rollback 1 edit', $rollbackOutput );
+       }
+
+       public static function provideCasesForRollbackGeneration() {
+               return [
+                       [
+                               true,
+                               [ 'mediawiki.page.rollback.confirmation' ]
+
+                       ],
+                       [
+                               false,
+                               []
+                       ]
+               ];
+       }
+
        public static function provideCasesForFormatLinksInComment() {
                // phpcs:disable Generic.Files.LineLength
                return [