Make LocalisationCache a service
[lhc/web/wiklou.git] / tests / phpunit / MediaWikiIntegrationTestCase.php
index b738312..24a601e 100644 (file)
@@ -407,6 +407,7 @@ abstract class MediaWikiIntegrationTestCase extends PHPUnit\Framework\TestCase {
 
                $wgRequest = new FauxRequest();
                MediaWiki\Session\SessionManager::resetCache();
+               Language::clearCaches();
        }
 
        public function run( PHPUnit_Framework_TestResult $result = null ) {
@@ -1465,7 +1466,7 @@ abstract class MediaWikiIntegrationTestCase extends PHPUnit\Framework\TestCase {
                        $db->_originalTablePrefix = $oldPrefix;
 
                        $lb = MediaWikiServices::getInstance()->getDBLoadBalancer();
-                       $lb->setTempTablesOnlyMode( self::$useTemporaryTables, $lb->getLocalDomainID() );
+                       $lb->setTempTablesOnlyMode( self::$useTemporaryTables, $db->getDomainID() );
                }
 
                return true;
@@ -1821,22 +1822,30 @@ abstract class MediaWikiIntegrationTestCase extends PHPUnit\Framework\TestCase {
        /**
         * Empty all tables so they can be repopulated for tests
         *
-        * @param Database $db|null Database to reset
-        * @param array $tablesUsed Tables to reset
+        * @param IDatabase $db|null Database to reset
+        * @param string[] $tablesUsed Tables to reset
         */
-       private function resetDB( $db, $tablesUsed ) {
+       private function resetDB( IDatabase $db = null, array $tablesUsed ) {
                if ( $db ) {
-                       $userTables = [ 'user', 'user_groups', 'user_properties', 'actor' ];
-                       $pageTables = [
-                               'page', 'revision', 'ip_changes', 'revision_comment_temp', 'comment', 'archive',
-                               'revision_actor_temp', 'slots', 'content', 'content_models', 'slot_roles',
-                               'change_tag',
+                       // some groups of tables are connected such that if any is used, all should be cleared
+                       $extraTables = [
+                               'user' => [ 'user', 'user_groups', 'user_properties', 'actor' ],
+                               'page' => [ 'page', 'revision', 'ip_changes', 'revision_comment_temp', 'comment', 'archive',
+                                       'revision_actor_temp', 'slots', 'content', 'content_models', 'slot_roles',
+                                       'change_tag' ],
+                               'logging' => [ 'logging', 'log_search', 'change_tag' ],
                        ];
-                       $coreDBDataTables = array_merge( $userTables, $pageTables );
+                       $coreDBDataTables = array_merge( $extraTables['user'], $extraTables['page'] );
+
+                       foreach ( $extraTables as $i => $group ) {
+                               if ( !array_intersect( $tablesUsed, $group ) ) {
+                                       unset( $extraTables[$i] );
+                               }
+                       }
+                       $extraTables = array_values( $extraTables );
+                       $tablesUsed = array_unique( array_merge( $tablesUsed, ...$extraTables ) );
 
-                       // If any of the user or page tables were marked as used, we should clear all of them.
-                       if ( array_intersect( $tablesUsed, $userTables ) ) {
-                               $tablesUsed = array_unique( array_merge( $tablesUsed, $userTables ) );
+                       if ( in_array( 'user', $tablesUsed ) ) {
                                TestUserRegistry::clear();
 
                                // Reset $wgUser, which is probably 127.0.0.1, as its loaded data is probably not valid
@@ -1845,9 +1854,6 @@ abstract class MediaWikiIntegrationTestCase extends PHPUnit\Framework\TestCase {
                                global $wgUser;
                                $wgUser->clearInstanceCache( $wgUser->mFrom );
                        }
-                       if ( array_intersect( $tablesUsed, $pageTables ) ) {
-                               $tablesUsed = array_unique( array_merge( $tablesUsed, $pageTables ) );
-                       }
 
                        // Postgres uses mwuser/pagecontent
                        // instead of user/text. But Postgres does not remap the
@@ -2382,32 +2388,6 @@ abstract class MediaWikiIntegrationTestCase extends PHPUnit\Framework\TestCase {
                $this->mergeMwGlobalArrayValue( 'wgHooks', [ $hookName => [ $handler ] ] );
        }
 
-       /**
-        * Check whether file contains given data.
-        * @param string $fileName
-        * @param string $actualData
-        * @param bool $createIfMissing If true, and file does not exist, create it with given data
-        *                              and skip the test.
-        * @param string $msg
-        * @since 1.30
-        */
-       protected function assertFileContains(
-               $fileName,
-               $actualData,
-               $createIfMissing = false,
-               $msg = ''
-       ) {
-               if ( $createIfMissing ) {
-                       if ( !file_exists( $fileName ) ) {
-                               file_put_contents( $fileName, $actualData );
-                               $this->markTestSkipped( "Data file $fileName does not exist" );
-                       }
-               } else {
-                       self::assertFileExists( $fileName );
-               }
-               self::assertEquals( file_get_contents( $fileName ), $actualData, $msg );
-       }
-
        /**
         * Edits or creates a page/revision
         * @param string $pageName Page title