Call overrideMwServices() in TitlePermissionTest
[lhc/web/wiklou.git] / tests / phpunit / includes / TitlePermissionTest.php
index 7dfb735..63803cc 100644 (file)
@@ -1,5 +1,7 @@
 <?php
 
+use MediaWiki\MediaWikiServices;
+
 /**
  * @group Database
  *
@@ -67,6 +69,7 @@ class TitlePermissionTest extends MediaWikiLangTestCase {
 
                        $this->user = $this->userUser;
                }
+               $this->overrideMwServices();
        }
 
        protected function setUserPerm( $perm ) {
@@ -99,8 +102,8 @@ class TitlePermissionTest extends MediaWikiLangTestCase {
         * @covers Title::checkQuickPermissions
         */
        public function testQuickPermissions() {
-               global $wgContLang;
-               $prefix = $wgContLang->getFormattedNsText( NS_PROJECT );
+               $prefix = MediaWikiServices::getInstance()->getContentLanguage()->
+                       getFormattedNsText( NS_PROJECT );
 
                $this->setUser( 'anon' );
                $this->setTitle( NS_TALK );
@@ -453,14 +456,38 @@ class TitlePermissionTest extends MediaWikiLangTestCase {
                $this->runConfigEditPermissions(
                        [ [ 'badaccess-group0' ], [ 'mycustomjsprotected', 'bogus' ] ],
 
+                       [ [ 'badaccess-group0' ], [ 'mycustomjsprotected', 'bogus' ] ],
                        [ [ 'badaccess-group0' ], [ 'mycustomjsprotected', 'bogus' ] ],
                        [ [ 'badaccess-group0' ] ],
 
+                       [ [ 'badaccess-group0' ], [ 'mycustomjsprotected', 'bogus' ] ],
                        [ [ 'badaccess-group0' ], [ 'mycustomjsprotected', 'bogus' ] ],
                        [ [ 'badaccess-group0' ] ]
                );
        }
 
+       /**
+        * @todo This test method should be split up into separate test methods and
+        * data providers
+        * @covers Title::checkUserConfigPermissions
+        */
+       public function testJsonConfigEditPermissions() {
+               $this->setUser( $this->userName );
+
+               $this->setTitle( NS_USER, $this->userName . '/test.json' );
+               $this->runConfigEditPermissions(
+                       [ [ 'badaccess-group0' ], [ 'mycustomjsonprotected', 'bogus' ] ],
+
+                       [ [ 'badaccess-group0' ], [ 'mycustomjsonprotected', 'bogus' ] ],
+                       [ [ 'badaccess-group0' ] ],
+                       [ [ 'badaccess-group0' ], [ 'mycustomjsonprotected', 'bogus' ] ],
+
+                       [ [ 'badaccess-group0' ], [ 'mycustomjsonprotected', 'bogus' ] ],
+                       [ [ 'badaccess-group0' ] ],
+                       [ [ 'badaccess-group0' ], [ 'mycustomjsonprotected', 'bogus' ] ]
+               );
+       }
+
        /**
         * @todo This test method should be split up into separate test methods and
         * data providers
@@ -475,8 +502,10 @@ class TitlePermissionTest extends MediaWikiLangTestCase {
 
                        [ [ 'badaccess-group0' ] ],
                        [ [ 'badaccess-group0' ], [ 'mycustomcssprotected', 'bogus' ] ],
+                       [ [ 'badaccess-group0' ], [ 'mycustomcssprotected', 'bogus' ] ],
 
                        [ [ 'badaccess-group0' ] ],
+                       [ [ 'badaccess-group0' ], [ 'mycustomcssprotected', 'bogus' ] ],
                        [ [ 'badaccess-group0' ], [ 'mycustomcssprotected', 'bogus' ] ]
                );
        }
@@ -493,14 +522,38 @@ class TitlePermissionTest extends MediaWikiLangTestCase {
                $this->runConfigEditPermissions(
                        [ [ 'badaccess-group0' ], [ 'customjsprotected', 'bogus' ] ],
 
+                       [ [ 'badaccess-group0' ], [ 'customjsprotected', 'bogus' ] ],
                        [ [ 'badaccess-group0' ], [ 'customjsprotected', 'bogus' ] ],
                        [ [ 'badaccess-group0' ], [ 'customjsprotected', 'bogus' ] ],
 
+                       [ [ 'badaccess-group0' ], [ 'customjsprotected', 'bogus' ] ],
                        [ [ 'badaccess-group0' ], [ 'customjsprotected', 'bogus' ] ],
                        [ [ 'badaccess-group0' ] ]
                );
        }
 
+       /**
+        * @todo This test method should be split up into separate test methods and
+        * data providers
+        * @covers Title::checkUserConfigPermissions
+        */
+       public function testOtherJsonConfigEditPermissions() {
+               $this->setUser( $this->userName );
+
+               $this->setTitle( NS_USER, $this->altUserName . '/test.json' );
+               $this->runConfigEditPermissions(
+                       [ [ 'badaccess-group0' ], [ 'customjsonprotected', 'bogus' ] ],
+
+                       [ [ 'badaccess-group0' ], [ 'customjsonprotected', 'bogus' ] ],
+                       [ [ 'badaccess-group0' ], [ 'customjsonprotected', 'bogus' ] ],
+                       [ [ 'badaccess-group0' ], [ 'customjsonprotected', 'bogus' ] ],
+
+                       [ [ 'badaccess-group0' ], [ 'customjsonprotected', 'bogus' ] ],
+                       [ [ 'badaccess-group0' ] ],
+                       [ [ 'badaccess-group0' ], [ 'customjsonprotected', 'bogus' ] ]
+               );
+       }
+
        /**
         * @todo This test method should be split up into separate test methods and
         * data providers
@@ -513,10 +566,12 @@ class TitlePermissionTest extends MediaWikiLangTestCase {
                $this->runConfigEditPermissions(
                        [ [ 'badaccess-group0' ], [ 'customcssprotected', 'bogus' ] ],
 
+                       [ [ 'badaccess-group0' ], [ 'customcssprotected', 'bogus' ] ],
                        [ [ 'badaccess-group0' ], [ 'customcssprotected', 'bogus' ] ],
                        [ [ 'badaccess-group0' ], [ 'customcssprotected', 'bogus' ] ],
 
                        [ [ 'badaccess-group0' ] ],
+                       [ [ 'badaccess-group0' ], [ 'customcssprotected', 'bogus' ] ],
                        [ [ 'badaccess-group0' ], [ 'customcssprotected', 'bogus' ] ]
                );
        }
@@ -533,9 +588,11 @@ class TitlePermissionTest extends MediaWikiLangTestCase {
                $this->runConfigEditPermissions(
                        [ [ 'badaccess-group0' ] ],
 
+                       [ [ 'badaccess-group0' ] ],
                        [ [ 'badaccess-group0' ] ],
                        [ [ 'badaccess-group0' ] ],
 
+                       [ [ 'badaccess-group0' ] ],
                        [ [ 'badaccess-group0' ] ],
                        [ [ 'badaccess-group0' ] ]
                );
@@ -544,8 +601,10 @@ class TitlePermissionTest extends MediaWikiLangTestCase {
        protected function runConfigEditPermissions(
                $resultNone,
                $resultMyCss,
+               $resultMyJson,
                $resultMyJs,
                $resultUserCss,
+               $resultUserJson,
                $resultUserJs
        ) {
                $this->setUserPerm( '' );
@@ -556,6 +615,10 @@ class TitlePermissionTest extends MediaWikiLangTestCase {
                $result = $this->title->getUserPermissionsErrors( 'bogus', $this->user );
                $this->assertEquals( $resultMyCss, $result );
 
+               $this->setUserPerm( 'editmyuserjson' );
+               $result = $this->title->getUserPermissionsErrors( 'bogus', $this->user );
+               $this->assertEquals( $resultMyJson, $result );
+
                $this->setUserPerm( 'editmyuserjs' );
                $result = $this->title->getUserPermissionsErrors( 'bogus', $this->user );
                $this->assertEquals( $resultMyJs, $result );
@@ -564,11 +627,15 @@ class TitlePermissionTest extends MediaWikiLangTestCase {
                $result = $this->title->getUserPermissionsErrors( 'bogus', $this->user );
                $this->assertEquals( $resultUserCss, $result );
 
+               $this->setUserPerm( 'edituserjson' );
+               $result = $this->title->getUserPermissionsErrors( 'bogus', $this->user );
+               $this->assertEquals( $resultUserJson, $result );
+
                $this->setUserPerm( 'edituserjs' );
                $result = $this->title->getUserPermissionsErrors( 'bogus', $this->user );
                $this->assertEquals( $resultUserJs, $result );
 
-               $this->setUserPerm( [ 'edituserjs', 'editusercss' ] );
+               $this->setUserPerm( [ 'edituserjs', 'edituserjson', 'editusercss' ] );
                $result = $this->title->getUserPermissionsErrors( 'bogus', $this->user );
                $this->assertEquals( [ [ 'badaccess-group0' ] ], $result );
        }
@@ -579,9 +646,8 @@ class TitlePermissionTest extends MediaWikiLangTestCase {
         * @covers Title::checkPageRestrictions
         */
        public function testPageRestrictions() {
-               global $wgContLang;
-
-               $prefix = $wgContLang->getFormattedNsText( NS_PROJECT );
+               $prefix = MediaWikiServices::getInstance()->getContentLanguage()->
+                       getFormattedNsText( NS_PROJECT );
 
                $this->setTitle( NS_MAIN );
                $this->title->mRestrictionsLoaded = true;
@@ -778,18 +844,23 @@ class TitlePermissionTest extends MediaWikiLangTestCase {
         * @covers Title::checkUserBlock
         */
        public function testUserBlock() {
-               global $wgEmailConfirmToEdit, $wgEmailAuthentication;
-               $wgEmailConfirmToEdit = true;
-               $wgEmailAuthentication = true;
+               $this->setMwGlobals( [
+                       'wgEmailConfirmToEdit' => true,
+                       'wgEmailAuthentication' => true,
+               ] );
 
                $this->setUserPerm( [ "createpage", "move" ] );
                $this->setTitle( NS_HELP, "test page" );
 
-               # $short
-               $this->assertEquals( [ [ 'confirmedittext' ] ],
+               # $wgEmailConfirmToEdit only applies to 'edit' action
+               $this->assertEquals( [],
                        $this->title->getUserPermissionsErrors( 'move-target', $this->user ) );
-               $wgEmailConfirmToEdit = false;
-               $this->assertEquals( true, $this->title->userCan( 'move-target', $this->user ) );
+               $this->assertContains( [ 'confirmedittext' ],
+                       $this->title->getUserPermissionsErrors( 'edit', $this->user ) );
+
+               $this->setMwGlobals( 'wgEmailConfirmToEdit', false );
+               $this->assertNotContains( [ 'confirmedittext' ],
+                       $this->title->getUserPermissionsErrors( 'edit', $this->user ) );
 
                # $wgEmailConfirmToEdit && !$user->isEmailConfirmed() && $action != 'createaccount'
                $this->assertEquals( [],