From 3ecbd79ebefa6b61affad06fec81321f1130cb62 Mon Sep 17 00:00:00 2001 From: Reedy Date: Fri, 12 Apr 2019 00:26:51 +0100 Subject: [PATCH] Add test to check action- messages exist Bug: T220779 Change-Id: Ide681e1f03957a8024f538ea6cac4e4396fef23e --- .../phpunit/structure/AvailableRightsTest.php | 28 +++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/tests/phpunit/structure/AvailableRightsTest.php b/tests/phpunit/structure/AvailableRightsTest.php index a7d947ef77..57b063d5ba 100644 --- a/tests/phpunit/structure/AvailableRightsTest.php +++ b/tests/phpunit/structure/AvailableRightsTest.php @@ -54,6 +54,17 @@ class AvailableRightsTest extends PHPUnit\Framework\TestCase { ); } + /** + * Test, if for all rights an action- message exist, + * which is used on Special:ListGroupRights as help text + * Extensions and core + * + * @coversNothing + */ + public function testAllActionsWithMessages() { + $this->checkMessagesExist( 'action-' ); + } + /** * Test, if for all rights a right- message exist, * which is used on Special:ListGroupRights as help text @@ -62,27 +73,34 @@ class AvailableRightsTest extends PHPUnit\Framework\TestCase { * @coversNothing */ public function testAllRightsWithMessage() { + $this->checkMessagesExist( 'right-' ); + } + + /** + * @param string $prefix + */ + private function checkMessagesExist( $prefix ) { // Getting all user rights, for core: User::$mCoreRights, for extensions: $wgAvailableRights $allRights = User::getAllRights(); $allMessageKeys = Language::getMessageKeysFor( 'en' ); - $rightsWithMessage = []; + $messagesToCheck = []; foreach ( $allMessageKeys as $message ) { // === 0: must be at beginning of string (position 0) - if ( strpos( $message, 'right-' ) === 0 ) { - $rightsWithMessage[] = substr( $message, strlen( 'right-' ) ); + if ( strpos( $message, $prefix ) === 0 ) { + $messagesToCheck[] = substr( $message, strlen( $prefix ) ); } } $missing = array_diff( $allRights, - $rightsWithMessage + $messagesToCheck ); $this->assertEquals( [], $missing, - 'Each user rights (core/extensions) has a corresponding right- message.' + "Each user right (core/extensions) has a corresponding $prefix message." ); } } -- 2.20.1