Services: Convert PermissionManager's static to a const now HHVM is gone
[lhc/web/wiklou.git] / tests / phpunit / includes / Permissions / PermissionManagerTest.php
index 44b7f67..683e89d 100644 (file)
@@ -122,8 +122,6 @@ class PermissionManagerTest extends MediaWikiLangTestCase {
 
                        $this->user = $this->userUser;
                }
-
-               $this->resetServices();
        }
 
        public function tearDown() {
@@ -143,7 +141,6 @@ class PermissionManagerTest extends MediaWikiLangTestCase {
                } else {
                        $this->user = $this->altUser;
                }
-               $this->resetServices();
        }
 
        /**
@@ -421,8 +418,7 @@ class PermissionManagerTest extends MediaWikiLangTestCase {
 
                        global $wgGroupPermissions;
                        $old = $wgGroupPermissions;
-                       $wgGroupPermissions = [];
-                       $this->resetServices();
+                       $this->setMwGlobals( 'wgGroupPermissions', [] );
 
                        $this->assertEquals( $check[$action][1],
                                MediaWikiServices::getInstance()->getPermissionManager()
@@ -433,8 +429,7 @@ class PermissionManagerTest extends MediaWikiLangTestCase {
                        $this->assertEquals( $check[$action][1],
                                MediaWikiServices::getInstance()->getPermissionManager()
                                        ->getPermissionErrors( $action, $this->user, $this->title, 'secure' ) );
-                       $wgGroupPermissions = $old;
-                       $this->resetServices();
+                       $this->setMwGlobals( 'wgGroupPermissions', $old );
 
                        $this->overrideUserPermissions( $this->user, $action );
                        $this->assertEquals( $check[$action][2],
@@ -453,46 +448,39 @@ class PermissionManagerTest extends MediaWikiLangTestCase {
                                        ->userCan( $action, $this->user, $this->title, true ) );
                        $this->assertEquals( $check[$action][3],
                                MediaWikiServices::getInstance()->getPermissionManager()
-                                       ->userCan( $action, $this->user, $this->title,
-                                       PermissionManager::RIGOR_QUICK ) );
+                                       ->quickUserCan( $action, $this->user, $this->title ) );
                        # count( User::getGroupsWithPermissions( $action ) ) < 1
                }
        }
 
        protected function runGroupPermissions( $perm, $action, $result, $result2 = null ) {
-               global $wgGroupPermissions;
-
                if ( $result2 === null ) {
                        $result2 = $result;
                }
 
-               $wgGroupPermissions['autoconfirmed']['move'] = false;
-               $wgGroupPermissions['user']['move'] = false;
-               $this->resetServices();
+               $this->setGroupPermissions( 'autoconfirmed', 'move', false );
+               $this->setGroupPermissions( 'user', 'move', false );
                $this->overrideUserPermissions( $this->user, $perm );
                $res = MediaWikiServices::getInstance()->getPermissionManager()
                        ->getPermissionErrors( $action, $this->user, $this->title );
                $this->assertEquals( $result, $res );
 
-               $wgGroupPermissions['autoconfirmed']['move'] = true;
-               $wgGroupPermissions['user']['move'] = false;
-               $this->resetServices();
+               $this->setGroupPermissions( 'autoconfirmed', 'move', true );
+               $this->setGroupPermissions( 'user', 'move', false );
                $this->overrideUserPermissions( $this->user, $perm );
                $res = MediaWikiServices::getInstance()->getPermissionManager()
                        ->getPermissionErrors( $action, $this->user, $this->title );
                $this->assertEquals( $result2, $res );
 
-               $wgGroupPermissions['autoconfirmed']['move'] = true;
-               $wgGroupPermissions['user']['move'] = true;
-               $this->resetServices();
+               $this->setGroupPermissions( 'autoconfirmed', 'move', true );
+               $this->setGroupPermissions( 'user', 'move', true );
                $this->overrideUserPermissions( $this->user, $perm );
                $res = MediaWikiServices::getInstance()->getPermissionManager()
                        ->getPermissionErrors( $action, $this->user, $this->title );
                $this->assertEquals( $result2, $res );
 
-               $wgGroupPermissions['autoconfirmed']['move'] = false;
-               $wgGroupPermissions['user']['move'] = true;
-               $this->resetServices();
+               $this->setGroupPermissions( 'autoconfirmed', 'move', false );
+               $this->setGroupPermissions( 'user', 'move', true );
                $this->overrideUserPermissions( $this->user, $perm );
                $res = MediaWikiServices::getInstance()->getPermissionManager()
                        ->getPermissionErrors( $action, $this->user, $this->title );
@@ -734,7 +722,7 @@ class PermissionManagerTest extends MediaWikiLangTestCase {
                $permissionManager = new PermissionManager(
                        new LoggedServiceOptions(
                                self::$serviceOptionsAccessLog,
-                               PermissionManager::$constructorOptions,
+                               PermissionManager::CONSTRUCTOR_OPTIONS,
                                [
                                        'WhitelistRead' => [],
                                        'WhitelistReadRegexp' => [],
@@ -899,7 +887,7 @@ class PermissionManagerTest extends MediaWikiLangTestCase {
 
                $this->assertEquals( true,
                        MediaWikiServices::getInstance()->getPermissionManager()
-                               ->userCan( 'edit', $this->user, $this->title, PermissionManager::RIGOR_QUICK ) );
+                               ->quickUserCan( 'edit', $this->user, $this->title ) );
 
                $this->title->mRestrictions = [ "edit" => [ 'bogus', "sysop", "protect", "" ],
                        "bogus" => [ 'bogus', "sysop", "protect", "" ] ];
@@ -945,11 +933,11 @@ class PermissionManagerTest extends MediaWikiLangTestCase {
 
                $this->assertEquals( false,
                        MediaWikiServices::getInstance()->getPermissionManager()
-                               ->userCan( 'bogus', $this->user, $this->title, PermissionManager::RIGOR_QUICK ) );
+                               ->quickUserCan( 'bogus', $this->user, $this->title ) );
 
                $this->assertEquals( false,
-                       MediaWikiServices::getInstance()->getPermissionManager()->userCan(
-                               'edit', $this->user, $this->title, PermissionManager::RIGOR_QUICK ) );
+                       MediaWikiServices::getInstance()->getPermissionManager()->quickUserCan(
+                               'edit', $this->user, $this->title ) );
 
                $this->assertEquals( [ [ 'badaccess-group0' ],
                        [ 'protectedpagetext', 'bogus', 'bogus' ],
@@ -965,12 +953,12 @@ class PermissionManagerTest extends MediaWikiLangTestCase {
 
                $this->overrideUserPermissions( $this->user, [ "edit", "editprotected" ] );
                $this->assertEquals( false,
-                       MediaWikiServices::getInstance()->getPermissionManager()->userCan(
-                               'bogus', $this->user, $this->title, PermissionManager::RIGOR_QUICK ) );
+                       MediaWikiServices::getInstance()->getPermissionManager()->quickUserCan(
+                               'bogus', $this->user, $this->title ) );
 
                $this->assertEquals( false,
-                       MediaWikiServices::getInstance()->getPermissionManager()->userCan(
-                               'edit', $this->user, $this->title, PermissionManager::RIGOR_QUICK ) );
+                       MediaWikiServices::getInstance()->getPermissionManager()->quickUserCan(
+                               'edit', $this->user, $this->title ) );
 
                $this->assertEquals( [ [ 'badaccess-group0' ],
                        [ 'protectedpagetext', 'bogus', 'bogus' ],
@@ -1144,7 +1132,6 @@ class PermissionManagerTest extends MediaWikiLangTestCase {
                                ->getPermissionErrors( 'edit', $this->user, $this->title ) );
 
                $this->setMwGlobals( 'wgEmailConfirmToEdit', false );
-               $this->resetServices();
                $this->overrideUserPermissions( $this->user, [
                        'createpage',
                        'edit',
@@ -1188,8 +1175,7 @@ class PermissionManagerTest extends MediaWikiLangTestCase {
                        ->userCan( 'move-target', $this->user, $this->title ) );
                // quickUserCan should ignore user blocks
                $this->assertEquals( true, MediaWikiServices::getInstance()->getPermissionManager()
-                       ->userCan( 'move-target', $this->user, $this->title,
-                               PermissionManager::RIGOR_QUICK ) );
+                       ->quickUserCan( 'move-target', $this->user, $this->title ) );
 
                global $wgLocalTZoffset;
                $wgLocalTZoffset = -60;
@@ -1577,7 +1563,6 @@ class PermissionManagerTest extends MediaWikiLangTestCase {
                        $rights = array_diff( $rights, [ 'writetest' ] );
                } );
 
-               $this->resetServices();
                $rights = MediaWikiServices::getInstance()
                        ->getPermissionManager()
                        ->getUserPermissions( $user );
@@ -1859,13 +1844,28 @@ class PermissionManagerTest extends MediaWikiLangTestCase {
                        'wgRestrictionLevels' => [ '', 'autoconfirmed', 'sysop' ],
                        'wgAutopromote' => []
                ] );
-               $this->resetServices();
                $user = is_null( $userGroups ) ? null : $this->getTestUser( $userGroups )->getUser();
                $this->assertSame( $expected, MediaWikiServices::getInstance()
                        ->getPermissionManager()
                        ->getNamespaceRestrictionLevels( $ns, $user ) );
        }
 
+       /**
+        * @covers \MediaWiki\Permissions\PermissionManager::getAllPermissions
+        */
+       public function testGetAllPermissions() {
+               $this->setMwGlobals( [
+                       'wgAvailableRights' => [ 'test_right' ]
+               ] );
+               $this->resetServices();
+               $this->assertContains(
+                       'test_right',
+                       MediaWikiServices::getInstance()
+                               ->getPermissionManager()
+                               ->getAllPermissions()
+               );
+       }
+
        /**
         * @covers \MediaWiki\Permissions\PermissionManager::getRightsCacheKey
         * @throws \Exception