Updates German
[lhc/web/wiklou.git] / maintenance / parserTests.inc
index d0a5f6f..510a2db 100644 (file)
@@ -327,6 +327,22 @@ class ParserTest {
                }
        }
 
+
+       /**
+        * Use a regex to find out the value of an option
+        * @param $regex A regex, the first group will be the value returned
+        * @param $opts Options line to look in
+        * @param $defaults Default value returned if the regex does not match
+        */
+       private static function getOptionValue( $regex, $opts, $default ) {
+               $m = array();
+               if( preg_match( $regex, $opts, $m ) ) {
+                       return $m[1];
+               } else {
+                       return $default;
+               }
+       }
+
        /**
         * Set up the global variables for a consistent environment for each test.
         * Ideally this should replace the global configuration entirely.
@@ -342,19 +358,13 @@ class ParserTest {
                        $this->uploadDir = $this->setupUploadDir();
                }
 
-               $m = array();
-               if( preg_match( '/language=([a-z]+(?:_[a-z]+)?)/', $opts, $m ) ) {
-                       $lang = $m[1];
-               } else {
-                       $lang = 'en';
-               }
-
-               if( preg_match( '/variant=([a-z]+(?:-[a-z]+)?)/', $opts, $m ) ) {
-                       $variant = $m[1];
-               } else {
-                       $variant = false;
-               }
-
+               # Find out values for some special options.
+               $lang =
+                       self::getOptionValue( '/language=([a-z]+(?:_[a-z]+)?)/', $opts, 'en' );
+               $variant =
+                       self::getOptionValue( '/variant=([a-z]+(?:-[a-z]+)?)/', $opts, false );
+               $maxtoclevel =
+                       self::getOptionValue( '/wgMaxTocLevel=(\d+)/', $opts, 999 );
 
                $settings = array(
                        'wgServer' => 'http://localhost',
@@ -362,8 +372,15 @@ class ParserTest {
                        'wgScriptPath' => '/',
                        'wgArticlePath' => '/wiki/$1',
                        'wgActionPaths' => array(),
-                       'wgUploadPath' => 'http://example.com/images',
-                       'wgUploadDirectory' => $this->uploadDir,
+                       'wgLocalFileRepo' => array(
+                               'class' => 'LocalRepo',
+                               'name' => 'local',
+                               'directory' => $this->uploadDir,
+                               'url' => 'http://example.com/images',
+                               'hashLevels' => 2,
+                               'transformVia404' => false,
+                       ),
+                       'wgEnableUploads' => true,
                        'wgStyleSheetPath' => '/skins',
                        'wgSitename' => 'MediaWiki',
                        'wgServerName' => 'Britney Spears',
@@ -374,7 +391,7 @@ class ParserTest {
                        'wgLang' => null,
                        'wgContLang' => null,
                        'wgNamespacesWithSubpages' => array( 0 => preg_match('/\\bsubpage\\b/i', $opts)),
-                       'wgMaxTocLevel' => 999,
+                       'wgMaxTocLevel' => $maxtoclevel,
                        'wgCapitalLinks' => true,
                        'wgNoFollowLinks' => true,
                        'wgThumbnailScriptPath' => false,
@@ -416,7 +433,7 @@ class ParserTest {
                        'watchlist', 'math', 'searchindex',
                        'interwiki', 'querycache',
                        'objectcache', 'job', 'redirect',
-                       'querycachetwo'
+                       'querycachetwo', 'archive', 'user_groups'
                );
                
                // Allow extensions to add to the list of tables to duplicate;
@@ -531,20 +548,12 @@ class ParserTest {
         */
        private function setupUploadDir() {
                global $IP;
-
                $dir = wfTempDir() . "/mwParser-" . mt_rand() . "-images";
+               wfDebug( "Creating upload directory $dir\n" );
                mkdir( $dir );
                mkdir( $dir . '/3' );
                mkdir( $dir . '/3/3a' );
-
-               $img = "$IP/skins/monobook/headbg.jpg";
-               $h = fopen($img, 'r');
-               $c = fread($h, filesize($img));
-               fclose($h);
-
-               $f = fopen( $dir . '/3/3a/Foobar.jpg', 'wb' );
-               fwrite( $f, $c );
-               fclose( $f );
+               copy( "$IP/skins/monobook/headbg.jpg", "$dir/3/3a/Foobar.jpg" );
                return $dir;
        }
 
@@ -553,6 +562,7 @@ class ParserTest {
         * after each test runs.
         */
        private function teardownGlobals() {
+               RepoGroup::destroySingleton();
                foreach( $this->savedGlobals as $var => $val ) {
                        $GLOBALS[$var] = $val;
                }
@@ -593,7 +603,7 @@ class ParserTest {
        }
 
        /**
-        * @desc delete the specified files, if they exist.
+        * Delete the specified files, if they exist.
         * @param array $files full paths to files to delete.
         */
        private static function deleteFiles( $files ) {
@@ -605,7 +615,7 @@ class ParserTest {
        }
 
        /**
-        * @desc delete the specified directories, if they exist. Must be empty.
+        * Delete the specified directories, if they exist. Must be empty.
         * @param array $dirs full paths to directories to delete.
         */
        private static function deleteDirs( $dirs ) {
@@ -783,7 +793,7 @@ class ParserTest {
        private function tidy( $text ) {
                global $wgUseTidy;
                if ($wgUseTidy) {
-                       $text = Tidy::RunOn($text);
+                       $text = Parser::tidy($text);
                }
                return $text;
        }