Revert r108358. It's a good fellow and we like to keep it.
[lhc/web/wiklou.git] / tests / phpunit / includes / parser / NewParserTest.php
index a4da039..e999796 100644 (file)
@@ -32,10 +32,6 @@ class NewParserTest extends MediaWikiTestCase {
 
        protected $file = false;
 
-       /*function __construct($a = null,$b = array(),$c = null ) {
-               parent::__construct($a,$b,$c);
-       }*/
-
        function setUp() {
                global $wgContLang, $wgNamespaceProtection, $wgNamespaceAliases;
                global $wgHooks, $IP;
@@ -60,15 +56,14 @@ class NewParserTest extends MediaWikiTestCase {
                $tmpGlobals['wgStylePath'] = '/skins';
                $tmpGlobals['wgThumbnailScriptPath'] = false;
                $tmpGlobals['wgLocalFileRepo'] = array(
-                       'class' => 'LocalRepo',
-                       'name' => 'local',
-                       'directory' => wfTempDir() . '/test-repo',
-                       'url' => 'http://example.com/images',
-                       'deletedDir' => wfTempDir() . '/test-repo/delete',
-                       'hashLevels' => 2,
+                       'class'           => 'LocalRepo',
+                       'name'            => 'local',
+                       'url'             => 'http://example.com/images',
+                       'hashLevels'      => 2,
                        'transformVia404' => false,
+                       'backend'         => 'local-backend'
                );
-
+               $tmpGlobals['wgForeignFileRepos'] = array();
                $tmpGlobals['wgEnableParserCache'] = false;
                $tmpGlobals['wgHooks'] = $wgHooks;
                $tmpGlobals['wgDeferredUpdateList'] = array();
@@ -79,10 +74,10 @@ class NewParserTest extends MediaWikiTestCase {
                // $tmpGlobals['wgContLang'] = new StubContLang;
                $tmpGlobals['wgUser'] = new User;
                $context = new RequestContext();
-               $tmpGlobals['wgLang'] = $context->getLang();
+               $tmpGlobals['wgLang'] = $context->getLanguage();
                $tmpGlobals['wgOut'] = $context->getOutput();
                $tmpGlobals['wgParser'] = new StubObject( 'wgParser', $GLOBALS['wgParserConf']['class'], array( $GLOBALS['wgParserConf'] ) );
-               $tmpGlobals['wgRequest'] = new WebRequest;
+               $tmpGlobals['wgRequest'] = $context->getRequest();
 
                if ( $GLOBALS['wgStyleDirectory'] === false ) {
                        $tmpGlobals['wgStyleDirectory'] = "$IP/skins";
@@ -104,11 +99,9 @@ class NewParserTest extends MediaWikiTestCase {
                $wgNamespaceProtection[NS_MEDIAWIKI] = 'editinterface';
                $wgNamespaceAliases['Image'] = NS_FILE;
                $wgNamespaceAliases['Image_talk'] = NS_FILE_TALK;
-
        }
 
        public function tearDown() {
-
                foreach ( $this->savedInitialGlobals as $var => $val ) {
                        $GLOBALS[$var] = $val;
                }
@@ -118,9 +111,14 @@ class NewParserTest extends MediaWikiTestCase {
                $wgNamespaceProtection[NS_MEDIAWIKI] = $this->savedWeirdGlobals['mw_namespace_protection'];
                $wgNamespaceAliases['Image'] = $this->savedWeirdGlobals['image_alias'];
                $wgNamespaceAliases['Image_talk'] = $this->savedWeirdGlobals['image_talk_alias'];
+
+               // Restore backends
+               RepoGroup::destroySingleton();
+               FileBackendGroup::destroySingleton();
        }
 
        function addDBData() {
+               $this->tablesUsed[] = 'image';
                # Hack: insert a few Wikipedia in-project interwiki prefixes,
                # for testing inter-language links
                $this->db->insert( 'interwiki', array(
@@ -164,7 +162,7 @@ class NewParserTest extends MediaWikiTestCase {
                # Update certain things in site_stats
                $this->db->insert( 'site_stats',
                        array( 'ss_row_id' => 1, 'ss_images' => 2, 'ss_good_articles' => 1 ),
-                       __METHOD__ );
+                       __METHOD__, array( 'IGNORE' ) );
 
                # Reinitialise the LocalisationCache to match the database state
                Language::getLocalisationCache()->unloadAll();
@@ -231,14 +229,22 @@ class NewParserTest extends MediaWikiTestCase {
                        'wgScript' => '/index.php',
                        'wgScriptPath' => '/',
                        'wgArticlePath' => '/wiki/$1',
+                       'wgExtensionAssetsPath' => '/extensions',
                        'wgActionPaths' => array(),
                        'wgLocalFileRepo' => array(
-                               'class' => 'LocalRepo',
-                               'name' => 'local',
-                               'directory' => $this->uploadDir,
-                               'url' => 'http://example.com/images',
-                               'hashLevels' => 2,
+                               'class'           => 'LocalRepo',
+                               'name'            => 'local',
+                               'url'             => 'http://example.com/images',
+                               'hashLevels'      => 2,
                                'transformVia404' => false,
+                               'backend'         => new FSFileBackend( array(
+                                       'name'        => 'local-backend',
+                                       'lockManager' => 'nullLockManager',
+                                       'containerPaths' => array(
+                                               'local-public' => "$this->uploadDir",
+                                               'local-thumb'  => "$this->uploadDir/thumb",
+                                       )
+                               ) )
                        ),
                        'wgEnableUploads' => self::getOptionValue( 'wgEnableUploads', $opts, true ),
                        'wgStylePath' => '/skins',
@@ -278,6 +284,7 @@ class NewParserTest extends MediaWikiTestCase {
                        'wgExternalLinkTarget' => false,
                        'wgAlwaysUseTidy' => false,
                        'wgHtml5' => true,
+                       'wgCleanupPresentationalAttributes' => true,
                        'wgWellFormedXml' => true,
                        'wgAllowMicrodataAttributes' => true,
                        'wgAdaptiveMessageCache' => true,
@@ -307,28 +314,30 @@ class NewParserTest extends MediaWikiTestCase {
                $langObj = Language::factory( $lang );
                $GLOBALS['wgContLang'] = $langObj;
                $context = new RequestContext();
-               $GLOBALS['wgLang'] = $context->getLang();
+               $GLOBALS['wgLang'] = $context->getLanguage();
 
                $GLOBALS['wgMemc'] = new EmptyBagOStuff;
                $GLOBALS['wgOut'] = $context->getOutput();
+               $GLOBALS['wgUser'] = $context->getUser();
 
                global $wgHooks;
 
                $wgHooks['ParserTestParser'][] = 'ParserTestParserHook::setup';
-               $wgHooks['ParserTestParser'][] = 'ParserTestStaticParserHook::setup';
                $wgHooks['ParserGetVariableValueTs'][] = 'ParserTest::getFakeTimestamp';
 
                MagicWord::clearCache();
+               RepoGroup::destroySingleton();
+               FileBackendGroup::destroySingleton();
 
                # Publish the articles after we have the final language set
                $this->publishTestArticles();
 
                # The entries saved into RepoGroup cache with previous globals will be wrong.
                RepoGroup::destroySingleton();
+               FileBackendGroup::destroySingleton();
                MessageCache::singleton()->destroyInstance();
 
-               global $wgUser;
-               $wgUser = new User();
+               return $context;
        }
 
        /**
@@ -369,13 +378,13 @@ class NewParserTest extends MediaWikiTestCase {
         * after each test runs.
         */
        protected function teardownGlobals() {
-               RepoGroup::destroySingleton();
-               LinkCache::singleton()->clear();
-
                foreach ( $this->savedGlobals as $var => $val ) {
                        $GLOBALS[$var] = $val;
                }
 
+               RepoGroup::destroySingleton();
+               LinkCache::singleton()->clear();
+
                $this->teardownUploadDir( $this->uploadDir );
        }
 
@@ -470,10 +479,10 @@ class NewParserTest extends MediaWikiTestCase {
                wfDebug( "Running parser test: $desc\n" );
 
                $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'];
@@ -500,8 +509,7 @@ class NewParserTest extends MediaWikiTestCase {
                        $replace = $opts['replace'][1];
                        $out = $parser->replaceSection( $input, $section, $replace );
                } elseif ( isset( $opts['comment'] ) ) {
-                       $linker = $user->getSkin();
-                       $out = $linker->formatComment( $input, $title, $local );
+                       $out = Linker::formatComment( $input, $title, $local );
                } elseif ( isset( $opts['preload'] ) ) {
                        $out = $parser->getpreloadText( $input, $title, $options );
                } else {
@@ -519,10 +527,9 @@ class NewParserTest extends MediaWikiTestCase {
                        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'] ) );
@@ -543,11 +550,12 @@ class NewParserTest extends MediaWikiTestCase {
        /**
         * Run a fuzz test series
         * Draw input from a set of test files
+        *
+        * @todo @fixme Needs some work to not eat memory until the world explodes
+        *
+        * @group Broken
         */
        function testFuzzTests() {
-
-               $this->markTestIncomplete( 'Breaks tesla due to memory restrictions' );
-
                global $wgParserTestFiles;
 
                $files = $wgParserTestFiles;
@@ -690,7 +698,7 @@ class NewParserTest extends MediaWikiTestCase {
        //Various action functions
 
        public function addArticle( $name, $text, $line ) {
-               self::$articles[$name] = $text;
+               self::$articles[$name] = array( $text, $line );
        }
 
        public function publishTestArticles() {
@@ -698,12 +706,9 @@ class NewParserTest extends MediaWikiTestCase {
                        return;
                }
 
-               foreach ( self::$articles as $name => $text ) {
-                       $title = Title::newFromText( $name );
-
-                       if ( $title->getArticleID( Title::GAID_FOR_UPDATE ) == 0 ) {
-                               ParserTest::addArticle( $name, $text );
-                       }
+               foreach ( self::$articles as $name => $info ) {
+                       list( $text, $line ) = $info;
+                       ParserTest::addArticle( $name, $text, $line, 'ignoreduplicate' );
                }
        }
 
@@ -728,7 +733,7 @@ class NewParserTest extends MediaWikiTestCase {
        }
        //Various "cleanup" functions
 
-       /*
+       /**
         * Run the "tidy" command on text if the $wgUseTidy
         * global is true
         *
@@ -757,10 +762,6 @@ class NewParserTest extends MediaWikiTestCase {
                }
        }
 
-       public function showRunFile( $file ) {
-               /* NOP */
-       }
-
        //Test options parser functions
 
        protected function parseOptions( $instring ) {