Made setupGlobals() return the created context and use it instead of either global...
[lhc/web/wiklou.git] / tests / parser / parserTest.inc
index 259fc2f..af0d4bf 100644 (file)
@@ -136,7 +136,8 @@ class ParserTest {
                        $wgUser, $wgLang, $wgOut, $wgRequest, $wgStyleDirectory, $wgEnableParserCache,
                        $wgNamespaceAliases, $wgNamespaceProtection, $wgLocalFileRepo,
                        $parserMemc, $wgThumbnailScriptPath, $wgScriptPath,
-                       $wgArticlePath, $wgStyleSheetPath, $wgScript, $wgStylePath, $wgExtensionAssetsPath;
+                       $wgArticlePath, $wgStyleSheetPath, $wgScript, $wgStylePath, $wgExtensionAssetsPath,
+                       $wgMainCacheType, $wgMessageCacheType, $wgParserCacheType;
 
                $wgScript = '/index.php';
                $wgScriptPath = '/';
@@ -158,10 +159,20 @@ class ParserTest {
                $wgNamespaceAliases['Image'] = NS_FILE;
                $wgNamespaceAliases['Image_talk'] = NS_FILE_TALK;
 
+               // XXX: tests won't run without this (for CACHE_DB)
+               if ( $wgMainCacheType === CACHE_DB ) {
+                       $wgMainCacheType = CACHE_NONE;
+               }
+               if ( $wgMessageCacheType === CACHE_DB ) {
+                       $wgMessageCacheType = CACHE_NONE;
+               }
+               if ( $wgParserCacheType === CACHE_DB ) {
+                       $wgParserCacheType = CACHE_NONE;
+               }
 
                $wgEnableParserCache = false;
                DeferredUpdates::clearPendingUpdates();
-               $wgMemc = wfGetMainCache();
+               $wgMemc = wfGetMainCache(); // checks $wgMainCacheType
                $messageMemc = wfGetMessageCacheStorage();
                $parserMemc = wfGetParserCacheStorage();
 
@@ -424,10 +435,10 @@ class ParserTest {
                }
 
                $opts = $this->parseOptions( $opts );
-               $this->setupGlobals( $opts, $config );
+               $context = $this->setupGlobals( $opts, $config );
 
-               $user = new User();
-               $options = ParserOptions::newFromUser( $user );
+               $user = $context->getUser();
+               $options = ParserOptions::newFromContext( $context );
 
                if ( isset( $opts['title'] ) ) {
                        $titleText = $opts['title'];
@@ -471,10 +482,9 @@ class ParserTest {
                        if ( isset( $opts['ill'] ) ) {
                                $out = $this->tidy( implode( ' ', $output->getLanguageLinks() ) );
                        } elseif ( isset( $opts['cat'] ) ) {
-                               global $wgOut;
-
-                               $wgOut->addCategoryLinks( $output->getCategories() );
-                               $cats = $wgOut->getCategoryLinks();
+                               $outputPage = $context->getOutput();
+                               $outputPage->addCategoryLinks( $output->getCategories() );
+                               $cats = $outputPage->getCategoryLinks();
 
                                if ( isset( $cats['normal'] ) ) {
                                        $out = $this->tidy( implode( ' ', $cats['normal'] ) );
@@ -693,6 +703,8 @@ class ParserTest {
                $wgHooks['ParserGetVariableValueTs'][] = 'ParserTest::getFakeTimestamp';
 
                MagicWord::clearCache();
+
+               return $context;
        }
 
        /**
@@ -857,6 +869,13 @@ class ParserTest {
                $this->databaseSetupDone = false;
 
                if ( $this->useTemporaryTables ) {
+                       if( $this->db->getType() == 'sqlite' ) {
+                               # Under SQLite the searchindex table is virtual and need
+                               # to be explicitly destroyed. See bug 29912
+                               # See also MediaWikiTestCase::destroyDB()
+                               wfDebug( __METHOD__ . " explicitly destroying sqlite virtual table parsertest_searchindex\n" );
+                               $this->db->query( "DROP TABLE `parsertest_searchindex`" );
+                       }
                        # Don't need to do anything
                        $this->teardownGlobals();
                        return;