diff options
author | Yaco <franco@reevo.org> | 2020-06-04 11:01:00 -0300 |
---|---|---|
committer | Yaco <franco@reevo.org> | 2020-06-04 11:01:00 -0300 |
commit | fc7369835258467bf97eb64f184b93691f9a9fd5 (patch) | |
tree | daabd60089d2dd76d9f5fb416b005fbe159c799d /www/wiki/tests/phpunit/structure/AvailableRightsTest.php |
first commit
Diffstat (limited to 'www/wiki/tests/phpunit/structure/AvailableRightsTest.php')
-rw-r--r-- | www/wiki/tests/phpunit/structure/AvailableRightsTest.php | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/www/wiki/tests/phpunit/structure/AvailableRightsTest.php b/www/wiki/tests/phpunit/structure/AvailableRightsTest.php new file mode 100644 index 00000000..6c2ff024 --- /dev/null +++ b/www/wiki/tests/phpunit/structure/AvailableRightsTest.php @@ -0,0 +1,53 @@ +<?php + +/** + * Try to make sure that extensions register all rights in $wgAvailableRights + * or via the 'UserGetAllRights' hook. + * + * @author Marius Hoch < hoo@online.de > + */ +class AvailableRightsTest extends PHPUnit\Framework\TestCase { + + use MediaWikiCoversValidator; + + /** + * 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( + [], + // Re-index to produce nicer output, keys are meaningless. + array_values( $missingRights ), + 'Additional user rights need to be added to $wgAvailableRights or ' . + 'via the "UserGetAllRights" hook. See the instructions at: ' . + 'https://www.mediawiki.org/wiki/Manual:User_rights#Adding_new_rights' + ); + } +} |