Revert r108358. It's a good fellow and we like to keep it.
[lhc/web/wiklou.git] / tests / phpunit / includes / parser / NewParserTest.php
index 5adbfe6..e999796 100644 (file)
@@ -1,10 +1,19 @@
 <?php
 
 /**
+ * Although marked as a stub, can work independently.
+ *
  * @group Database
+ * @group Parser
+ * @group Stub
  */
 class NewParserTest extends MediaWikiTestCase {
 
+       static protected $articles = array();   // Array of test articles defined by the tests
+       /* The dataProvider is run on a different instance than the test, so it must be static
+        * When running tests from several files, all tests will see all articles.
+        */
+
        public $uploadDir;
        public $keepUploads = false;
        public $runDisabled = false;
@@ -21,12 +30,13 @@ class NewParserTest extends MediaWikiTestCase {
        public $fuzzSeed = 0;
        public $memoryLimit = 50;
 
-       //PHPUnit + MediaWikiTestCase functions
+       protected $file = false;
 
        function setUp() {
-               global $wgContLang, $wgNamespaceProtection, $wgNamespaceAliases, $IP;
+               global $wgContLang, $wgNamespaceProtection, $wgNamespaceAliases;
+               global $wgHooks, $IP;
                $wgContLang = Language::factory( 'en' );
-               
+
                //Setup CLI arguments
                if ( $this->getCliArg( 'regex=' ) ) {
                        $this->regex = $this->getCliArg( 'regex=' );
@@ -34,11 +44,11 @@ class NewParserTest extends MediaWikiTestCase {
                        # Matches anything
                        $this->regex = '';
                }
-               
+
                $this->keepUploads = $this->getCliArg( 'keep-uploads' );
-                               
+
                $tmpGlobals = array();
-               
+
                $tmpGlobals['wgScript'] = '/index.php';
                $tmpGlobals['wgScriptPath'] = '/';
                $tmpGlobals['wgArticlePath'] = '/wiki/$1';
@@ -46,33 +56,34 @@ 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();
-               $tmpGlobals['wgMemc'] = &wfGetMainCache();
-               $tmpGlobals['messageMemc'] = &wfGetMessageCacheStorage();
-               $tmpGlobals['parserMemc'] = &wfGetParserCacheStorage();
+               $tmpGlobals['wgMemc'] = wfGetMainCache();
+               $tmpGlobals['messageMemc'] = wfGetMessageCacheStorage();
+               $tmpGlobals['parserMemc'] = wfGetParserCacheStorage();
 
                // $tmpGlobals['wgContLang'] = new StubContLang;
                $tmpGlobals['wgUser'] = new User;
-               $tmpGlobals['wgLang'] = new StubUserLang;
-               $tmpGlobals['wgOut'] = new StubObject( 'wgOut', 'OutputPage' );
+               $context = new RequestContext();
+               $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";
                }
-               
-               
+
+
                foreach ( $tmpGlobals as $var => $val ) {
                        if ( array_key_exists( $var, $GLOBALS ) ) {
                                $this->savedInitialGlobals[$var] = $GLOBALS[$var];
@@ -80,31 +91,34 @@ class NewParserTest extends MediaWikiTestCase {
 
                        $GLOBALS[$var] = $val;
                }
-               
+
                $this->savedWeirdGlobals['mw_namespace_protection'] = $wgNamespaceProtection[NS_MEDIAWIKI];
                $this->savedWeirdGlobals['image_alias'] = $wgNamespaceAliases['Image'];
                $this->savedWeirdGlobals['image_talk_alias'] = $wgNamespaceAliases['Image_talk'];
-               
+
                $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;
                }
-               
+
                global $wgNamespaceProtection, $wgNamespaceAliases;
-               
+
                $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(
@@ -138,11 +152,17 @@ class NewParserTest extends MediaWikiTestCase {
                                   'iw_api'    => '',
                                   'iw_wikiid' => '',
                                   'iw_local'  => 1 ),
-                       ) );
+                       /**
+                        * @todo Fixme! Why are we inserting duplicate data here? Shouldn't
+                        * need this IGNORE or shouldn't need the insert at all.
+                        */
+                       ), __METHOD__, array( 'IGNORE' ) );
 
 
                # Update certain things in site_stats
-               $this->db->insert( 'site_stats', array( 'ss_row_id' => 1, 'ss_images' => 2, 'ss_good_articles' => 1 ) );
+               $this->db->insert( 'site_stats',
+                       array( 'ss_row_id' => 1, 'ss_images' => 2, 'ss_good_articles' => 1 ),
+                       __METHOD__, array( 'IGNORE' ) );
 
                # Reinitialise the LocalisationCache to match the database state
                Language::getLocalisationCache()->unloadAll();
@@ -151,9 +171,10 @@ class NewParserTest extends MediaWikiTestCase {
                MessageCache::singleton()->clear();
 
                $this->uploadDir = $this->setupUploadDir();
-               
+
                $user = User::newFromId( 0 );
-               
+               LinkCache::singleton()->clear(); # Avoids the odd failure at creating the nullRevision
+
                $image = wfLocalFile( Title::makeTitle( NS_FILE, 'Foobar.jpg' ) );
                $image->recordUpload2( '', 'Upload of some lame file', 'Some lame file', array(
                        'size'        => 12345,
@@ -182,12 +203,12 @@ class NewParserTest extends MediaWikiTestCase {
                        ), $this->db->timestamp( '20010115123500' ), $user );
 
        }
-       
-       
-       
-       
+
+
+
+
        //ParserTest setup/teardown functions
-       
+
        /**
         * Set up the global variables for a consistent environment for each test.
         * Ideally this should replace the global configuration entirely.
@@ -208,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',
@@ -255,9 +284,11 @@ class NewParserTest extends MediaWikiTestCase {
                        'wgExternalLinkTarget' => false,
                        'wgAlwaysUseTidy' => false,
                        'wgHtml5' => true,
+                       'wgCleanupPresentationalAttributes' => true,
                        'wgWellFormedXml' => true,
                        'wgAllowMicrodataAttributes' => true,
-                       'wgAdaptiveMessageCache' => true
+                       'wgAdaptiveMessageCache' => true,
+                       'wgUseDatabaseMessages' => true,
                );
 
                if ( $config ) {
@@ -281,36 +312,34 @@ class NewParserTest extends MediaWikiTestCase {
                }
 
                $langObj = Language::factory( $lang );
-               $GLOBALS['wgLang'] = $langObj;
                $GLOBALS['wgContLang'] = $langObj;
-               $GLOBALS['wgMemc'] = new FakeMemCachedClient;
-               $GLOBALS['wgOut'] = new OutputPage;
+               $context = new RequestContext();
+               $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();
 
-               global $wgUser;
-               $wgUser = new User();
-       }
-       
-       /**
-        * Restore default values and perform any necessary clean-up
-        * after each test runs.
-        */
-       protected function teardownGlobals() {
+               # 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();
-               LinkCache::singleton()->clear();
+               FileBackendGroup::destroySingleton();
+               MessageCache::singleton()->destroyInstance();
 
-               foreach ( $this->savedGlobals as $var => $val ) {
-                       $GLOBALS[$var] = $val;
-               }
+               return $context;
        }
-       
+
        /**
         * Create a dummy uploads directory which will contain a couple
         * of files in order to pass existence tests.
@@ -336,144 +365,209 @@ class NewParserTest extends MediaWikiTestCase {
                        return $dir;
                }
 
-               wfMkdirParents( $dir . '/3/3a' );
+               wfMkdirParents( $dir . '/3/3a', null, __METHOD__ );
                copy( "$IP/skins/monobook/headbg.jpg", "$dir/3/3a/Foobar.jpg" );
-               wfMkdirParents( $dir . '/0/09' );
+               wfMkdirParents( $dir . '/0/09', null, __METHOD__ );
                copy( "$IP/skins/monobook/headbg.jpg", "$dir/0/09/Bad.jpg" );
 
                return $dir;
        }
-       
-       
-       
-       
-       
-       //Actual test suites
-
-       public function testParserTests() {
-               
-               global $wgParserTestFiles;
-               
-               $files = $wgParserTestFiles;
-               
-               if( $this->getCliArg( 'file=' ) ) {
-                       $files = array( $this->getCliArg( 'file=' ) );
+
+       /**
+        * Restore default values and perform any necessary clean-up
+        * after each test runs.
+        */
+       protected function teardownGlobals() {
+               foreach ( $this->savedGlobals as $var => $val ) {
+                       $GLOBALS[$var] = $val;
                }
-               
-               foreach( $files as $file ) {
-                       
-                       $iter = new ParserTestFileIterator( $file, $this );
-                       
-                       foreach ( $iter as $t ) {
-                               
-                               try {
-                                       
-                                       $desc = $t['test'];
-                                       $input = $t['input'];
-                                       $result = $t['result'];
-                                       $opts = $t['options'];
-                                       $config = $t['config'];
-                                       
-                                       
-                                       $opts = $this->parseOptions( $opts );
-                                       $this->setupGlobals( $opts, $config );
-                       
-                                       $user = new User();
-                                       $options = ParserOptions::newFromUser( $user );
-                       
-                                       if ( isset( $opts['title'] ) ) {
-                                               $titleText = $opts['title'];
-                                       }
-                                       else {
-                                               $titleText = 'Parser test';
-                                       }
-                       
-                                       $local = isset( $opts['local'] );
-                                       $preprocessor = isset( $opts['preprocessor'] ) ? $opts['preprocessor'] : null;
-                                       $parser = $this->getParser( $preprocessor );
-                                       $title = Title::newFromText( $titleText );
-                       
-                                       if ( isset( $opts['pst'] ) ) {
-                                               $out = $parser->preSaveTransform( $input, $title, $user, $options );
-                                       } elseif ( isset( $opts['msg'] ) ) {
-                                               $out = $parser->transformMsg( $input, $options );
-                                       } elseif ( isset( $opts['section'] ) ) {
-                                               $section = $opts['section'];
-                                               $out = $parser->getSection( $input, $section );
-                                       } elseif ( isset( $opts['replace'] ) ) {
-                                               $section = $opts['replace'][0];
-                                               $replace = $opts['replace'][1];
-                                               $out = $parser->replaceSection( $input, $section, $replace );
-                                       } elseif ( isset( $opts['comment'] ) ) {
-                                               $linker = $user->getSkin();
-                                               $out = $linker->formatComment( $input, $title, $local );
-                                       } elseif ( isset( $opts['preload'] ) ) {
-                                               $out = $parser->getpreloadText( $input, $title, $options );
-                                       } else {
-                                               $output = $parser->parse( $input, $title, $options, true, true, 1337 );
-                                               $out = $output->getText();
-                       
-                                               if ( isset( $opts['showtitle'] ) ) {
-                                                       if ( $output->getTitleText() ) {
-                                                               $title = $output->getTitleText();
-                                                       }
-                       
-                                                       $out = "$title\n$out";
-                                               }
-                       
-                                               if ( isset( $opts['ill'] ) ) {
-                                                       $out = $this->tidy( implode( ' ', $output->getLanguageLinks() ) );
-                                               } elseif ( isset( $opts['cat'] ) ) {
-                                                       global $wgOut;
-                       
-                                                       $wgOut->addCategoryLinks( $output->getCategories() );
-                                                       $cats = $wgOut->getCategoryLinks();
-                       
-                                                       if ( isset( $cats['normal'] ) ) {
-                                                               $out = $this->tidy( implode( ' ', $cats['normal'] ) );
-                                                       } else {
-                                                               $out = '';
-                                                       }
-                                               }
-                       
-                                               $result = $this->tidy( $result );
-                                       }
-                       
-                                       $this->teardownGlobals();
-                                       
-                                       $this->assertEquals( $result, $out, $desc );
-                               
+
+               RepoGroup::destroySingleton();
+               LinkCache::singleton()->clear();
+
+               $this->teardownUploadDir( $this->uploadDir );
+       }
+
+       /**
+        * Remove the dummy uploads directory
+        */
+       private function teardownUploadDir( $dir ) {
+               if ( $this->keepUploads ) {
+                       return;
+               }
+
+               // delete the files first, then the dirs.
+               self::deleteFiles(
+                       array (
+                               "$dir/3/3a/Foobar.jpg",
+                               "$dir/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg",
+                               "$dir/thumb/3/3a/Foobar.jpg/200px-Foobar.jpg",
+                               "$dir/thumb/3/3a/Foobar.jpg/640px-Foobar.jpg",
+                               "$dir/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg",
+
+                               "$dir/0/09/Bad.jpg",
+
+                               "$dir/math/f/a/5/fa50b8b616463173474302ca3e63586b.png",
+                       )
+               );
+
+               self::deleteDirs(
+                       array (
+                               "$dir/3/3a",
+                               "$dir/3",
+                               "$dir/thumb/6/65",
+                               "$dir/thumb/6",
+                               "$dir/thumb/3/3a/Foobar.jpg",
+                               "$dir/thumb/3/3a",
+                               "$dir/thumb/3",
+
+                               "$dir/0/09/",
+                               "$dir/0/",
+                               "$dir/thumb",
+                               "$dir/math/f/a/5",
+                               "$dir/math/f/a",
+                               "$dir/math/f",
+                               "$dir/math",
+                               "$dir",
+                       )
+               );
+       }
+
+       /**
+        * Delete the specified files, if they exist.
+        * @param $files Array: full paths to files to delete.
+        */
+       private static function deleteFiles( $files ) {
+               foreach ( $files as $file ) {
+                       if ( file_exists( $file ) ) {
+                               unlink( $file );
+                       }
+               }
+       }
+
+       /**
+        * Delete the specified directories, if they exist. Must be empty.
+        * @param $dirs Array: full paths to directories to delete.
+        */
+       private static function deleteDirs( $dirs ) {
+               foreach ( $dirs as $dir ) {
+                       if ( is_dir( $dir ) ) {
+                               rmdir( $dir );
+                       }
+               }
+       }
+
+       public function parserTestProvider() {
+               if ( $this->file === false ) {
+                       global $wgParserTestFiles;
+                       $this->file = $wgParserTestFiles[0];
+               }
+               return new TestFileIterator( $this->file, $this );
+       }
+
+       /**
+        * Set the file from whose tests will be run by this instance
+        */
+       public function setParserTestFile( $filename ) {
+               $this->file = $filename;
+       }
+
+       /** @dataProvider parserTestProvider */
+       public function testParserTest( $desc, $input, $result, $opts, $config ) {
+               if ( !preg_match( '/' . $this->regex . '/', $desc ) ) return; //$this->markTestSkipped( 'Filtered out by the user' );
+
+               wfDebug( "Running parser test: $desc\n" );
+
+               $opts = $this->parseOptions( $opts );
+               $context = $this->setupGlobals( $opts, $config );
+
+               $user = $context->getUser();
+               $options = ParserOptions::newFromContext( $context );
+
+               if ( isset( $opts['title'] ) ) {
+                       $titleText = $opts['title'];
+               }
+               else {
+                       $titleText = 'Parser test';
+               }
+
+               $local = isset( $opts['local'] );
+               $preprocessor = isset( $opts['preprocessor'] ) ? $opts['preprocessor'] : null;
+               $parser = $this->getParser( $preprocessor );
+
+               $title = Title::newFromText( $titleText );
+
+               if ( isset( $opts['pst'] ) ) {
+                       $out = $parser->preSaveTransform( $input, $title, $user, $options );
+               } elseif ( isset( $opts['msg'] ) ) {
+                       $out = $parser->transformMsg( $input, $options, $title );
+               } elseif ( isset( $opts['section'] ) ) {
+                       $section = $opts['section'];
+                       $out = $parser->getSection( $input, $section );
+               } elseif ( isset( $opts['replace'] ) ) {
+                       $section = $opts['replace'][0];
+                       $replace = $opts['replace'][1];
+                       $out = $parser->replaceSection( $input, $section, $replace );
+               } elseif ( isset( $opts['comment'] ) ) {
+                       $out = Linker::formatComment( $input, $title, $local );
+               } elseif ( isset( $opts['preload'] ) ) {
+                       $out = $parser->getpreloadText( $input, $title, $options );
+               } else {
+                       $output = $parser->parse( $input, $title, $options, true, true, 1337 );
+                       $out = $output->getText();
+
+                       if ( isset( $opts['showtitle'] ) ) {
+                               if ( $output->getTitleText() ) {
+                                       $title = $output->getTitleText();
                                }
-                               catch( Exception $e ) {
-                                       $this->assertTrue( false, $t['test'] . ' (failed: ' . $e->getMessage() . ')' );
+
+                               $out = "$title\n$out";
+                       }
+
+                       if ( isset( $opts['ill'] ) ) {
+                               $out = $this->tidy( implode( ' ', $output->getLanguageLinks() ) );
+                       } elseif ( isset( $opts['cat'] ) ) {
+                               $outputPage = $context->getOutput();
+                               $outputPage->addCategoryLinks( $output->getCategories() );
+                               $cats = $outputPage->getCategoryLinks();
+
+                               if ( isset( $cats['normal'] ) ) {
+                                       $out = $this->tidy( implode( ' ', $cats['normal'] ) );
+                               } else {
+                                       $out = '';
                                }
-                               
                        }
-               
+                       $parser->mPreprocessor = null;
+
+                       $result = $this->tidy( $result );
                }
-                       
+
+               $this->teardownGlobals();
+
+               $this->assertEquals( $result, $out, $desc );
        }
-       
+
        /**
         * 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;
-               
+
                if( $this->getCliArg( 'file=' ) ) {
                        $files = array( $this->getCliArg( 'file=' ) );
                }
-               
+
                $dict = $this->getFuzzInput( $files );
                $dictSize = strlen( $dict );
                $logMaxLength = log( $this->maxFuzzTestLength );
-               
+
                ini_set( 'memory_limit', $this->memoryLimit * 1048576 );
 
                $user = new User;
@@ -481,9 +575,9 @@ class NewParserTest extends MediaWikiTestCase {
                $title = Title::makeTitle( NS_MAIN, 'Parser_test' );
 
                $id = 1;
-               
+
                while ( true ) {
-                       
+
                        // Generate test input
                        mt_srand( ++$this->fuzzSeed );
                        $totalLength = mt_rand( 1, $this->maxFuzzTestLength );
@@ -504,12 +598,8 @@ class NewParserTest extends MediaWikiTestCase {
                                $parser->parse( $input, $title, $opts );
                                $this->assertTrue( true, "Test $id, fuzz seed {$this->fuzzSeed}" );
                        } catch ( Exception $exception ) {
-                               
-                               ob_start();
-                               var_dump( $input );
-                               $input_dump = ob_get_contents();
-                               ob_end_clean();
-                               
+                               $input_dump = sprintf( "string(%d) \"%s\"\n", strlen( $input ), $input );
+
                                $this->assertTrue( false, "Test $id, fuzz seed {$this->fuzzSeed}. \n\nInput: $input_dump\n\nError: {$exception->getMessage()}\n\nBacktrace: {$exception->getTraceAsString()}" );
                        }
 
@@ -526,18 +616,18 @@ class NewParserTest extends MediaWikiTestCase {
                                        foreach ( $memStats as $name => $usage ) {
                                                $ret .= "$name: $usage\n";
                                        }
-                                       
+
                                        throw new MWException( $ret );
                                }
                        }
-                       
+
                        $id++;
-                       
+
                }
        }
 
        //Various getter functions
-       
+
        /**
         * Get an input dictionary from a set of parser test files
         */
@@ -555,7 +645,7 @@ class NewParserTest extends MediaWikiTestCase {
 
                return $dict;
        }
-       
+
        /**
         * Get a memory usage breakdown
         */
@@ -590,7 +680,7 @@ class NewParserTest extends MediaWikiTestCase {
 
                return $memStats;
        }
-       
+
        /**
         * Get a Parser object
         */
@@ -600,56 +690,28 @@ class NewParserTest extends MediaWikiTestCase {
                $class = $wgParserConf['class'];
                $parser = new $class( array( 'preprocessorClass' => $preprocessor ) + $wgParserConf );
 
-               foreach ( $this->hooks as $tag => $callback ) {
-                       $parser->setHook( $tag, $callback );
-               }
-
-               foreach ( $this->functionHooks as $tag => $bits ) {
-                       list( $callback, $flags ) = $bits;
-                       $parser->setFunctionHook( $tag, $callback, $flags );
-               }
-
                wfRunHooks( 'ParserTestParser', array( &$parser ) );
 
                return $parser;
        }
 
        //Various action functions
-       
-       /**
-        * Insert a temporary test article
-        * @param $name String: the title, including any prefix
-        * @param $text String: the article text
-        * @param $line Integer: the input line number, for reporting errors
-        */
-       public function addArticle( $name, $text, $line = 'unknown' ) {
-               global $wgCapitalLinks;
-
-               $text = $this->removeEndingNewline($text);
-
-               $oldCapitalLinks = $wgCapitalLinks;
-               $wgCapitalLinks = true; // We only need this from SetupGlobals() See r70917#c8637
 
-               $name = $this->removeEndingNewline( $name );
-               $title = Title::newFromText( $name );
+       public function addArticle( $name, $text, $line ) {
+               self::$articles[$name] = array( $text, $line );
+       }
 
-               if ( is_null( $title ) ) {
-                       throw new MWException( "invalid title ('$name' => '$title') at line $line\n" );
+       public function publishTestArticles() {
+               if ( empty( self::$articles ) ) {
+                       return;
                }
 
-               $aid = $title->getArticleID( Title::GAID_FOR_UPDATE );
-
-               if ( $aid != 0 ) {
-                       debug_print_backtrace();
-                       throw new MWException( "duplicate article '$name' at line $line\n" );
+               foreach ( self::$articles as $name => $info ) {
+                       list( $text, $line ) = $info;
+                       ParserTest::addArticle( $name, $text, $line, 'ignoreduplicate' );
                }
-
-               $art = new Article( $title );
-               $art->doEdit( $text, '', EDIT_NEW );
-
-               $wgCapitalLinks = $oldCapitalLinks;
        }
-       
+
        /**
         * Steal a callback function from the primary parser, save it for
         * application to our scary parser. If the hook is not installed,
@@ -660,28 +722,23 @@ class NewParserTest extends MediaWikiTestCase {
         */
        public function requireHook( $name ) {
                global $wgParser;
-
                $wgParser->firstCallInit( ); // make sure hooks are loaded.
-
-               if ( isset( $wgParser->mTagHooks[$name] ) ) {
-                       $this->hooks[$name] = $wgParser->mTagHooks[$name];
-               } else {
-                       echo "   This test suite requires the '$name' hook extension, skipping.\n";
-                       return false;
-               }
-
-               return true;
+               return isset( $wgParser->mTagHooks[$name] );
        }
 
+       public function requireFunctionHook( $name ) {
+               global $wgParser;
+               $wgParser->firstCallInit( ); // make sure hooks are loaded.
+               return isset( $wgParser->mFunctionHooks[$name] );
+       }
        //Various "cleanup" functions
-       
-       /*
+
+       /**
         * Run the "tidy" command on text if the $wgUseTidy
         * global is true
         *
         * @param $text String: the text to tidy
         * @return String
-        * @static
         */
        protected function tidy( $text ) {
                global $wgUseTidy;
@@ -692,7 +749,7 @@ class NewParserTest extends MediaWikiTestCase {
 
                return $text;
        }
-       
+
        /**
         * Remove last character if it is a newline
         */
@@ -706,7 +763,7 @@ class NewParserTest extends MediaWikiTestCase {
        }
 
        //Test options parser functions
-       
+
        protected function parseOptions( $instring ) {
                $opts = array();
                // foo
@@ -761,7 +818,7 @@ class NewParserTest extends MediaWikiTestCase {
                }
                return $opts;
        }
-       
+
        protected function cleanupOption( $opt ) {
                if ( substr( $opt, 0, 1 ) == '"' ) {
                        return substr( $opt, 1, -1 );
@@ -772,7 +829,7 @@ class NewParserTest extends MediaWikiTestCase {
                }
                return $opt;
        }
-       
+
        /**
         * Use a regex to find out the value of an option
         * @param $key String: name of option val to retrieve