jenkins-bot has submitted this change and it was merged.

Change subject: Add AvailableRightsTest for User::getAllRights completeness
......................................................................


Add AvailableRightsTest for User::getAllRights completeness

Because extensions often don't add their rights to $wgAvailableRights
or via the 'UserGetAllRights' hook, thus User::getAllRights is incomplete.

Change-Id: Id9ae9eff71e822ec5c038c1c1f990ac36f05cea8
---
M includes/User.php
A tests/phpunit/structure/AvailableRightsTest.php
2 files changed, 46 insertions(+), 1 deletion(-)

Approvals:
  Aude: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/User.php b/includes/User.php
index c2db67a..961c510 100644
--- a/includes/User.php
+++ b/includes/User.php
@@ -4399,7 +4399,7 @@
 
        /**
         * Get a list of all available permissions.
-        * @return array Array of permission names
+        * @return string[] Array of permission names
         */
        public static function getAllRights() {
                if ( self::$mAllRights === false ) {
diff --git a/tests/phpunit/structure/AvailableRightsTest.php 
b/tests/phpunit/structure/AvailableRightsTest.php
new file mode 100644
index 0000000..9737e82
--- /dev/null
+++ b/tests/phpunit/structure/AvailableRightsTest.php
@@ -0,0 +1,45 @@
+<?php
+
+/**
+ * Try to make sure that extensions register all rights in $wgAvailableRights
+ * or via the 'UserGetAllRights' hook.
+ *
+ * @author Marius Hoch < [email protected] >
+ */
+class AvailableRightsTest extends PHPUnit_Framework_TestCase {
+
+       /**
+        * Returns all rights that should be in $wgAvailableRights + all rights
+        * registered via the 'UserGetAllRights' hook + all "core" rights.
+        *
+        * @return string[]
+        */
+       private function getAllVisibleRights() {
+               global $wgGroupPermissions, $wgRevokePermissions;
+
+               $rights = User::getAllRights();
+
+               foreach( $wgGroupPermissions as $permissions ) {
+                       $rights = array_merge( $rights, array_keys( 
$permissions ) );
+               }
+
+               foreach( $wgRevokePermissions as $permissions ) {
+                       $rights = array_merge( $rights, array_keys( 
$permissions ) );
+               }
+
+               $rights = array_unique( $rights );
+               sort( $rights );
+
+               return $rights;
+       }
+
+       public function testAvailableRights() {
+               $missingRights = array_diff( $this->getAllVisibleRights(), 
User::getAllRights() );
+
+               $this->assertEquals(
+                       array(),
+                       array_values( $missingRights ), // Re-Index to produce 
nicer output, keys are meaningless
+                       'Additional user rights need to be added to 
$wgAvailableRights or via the "UserGetAllRights" hook'
+               );
+       }
+}

-- 
To view, visit https://gerrit.wikimedia.org/r/189607
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Id9ae9eff71e822ec5c038c1c1f990ac36f05cea8
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Hoo man <[email protected]>
Gerrit-Reviewer: Addshore <[email protected]>
Gerrit-Reviewer: Aude <[email protected]>
Gerrit-Reviewer: Hoo man <[email protected]>
Gerrit-Reviewer: Legoktm <[email protected]>
Gerrit-Reviewer: Thiemo Mättig (WMDE) <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to