4 * Try to make sure that extensions register all rights in $wgAvailableRights
5 * or via the 'UserGetAllRights' hook.
7 * @author Marius Hoch < hoo@online.de >
9 class AvailableRightsTest
extends PHPUnit\Framework\TestCase
{
11 use MediaWikiCoversValidator
;
14 * Returns all rights that should be in $wgAvailableRights + all rights
15 * registered via the 'UserGetAllRights' hook + all "core" rights.
19 private function getAllVisibleRights() {
20 global $wgGroupPermissions, $wgRevokePermissions;
22 $rights = User
::getAllRights();
24 foreach ( $wgGroupPermissions as $permissions ) {
25 $rights = array_merge( $rights, array_keys( $permissions ) );
28 foreach ( $wgRevokePermissions as $permissions ) {
29 $rights = array_merge( $rights, array_keys( $permissions ) );
32 $rights = array_unique( $rights );
41 public function testAvailableRights() {
42 $missingRights = array_diff(
43 $this->getAllVisibleRights(),
49 // Re-index to produce nicer output, keys are meaningless.
50 array_values( $missingRights ),
51 'Additional user rights need to be added to $wgAvailableRights or ' .
52 'via the "UserGetAllRights" hook. See the instructions at: ' .
53 'https://www.mediawiki.org/wiki/Manual:User_rights#Adding_new_rights'
58 * Test, if for all rights a right- message exist,
59 * which is used on Special:ListGroupRights as help text
64 public function testAllRightsWithMessage() {
65 // Getting all user rights, for core: User::$mCoreRights, for extensions: $wgAvailableRights
66 $allRights = User
::getAllRights();
67 $allMessageKeys = Language
::getMessageKeysFor( 'en' );
69 $rightsWithMessage = [];
70 foreach ( $allMessageKeys as $message ) {
71 // === 0: must be at beginning of string (position 0)
72 if ( strpos( $message, 'right-' ) === 0 ) {
73 $rightsWithMessage[] = substr( $message, strlen( 'right-' ) );
77 $missing = array_diff(
85 'Each user rights (core/extensions) has a corresponding right- message.'