Merge "Fix eslint warnings and switch to error code"
[lhc/web/wiklou.git] / tests / phpunit / includes / TitlePermissionTest.php
index 4e34244..dd84b7e 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 ) {
@@ -96,11 +99,15 @@ class TitlePermissionTest extends MediaWikiLangTestCase {
        /**
         * @todo This test method should be split up into separate test methods and
         * data providers
+        *
+        * This test is failing per T201776.
+        *
+        * @group Broken
         * @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 );
@@ -640,12 +647,15 @@ class TitlePermissionTest extends MediaWikiLangTestCase {
        /**
         * @todo This test method should be split up into separate test methods and
         * data providers
+        *
+        * This test is failing per T201776.
+        *
+        * @group Broken
         * @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;
@@ -842,18 +852,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( [],