Avoid using $wgUser in TitlePermissionTest
authorumherirrender <umherirrender_de.wp@web.de>
Wed, 10 Oct 2012 17:18:12 +0000 (19:18 +0200)
committerGerrit Code Review <gerrit@wikimedia.org>
Sun, 14 Oct 2012 19:00:24 +0000 (19:00 +0000)
Change-Id: I2432cd66c11d68213f96ef96f972fc10d9dfa504

tests/phpunit/includes/TitlePermissionTest.php

index f7387e1..55c5610 100644 (file)
@@ -36,7 +36,6 @@ class TitlePermissionTest extends MediaWikiLangTestCase {
                        'wgNamespaceProtection' => array(
                                NS_MEDIAWIKI => 'editinterface',
                        ),
-                       'wgUser' => null,
                ) );
 
                $this->userName = 'Useruser';
@@ -84,8 +83,6 @@ class TitlePermissionTest extends MediaWikiLangTestCase {
        }
 
        function setUser( $userName = null ) {
-               global $wgUser;
-
                if ( $userName === 'anon' ) {
                        $this->user = $this->anonUser;
                } elseif ( $userName === null || $userName === $this->userName ) {
@@ -93,8 +90,6 @@ class TitlePermissionTest extends MediaWikiLangTestCase {
                } else {
                        $this->user = $this->altUser;
                }
-
-               $wgUser = $this->user;
        }
 
        function testQuickPermissions() {
@@ -298,8 +293,7 @@ class TitlePermissionTest extends MediaWikiLangTestCase {
                                                                                        array( array( 'badaccess-group0' ), array( 'protect-cantedit' ) ),
                                                                                        array( array( 'protect-cantedit' ) ), false ),
                                                '' => array( array( ), array( ), array( ), true ) );
-               global $wgUser;
-               $wgUser = $this->user;
+
                foreach ( array( "edit", "protect", "" ) as $action ) {
                        $this->setUserPerm( null );
                        $this->assertEquals( $check[$action][0],
@@ -319,9 +313,9 @@ class TitlePermissionTest extends MediaWikiLangTestCase {
 
                        $this->setUserPerm( $action );
                        $this->assertEquals( $check[$action][3],
-                               $this->title->userCan( $action, true ) );
+                               $this->title->userCan( $action, $this->user, true ) );
                        $this->assertEquals( $check[$action][3],
-                               $this->title->quickUserCan( $action ) );
+                               $this->title->quickUserCan( $action, $this->user ) );
 
                        # count( User::getGroupsWithPermissions( $action ) ) < 1
                }
@@ -397,13 +391,13 @@ class TitlePermissionTest extends MediaWikiLangTestCase {
                $this->assertEquals( array( ),
                                                         $this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
                $this->assertEquals( true,
-                                                        $this->title->userCan( 'bogus' ) );
+                                                        $this->title->userCan( 'bogus', $this->user ) );
 
                $this->setUserPerm( '' );
                $this->assertEquals( array( array( 'badaccess-group0' ) ),
                                                         $this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
                $this->assertEquals( false,
-                                                        $this->title->userCan( 'bogus' ) );
+                                                        $this->title->userCan( 'bogus', $this->user ) );
        }
 
        function testCssAndJavascriptPermissions() {
@@ -456,11 +450,10 @@ class TitlePermissionTest extends MediaWikiLangTestCase {
        }
 
        function testPageRestrictions() {
-               global $wgUser, $wgContLang;
+               global $wgContLang;
 
                $prefix = $wgContLang->getFormattedNsText( NS_PROJECT );
 
-               $wgUser = $this->user;
                $this->setTitle( NS_MAIN );
                $this->title->mRestrictionsLoaded = true;
                $this->setUserPerm( "edit" );
@@ -471,7 +464,7 @@ class TitlePermissionTest extends MediaWikiLangTestCase {
                                                                                                                                         $this->user ) );
 
                $this->assertEquals( true,
-                                                        $this->title->quickUserCan( 'edit' ) );
+                                                        $this->title->quickUserCan( 'edit', $this->user ) );
                $this->title->mRestrictions = array( "edit" => array( 'bogus', "sysop", "protect", "" ),
                                                                                   "bogus" => array( 'bogus', "sysop", "protect", "" ) );
 
@@ -511,9 +504,9 @@ class TitlePermissionTest extends MediaWikiLangTestCase {
                                                                                                                                         $this->user ) );
                $this->title->mCascadeRestriction = true;
                $this->assertEquals( false,
-                                                        $this->title->quickUserCan( 'bogus' ) );
+                                                        $this->title->quickUserCan( 'bogus', $this->user ) );
                $this->assertEquals( false,
-                                                        $this->title->quickUserCan( 'edit' ) );
+                                                        $this->title->quickUserCan( 'edit', $this->user ) );
                $this->assertEquals( array( array( 'badaccess-group0' ),
                                                                        array( 'protectedpagetext', 'bogus' ),
                                                                        array( 'protectedpagetext', 'protect' ),
@@ -528,8 +521,6 @@ class TitlePermissionTest extends MediaWikiLangTestCase {
        }
 
        function testCascadingSourcesRestrictions() {
-               global $wgUser;
-               $wgUser = $this->user;
                $this->setTitle( NS_MAIN, "test page" );
                $this->setUserPerm( array( "edit", "bogus" ) );
 
@@ -537,22 +528,19 @@ class TitlePermissionTest extends MediaWikiLangTestCase {
                $this->title->mCascadingRestrictions = array( "bogus" => array( 'bogus', "sysop", "protect", "" ) );
 
                $this->assertEquals( false,
-                                                        $this->title->userCan( 'bogus' ) );
+                                                        $this->title->userCan( 'bogus', $this->user ) );
                $this->assertEquals( array( array( "cascadeprotected", 2, "* [[:Bogus]]\n* [[:UnBogus]]\n" ),
                                                                        array( "cascadeprotected", 2, "* [[:Bogus]]\n* [[:UnBogus]]\n" ) ),
                                                         $this->title->getUserPermissionsErrors( 'bogus', $this->user ) );
 
                $this->assertEquals( true,
-                                                        $this->title->userCan( 'edit' ) );
+                                                        $this->title->userCan( 'edit', $this->user ) );
                $this->assertEquals( array( ),
                                                         $this->title->getUserPermissionsErrors( 'edit', $this->user ) );
 
        }
 
        function testActionPermissions() {
-               global $wgUser;
-               $wgUser = $this->user;
-
                $this->setUserPerm( array( "createpage" ) );
                $this->setTitle( NS_MAIN, "test page" );
                $this->title->mTitleProtection['pt_create_perm'] = '';
@@ -564,26 +552,26 @@ class TitlePermissionTest extends MediaWikiLangTestCase {
                $this->assertEquals( array( array( 'titleprotected', 'Useruser', 'test' ) ),
                                                         $this->title->getUserPermissionsErrors( 'create', $this->user ) );
                $this->assertEquals( false,
-                                                        $this->title->userCan( 'create' ) );
+                                                        $this->title->userCan( 'create', $this->user ) );
 
                $this->title->mTitleProtection['pt_create_perm'] = 'sysop';
                $this->setUserPerm( array( 'createpage', 'protect' ) );
                $this->assertEquals( array( ),
                                                         $this->title->getUserPermissionsErrors( 'create', $this->user ) );
                $this->assertEquals( true,
-                                                        $this->title->userCan( 'create' ) );
+                                                        $this->title->userCan( 'create', $this->user ) );
 
 
                $this->setUserPerm( array( 'createpage' ) );
                $this->assertEquals( array( array( 'titleprotected', 'Useruser', 'test' ) ),
                                                         $this->title->getUserPermissionsErrors( 'create', $this->user ) );
                $this->assertEquals( false,
-                                                        $this->title->userCan( 'create' ) );
+                                                        $this->title->userCan( 'create', $this->user ) );
 
                $this->setTitle( NS_MEDIA, "test page" );
                $this->setUserPerm( array( "move" ) );
                $this->assertEquals( false,
-                                                        $this->title->userCan( 'move' ) );
+                                                        $this->title->userCan( 'move', $this->user ) );
                $this->assertEquals( array( array( 'immobile-source-namespace', 'Media' ) ),
                                                         $this->title->getUserPermissionsErrors( 'move', $this->user ) );
 
