From 13b817d408402873c71a954505413403cac2a5a1 Mon Sep 17 00:00:00 2001 From: Kunal Mehta Date: Thu, 26 Jul 2018 14:14:54 -0700 Subject: [PATCH] Check for right-* messages as a structure test 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 | 30 ----------------- .../phpunit/structure/AvailableRightsTest.php | 32 +++++++++++++++++++ 2 files changed, 32 insertions(+), 30 deletions(-) diff --git a/tests/phpunit/includes/user/UserTest.php b/tests/phpunit/includes/user/UserTest.php index 294bd80d9f..169a7c556f 100644 --- a/tests/phpunit/includes/user/UserTest.php +++ b/tests/phpunit/includes/user/UserTest.php @@ -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 diff --git a/tests/phpunit/structure/AvailableRightsTest.php b/tests/phpunit/structure/AvailableRightsTest.php index ea132e9a7b..a7d947ef77 100644 --- a/tests/phpunit/structure/AvailableRightsTest.php +++ b/tests/phpunit/structure/AvailableRightsTest.php @@ -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.' + ); + } } -- 2.20.1