<?php
+use MediaWiki\MediaWikiServices;
+
/**
* Try to make sure that extensions register all rights in $wgAvailableRights
* or via the 'UserGetAllRights' hook.
private function getAllVisibleRights() {
global $wgGroupPermissions, $wgRevokePermissions;
- $rights = User::getAllRights();
+ $rights = MediaWikiServices::getInstance()->getPermissionManager()->getAllPermissions();
foreach ( $wgGroupPermissions as $permissions ) {
$rights = array_merge( $rights, array_keys( $permissions ) );
return $rights;
}
- /**
- * @coversNothing
- */
public function testAvailableRights() {
$missingRights = array_diff(
$this->getAllVisibleRights(),
- User::getAllRights()
+ MediaWikiServices::getInstance()->getPermissionManager()->getAllPermissions()
);
$this->assertEquals(
}
/**
- * Test, if for all rights a right- message exist,
+ * 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
+ * Extensions and core
+ */
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();
+ $allRights = MediaWikiServices::getInstance()->getPermissionManager()->getAllPermissions();
$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."
);
}
}