@@ -591,17 +579,17 @@ class TitlePermissionTest extends MediaWikiLangTestCase {
                $this->assertEquals( array( ),
                                                         $this->title->getUserPermissionsErrors( 'move', $this->user ) );
                $this->assertEquals( true,
-                                                        $this->title->userCan( 'move' ) );
+                                                        $this->title->userCan( 'move', $this->user ) );
 
                $this->title->mInterwiki = "no";
                $this->assertEquals( array( array( 'immobile-source-page' ) ),
                                                         $this->title->getUserPermissionsErrors( 'move', $this->user ) );
                $this->assertEquals( false,
-                                                        $this->title->userCan( 'move' ) );
+                                                        $this->title->userCan( 'move', $this->user ) );
 
                $this->setTitle( NS_MEDIA, "test page" );
                $this->assertEquals( false,
-                                                        $this->title->userCan( 'move-target' ) );
+                                                        $this->title->userCan( 'move-target', $this->user ) );
                $this->assertEquals( array( array( 'immobile-target-namespace', 'Media' ) ),
                                                         $this->title->getUserPermissionsErrors( 'move-target', $this->user ) );
 
@@ -609,21 +597,20 @@ class TitlePermissionTest extends MediaWikiLangTestCase {
                $this->assertEquals( array( ),
                                                         $this->title->getUserPermissionsErrors( 'move-target', $this->user ) );
                $this->assertEquals( true,
-                                                        $this->title->userCan( 'move-target' ) );
+                                                        $this->title->userCan( 'move-target', $this->user ) );
 
                $this->title->mInterwiki = "no";
                $this->assertEquals( array( array( 'immobile-target-page' ) ),
                                                         $this->title->getUserPermissionsErrors( 'move-target', $this->user ) );
                $this->assertEquals( false,
-                                                        $this->title->userCan( 'move-target' ) );
+                                                        $this->title->userCan( 'move-target', $this->user ) );
 
        }
 
        function testUserBlock() {
-               global $wgUser, $wgEmailConfirmToEdit, $wgEmailAuthentication;
+               global $wgEmailConfirmToEdit, $wgEmailAuthentication;
                $wgEmailConfirmToEdit = true;
                $wgEmailAuthentication = true;
-               $wgUser = $this->user;
 
                $this->setUserPerm( array( "createpage", "move" ) );
                $this->setTitle( NS_HELP, "test page" );
@@ -632,7 +619,7 @@ class TitlePermissionTest extends MediaWikiLangTestCase {
                $this->assertEquals( array( array( 'confirmedittext' ) ),
                                                         $this->title->getUserPermissionsErrors( 'move-target', $this->user ) );
                $wgEmailConfirmToEdit = false;
-               $this->assertEquals( true, $this->title->userCan( 'move-target' ) );
+               $this->assertEquals( true, $this->title->userCan( 'move-target', $this->user ) );
 
                # $wgEmailConfirmToEdit && !$user->isEmailConfirmed() && $action != 'createaccount'
                $this->assertEquals( array( ),
@@ -653,9 +640,9 @@ class TitlePermissionTest extends MediaWikiLangTestCase {
                        $this->title->getUserPermissionsErrors( 'move-target',
                        $this->user ) );
 
-               $this->assertEquals( false, $this->title->userCan( 'move-target' ) );
+               $this->assertEquals( false, $this->title->userCan( 'move-target', $this->user ) );
                // quickUserCan should ignore user blocks
-               $this->assertEquals( true, $this->title->quickUserCan( 'move-target' ) );
+               $this->assertEquals( true, $this->title->quickUserCan( 'move-target', $this->user ) );
 
                global $wgLocalTZoffset;
                $wgLocalTZoffset = -60;