docs update
[lhc/web/wiklou.git] / maintenance / parserTests.inc
index b789ebe..00b1fe1 100644 (file)
@@ -95,6 +95,7 @@ class ParserTest {
                } else {
                        $this->recorder = new TestRecorder( $this->term );
                }
+               $this->keepUploads = isset( $options['keep-uploads'] );
 
                $this->hooks = array();
                $this->functionHooks = array();
@@ -256,6 +257,7 @@ class ParserTest {
         * @return bool
         */
        private function runTest( $desc, $input, $result, $opts ) {
+               global $wgParserConf;
                if( $this->showProgress ) {
                        $this->showTesting( $desc );
                }
@@ -280,7 +282,8 @@ class ParserTest {
 
                $noxml = (bool)preg_match( '~\\b noxml \\b~x', $opts );
 
-               $parser = new Parser();
+               $class = $wgParserConf['class'];
+               $parser = new $class( $wgParserConf );
                foreach( $this->hooks as $tag => $callback ) {
                        $parser->setHook( $tag, $callback );
                }
@@ -297,11 +300,11 @@ class ParserTest {
                        $out = $parser->preSaveTransform( $input, $title, $user, $options );
                } elseif (preg_match('/\\bmsg\\b/i', $opts)) {
                        $out = $parser->transformMsg( $input, $options );
-               } elseif( preg_match( '/\\bsection=(\d+)\b/i', $opts, $matches ) ) {
-                       $section = intval( $matches[1] );
+               } elseif( preg_match( '/\\bsection=([\w-]+)\b/i', $opts, $matches ) ) {
+                       $section = $matches[1];
                        $out = $parser->getSection( $input, $section );
-               } elseif( preg_match( '/\\breplace=(\d+),"(.*?)"/i', $opts, $matches ) ) {
-                       $section = intval( $matches[1] );
+               } elseif( preg_match( '/\\breplace=([\w-]+),"(.*?)"/i', $opts, $matches ) ) {
+                       $section = $matches[1];
                        $replace = $matches[2];
                        $out = $parser->replaceSection( $input, $section, $replace );
                } else {
@@ -350,7 +353,7 @@ class ParserTest {
         */
        private function setupGlobals($opts = '') {
                # Save the prefixed / quoted table names for later use when we make the temporaries.
-               $db = wfGetDB( DB_READ );
+               $db = wfGetDB( DB_SLAVE );
                $this->oldTableNames = array();
                foreach( $this->listTables() as $table ) {
                        $this->oldTableNames[$table] = $db->tableName( $table );
@@ -432,7 +435,7 @@ class ParserTest {
                        'site_stats', 'hitcounter',     'ipblocks', 'image', 'oldimage',
                        'recentchanges', 'watchlist', 'math', 'interwiki',
                        'querycache', 'objectcache', 'job', 'redirect', 'querycachetwo',
-                       'archive', 'user_groups'
+                       'archive', 'user_groups', 'page_props'
                );
 
                if ($wgDBtype === 'mysql') 
@@ -550,7 +553,15 @@ class ParserTest {
         */
        private function setupUploadDir() {
                global $IP;
-               $dir = wfTempDir() . "/mwParser-" . mt_rand() . "-images";
+               if ( $this->keepUploads ) {
+                       $dir = wfTempDir() . '/mwParser-images';
+                       if ( is_dir( $dir ) ) {
+                               return $dir;
+                       }
+               } else {
+                       $dir = wfTempDir() . "/mwParser-" . mt_rand() . "-images";
+               }
+
                wfDebug( "Creating upload directory $dir\n" );
                mkdir( $dir );
                mkdir( $dir . '/3' );
@@ -578,6 +589,10 @@ class ParserTest {
         * Remove the dummy uploads directory
         */
        private function teardownUploadDir( $dir ) {
+               if ( $this->keepUploads ) {
+                       return;
+               }
+
                // delete the files first, then the dirs.
                self::deleteFiles(
                        array (