Check for right-* messages as a structure test
authorKunal Mehta <legoktm@member.fsf.org>
Thu, 26 Jul 2018 21:14:54 +0000 (14:14 -0700)
committerKunal Mehta <legoktm@member.fsf.org>
Thu, 26 Jul 2018 21:14:54 +0000 (14:14 -0700)
Structure tests run for extensions as well, which this test should. All
user rights should have right-* messages for display in the interface.

Bug: T143156
Change-Id: I23b8eb66bc68121b2ae17e73e705acd3e6f2d053

tests/phpunit/includes/user/UserTest.php
tests/phpunit/structure/AvailableRightsTest.php

index 294bd80..169a7c5 100644 (file)
@@ -235,36 +235,6 @@ class UserTest extends MediaWikiTestCase {
                ];
        }
 
-       /**
-        * Test, if for all rights a right- message exist,
-        * which is used on Special:ListGroupRights as help text
-        * Extensions and core
-        *
-        * @coversNothing
-        */
-       public function testAllRightsWithMessage() {
-               // Getting all user rights, for core: User::$mCoreRights, for extensions: $wgAvailableRights
-               $allRights = User::getAllRights();
-               $allMessageKeys = Language::getMessageKeysFor( 'en' );
-
-               $rightsWithMessage = [];
-               foreach ( $allMessageKeys as $message ) {
-                       // === 0: must be at beginning of string (position 0)
-                       if ( strpos( $message, 'right-' ) === 0 ) {
-                               $rightsWithMessage[] = substr( $message, strlen( 'right-' ) );
-                       }
-               }
-
-               sort( $allRights );
-               sort( $rightsWithMessage );
-
-               $this->assertEquals(
-                       $allRights,
-                       $rightsWithMessage,
-                       'Each user rights (core/extensions) has a corresponding right- message.'
-               );
-       }
-
        /**
         * Test User::editCount
         * @group medium
index ea132e9..a7d947e 100644 (file)
@@ -53,4 +53,36 @@ class AvailableRightsTest extends PHPUnit\Framework\TestCase {
                        'https://www.mediawiki.org/wiki/Manual:User_rights#Adding_new_rights'
                );
        }
+
+       /**
+        * Test, if for all rights a right- message exist,
+        * which is used on Special:ListGroupRights as help text
+        * Extensions and core
+        *
+        * @coversNothing
+        */
+       public function testAllRightsWithMessage() {
+               // Getting all user rights, for core: User::$mCoreRights, for extensions: $wgAvailableRights
+               $allRights = User::getAllRights();
+               $allMessageKeys = Language::getMessageKeysFor( 'en' );
+
+               $rightsWithMessage = [];
+               foreach ( $allMessageKeys as $message ) {
+                       // === 0: must be at beginning of string (position 0)
+                       if ( strpos( $message, 'right-' ) === 0 ) {
+                               $rightsWithMessage[] = substr( $message, strlen( 'right-' ) );
+                       }
+               }
+
+               $missing = array_diff(
+                       $allRights,
+                       $rightsWithMessage
+               );
+
+               $this->assertEquals(
+                       [],
+                       $missing,
+                       'Each user rights (core/extensions) has a corresponding right- message.'
+               );
+       }
 }