Fix some issues with HTMLSelectAndOtherField default and validation
[lhc/web/wiklou.git] / tests / phpunit / MediaWikiTestCase.php
index 1e70c57..f9416be 100644 (file)
@@ -817,29 +817,6 @@ abstract class MediaWikiTestCase extends PHPUnit\Framework\TestCase {
                return false;
        }
 
-       /**
-        * Stashes the global, will be restored in tearDown()
-        *
-        * Individual test functions may override globals through the setMwGlobals() function
-        * or directly. When directly overriding globals their keys should first be passed to this
-        * method in setUp to avoid breaking global state for other tests
-        *
-        * That way all other tests are executed with the same settings (instead of using the
-        * unreliable local settings for most tests and fix it only for some tests).
-        *
-        * @param array|string $globalKeys Key to the global variable, or an array of keys.
-        *
-        * @note To allow changes to global variables to take effect on global service instances,
-        *       call overrideMwServices().
-        *
-        * @since 1.23
-        * @deprecated since 1.32, use setMwGlobals() and don't alter globals directly
-        */
-       protected function stashMwGlobals( $globalKeys ) {
-               wfDeprecated( __METHOD__, '1.32' );
-               $this->doStashMwGlobals( $globalKeys );
-       }
-
        private function doStashMwGlobals( $globalKeys ) {
                if ( is_string( $globalKeys ) ) {
                        $globalKeys = [ $globalKeys ];
@@ -977,6 +954,8 @@ abstract class MediaWikiTestCase extends PHPUnit\Framework\TestCase {
                        $newInstance->redefineService( $name, $callback );
                }
 
+               self::resetGlobalParser();
+
                return $newInstance;
        }
 
@@ -1041,6 +1020,9 @@ abstract class MediaWikiTestCase extends PHPUnit\Framework\TestCase {
                );
 
                MediaWikiServices::forceGlobalInstance( $newServices );
+
+               self::resetGlobalParser();
+
                return $newServices;
        }
 
@@ -1069,9 +1051,26 @@ abstract class MediaWikiTestCase extends PHPUnit\Framework\TestCase {
                MediaWikiServices::forceGlobalInstance( self::$originalServices );
                $currentServices->destroy();
 
+               self::resetGlobalParser();
+
                return true;
        }
 
+       /**
+        * If $wgParser has been unstubbed, replace it with a fresh one so it picks up any config
+        * changes. $wgParser is deprecated, but we still support it for now.
+        */
+       private static function resetGlobalParser() {
+               // phpcs:ignore MediaWiki.Usage.DeprecatedGlobalVariables.Deprecated$wgParser
+               global $wgParser;
+               if ( $wgParser instanceof StubObject ) {
+                       return;
+               }
+               $wgParser = new StubObject( 'wgParser', function () {
+                       return MediaWikiServices::getInstance()->getParser();
+               } );
+       }
+
        /**
         * @since 1.27
         * @param string|Language $lang
@@ -2367,7 +2366,7 @@ abstract class MediaWikiTestCase extends PHPUnit\Framework\TestCase {
                if ( $createIfMissing ) {
                        if ( !file_exists( $fileName ) ) {
                                file_put_contents( $fileName, $actualData );
-                               $this->markTestSkipped( 'Data file $fileName does not exist' );
+                               $this->markTestSkipped( "Data file $fileName does not exist" );
                        }
                } else {
                        self::assertFileExists( $fileName );
@@ -2381,13 +2380,20 @@ abstract class MediaWikiTestCase extends PHPUnit\Framework\TestCase {
         * @param string $text Content of the page
         * @param string $summary Optional summary string for the revision
         * @param int $defaultNs Optional namespace id
+        * @param User|null $user If null, static::getTestSysop()->getUser() is used.
         * @return Status Object as returned by WikiPage::doEditContent()
         * @throws MWException If this test cases's needsDB() method doesn't return true.
         *         Test cases can use "@group Database" to enable database test support,
         *         or list the tables under testing in $this->tablesUsed, or override the
         *         needsDB() method.
         */
-       protected function editPage( $pageName, $text, $summary = '', $defaultNs = NS_MAIN ) {
+       protected function editPage(
+               $pageName,
+               $text,
+               $summary = '',
+               $defaultNs = NS_MAIN,
+               User $user = null
+       ) {
                if ( !$this->needsDB() ) {
                        throw new MWException( 'When testing which pages, the test cases\'s needsDB()' .
                                ' method should return true. Use @group Database or $this->tablesUsed.' );
@@ -2396,7 +2402,13 @@ abstract class MediaWikiTestCase extends PHPUnit\Framework\TestCase {
                $title = Title::newFromText( $pageName, $defaultNs );
                $page = WikiPage::factory( $title );
 
-               return $page->doEditContent( ContentHandler::makeContent( $text, $title ), $summary );
+               return $page->doEditContent(
+                       ContentHandler::makeContent( $text, $title ),
+                       $summary,
+                       0,
+                       false,
+                       $user
+               );
        }
 
        /**