Localisation updates for extension messages from Betawiki (2008-04-20 11:12 CEST)
[lhc/web/wiklou.git] / maintenance / parserTests.inc
index bfb226b..c2f4938 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();
@@ -141,10 +142,7 @@ class ParserTest {
                } else {
                        global $IP;
                        $relative = wfRelativePath( $filename, $IP );
-                       print $this->term->color( 1 ) .
-                               "Reading tests from \"$relative\"..." .
-                               $this->term->reset() .
-                               "\n";
+                       $this->showRunFile( $relative );
                }
 
                $data = array();
@@ -256,6 +254,7 @@ class ParserTest {
         * @return bool
         */
        private function runTest( $desc, $input, $result, $opts ) {
+               global $wgParserConf;
                if( $this->showProgress ) {
                        $this->showTesting( $desc );
                }
@@ -280,7 +279,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 +297,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 {
@@ -313,7 +313,8 @@ class ParserTest {
                        } else if (preg_match('/\\bcat\\b/i', $opts)) {
                                global $wgOut;
                                $wgOut->addCategoryLinks($output->getCategories());
-                               $out = $this->tidy ( implode( ' ', $wgOut->getCategoryLinks() ) );
+                               $cats = $wgOut->getCategoryLinks();
+                               $out = $this->tidy( implode( ' ', $cats['normal'] ) );
                        }
 
                        $result = $this->tidy($result);
@@ -350,7 +351,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 );
@@ -402,6 +403,14 @@ class ParserTest {
                        'wgUseTidy' => false,
                        'wgDefaultLanguageVariant' => $variant,
                        'wgVariantArticlePath' => false,
+                       'wgGroupPermissions' => array( '*' => array(
+                               'createaccount' => true,
+                               'read'          => true,
+                               'edit'          => true,
+                               'createpage'    => true,
+                               'createtalk'    => true,
+                       ) ),
+                       'wgDefaultExternalStore' => array(),
                        );
                $this->savedGlobals = array();
                foreach( $settings as $var => $val ) {
@@ -412,7 +421,6 @@ class ParserTest {
                $GLOBALS['wgLang'] = $langObj;
                $GLOBALS['wgContLang'] = $langObj;
 
-               $GLOBALS['wgLoadBalancer']->loadMasterPos();
                //$GLOBALS['wgMessageCache'] = new MessageCache( new BagOStuff(), false, 0, $GLOBALS['wgDBname'] );
                $this->setupDatabase();
 
@@ -432,7 +440,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', 'category'
                );
 
                if ($wgDBtype === 'mysql') 
@@ -458,7 +466,7 @@ class ParserTest {
                # Make sure we don't mess with the live DB
                if (!$setupDB && $wgDBprefix === 'parsertest_') {
                        # oh teh horror
-                       $GLOBALS['wgLoadBalancer'] = LoadBalancer::newFromParams( $GLOBALS['wgDBservers'] );
+                       LBFactory::destroy();
                        $db = wfGetDB( DB_MASTER );
 
                        $tables = $this->listTables();
@@ -550,7 +558,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 +594,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 (
@@ -631,7 +651,7 @@ class ParserTest {
        /**
         * "Running test $desc..."
         */
-       private function showTesting( $desc ) {
+       protected function showTesting( $desc ) {
                print "Running test $desc... ";
        }
 
@@ -641,7 +661,7 @@ class ParserTest {
         * @param string $desc The test name
         * @return bool
         */
-       private function showSuccess( $desc ) {
+       protected function showSuccess( $desc ) {
                if( $this->showProgress ) {
                        print $this->term->color( '1;32' ) . 'PASSED' . $this->term->reset() . "\n";
                }
@@ -657,7 +677,7 @@ class ParserTest {
         * @param string $html Actual HTML output
         * @return bool
         */
-       private function showFailure( $desc, $result, $html ) {
+       protected function showFailure( $desc, $result, $html ) {
                if( $this->showFailure ) {
                        if( !$this->showProgress ) {
                                # In quiet mode we didn't show the 'Testing' message before the
@@ -688,7 +708,7 @@ class ParserTest {
         * @param string $outFileTail Tailing for the output file name
         * @return string
         */
-       private function quickDiff( $input, $output, $inFileTail='expected', $outFileTail='actual' ) {
+       protected function quickDiff( $input, $output, $inFileTail='expected', $outFileTail='actual' ) {
                $prefix = wfTempDir() . "/mwParser-" . mt_rand();
 
                $infile = "$prefix-$inFileTail";
@@ -723,7 +743,7 @@ class ParserTest {
         * @param string $text
         * @return string
         */
-       private function colorDiff( $text ) {
+       protected function colorDiff( $text ) {
                return preg_replace(
                        array( '/^(-.*)$/m', '/^(\+.*)$/m' ),
                        array( $this->term->color( 34 ) . '$1' . $this->term->reset(),
@@ -731,6 +751,18 @@ class ParserTest {
                        $text );
        }
 
+       /**
+        * Show "Reading tests from ..."
+        *
+        * @param String $path
+        */
+       protected function showRunFile( $path ){
+               print $this->term->color( 1 ) .
+                       "Reading tests from \"$path\"..." .
+                       $this->term->reset() .
+                       "\n";
+       }
+
        /**
         * Insert a temporary test article
         * @param string $name the title, including any prefix
@@ -942,13 +974,17 @@ class DbTestRecorder extends TestRecorder  {
         * and all that fun stuff
         */
        function start() {
+               global $wgDBtype;
                parent::start();
 
                $this->db->begin();
 
                if( ! $this->db->tableExists( 'testrun' ) or ! $this->db->tableExists( 'testitem') ) {
                        print "WARNING> `testrun` table not found in database. Trying to create table.\n";
-                       dbsource( dirname(__FILE__) . '/testRunner.sql',  $this->db );
+            if ($wgDBtype === 'postgres')
+                               dbsource( dirname(__FILE__) . '/testRunner.postgres.sql',  $this->db );
+                       else
+                               dbsource( dirname(__FILE__) . '/testRunner.sql',  $this->db );
                        echo "OK, resuming.\n";
                }
 
@@ -964,7 +1000,10 @@ class DbTestRecorder extends TestRecorder  {
                                'tr_uname'       => php_uname()
                        ),
                        __METHOD__ );
-               $this->curRun = $this->db->insertId();
+                       if ($wgDBtype === 'postgres')
+                               $this->curRun = $this->db->currentSequenceValue('testrun_id_seq');
+                       else
+                               $this->curRun = $this->db->insertId();
        }
 
        /**