Merge "Language::isValidBuiltInCode() should not accept uppercase input"
[lhc/web/wiklou.git] / tests / parser / parserTest.inc
index 0bbee17..24c5aba 100644 (file)
@@ -69,11 +69,6 @@ class ParserTest {
         */
        private $djVuSupport;
 
-       /**
-        * @var string $oldTablePrefix Original table prefix
-        */
-       private $oldTablePrefix;
-
        private $maxFuzzTestLength = 300;
        private $fuzzSeed = 0;
        private $memoryLimit = 50;
@@ -145,6 +140,7 @@ class ParserTest {
 
                $this->hooks = array();
                $this->functionHooks = array();
+               $this->transparentHooks = array();
                self::setUp();
        }
 
@@ -152,6 +148,7 @@ class ParserTest {
                global $wgParser, $wgParserConf, $IP, $messageMemc, $wgMemc,
                        $wgUser, $wgLang, $wgOut, $wgRequest, $wgStyleDirectory, $wgEnableParserCache,
                        $wgExtraNamespaces, $wgNamespaceAliases, $wgNamespaceProtection, $wgLocalFileRepo,
+                       $wgExtraInterlanguageLinkPrefixes,
                        $parserMemc, $wgThumbnailScriptPath, $wgScriptPath,
                        $wgArticlePath, $wgScript, $wgStylePath, $wgExtensionAssetsPath,
                        $wgMainCacheType, $wgMessageCacheType, $wgParserCacheType, $wgLockManagers;
@@ -222,6 +219,9 @@ class ParserTest {
                if ( $wgStyleDirectory === false ) {
                        $wgStyleDirectory = "$IP/skins";
                }
+               // "extra language links"
+               // see https://gerrit.wikimedia.org/r/111390
+               array_push( $wgExtraInterlanguageLinkPrefixes, 'mul' );
 
                self::setupInterwikis();
        }
@@ -275,6 +275,11 @@ class ParserTest {
                                        'iw_api' => '',
                                        'iw_wikiid' => '',
                                        'iw_local' => 1 ),
+                               'mul' => array(
+                                       'iw_url' => 'http://wikisource.org/wiki/$1',
+                                       'iw_api' => '',
+                                       'iw_wikiid' => '',
+                                       'iw_local' => 1 ),
                        );
                        if ( array_key_exists( $prefix, $testInterwikis ) ) {
                                $iwData = $testInterwikis[$prefix];
@@ -528,6 +533,10 @@ class ParserTest {
                        $parser->setFunctionHook( $tag, $callback, $flags );
                }
 
+               foreach ( $this->transparentHooks as $tag => $callback ) {
+                       $parser->setTransparentTagHook( $tag, $callback );
+               }
+
                wfRunHooks( 'ParserTestParser', array( &$parser ) );
 
                return $parser;
@@ -928,7 +937,6 @@ class ParserTest {
                }
 
                $this->databaseSetupDone = true;
-               $this->oldTablePrefix = $wgDBprefix;
 
                # SqlBagOStuff broke when using temporary tables on r40209 (bug 15892).
                # It seems to have been fixed since (r55079?), but regressed at some point before r85701.
@@ -1007,7 +1015,7 @@ class ParserTest {
                                'size'        => 12345,
                                'width'       => 240,
                                'height'      => 180,
-                               'bits'        => 24,
+                               'bits'        => 0,
                                'media_type'  => MEDIATYPE_DRAWING,
                                'mime'        => 'image/svg+xml',
                                'metadata'    => serialize( array() ),
@@ -1015,34 +1023,6 @@ class ParserTest {
                                'fileExists'  => true
                ), $this->db->timestamp( '20010115123500' ), $user );
 
-               $image = wfLocalFile( Title::makeTitle( NS_FILE, 'Portrait.png' ) );
-               # again, note that size/width/height below are ignored; see above.
-               $image->recordUpload2( '', 'Upload of tall bitmap', 'Some tall bitmap', array(
-                       'size'        => 12345,
-                       'width'       => 180,
-                       'height'      => 240,
-                       'bits'        => 8,
-                       'media_type'  => MEDIATYPE_BITMAP,
-                       'mime'        => 'image/png',
-                       'metadata'    => serialize( array() ),
-                       'sha1'        => wfBaseConvert( '', 16, 36, 31 ),
-                       'fileExists'  => true
-               ), $this->db->timestamp( '20140515134200' ), $user );
-
-               $image = wfLocalFile( Title::makeTitle( NS_FILE, 'Portrait.svg' ) );
-               # again, note that size/width/height below are ignored; see above.
-               $image->recordUpload2( '', 'Upload of tall SVG', 'Some tall SVG', array(
-                       'size'        => 12345,
-                       'width'       => 180,
-                       'height'      => 240,
-                       'bits'        => 24,
-                       'media_type'  => MEDIATYPE_DRAWING,
-                       'mime'        => 'image/svg+xml',
-                       'metadata'    => serialize( array() ),
-                       'sha1'        => wfBaseConvert( '', 16, 36, 31 ),
-                       'fileExists'  => true
-               ), $this->db->timestamp( '20140325124200' ), $user );
-
                # This image will be blacklisted in [[MediaWiki:Bad image list]]
                $image = wfLocalFile( Title::makeTitle( NS_FILE, 'Bad.jpg' ) );
                $image->recordUpload2( '', 'zomgnotcensored', 'Borderline image', array(
@@ -1063,6 +1043,7 @@ class ParserTest {
                        'size' => 3249,
                        'width' => 2480,
                        'height' => 3508,
+                       'bits' => 0,
                        'media_type' => MEDIATYPE_BITMAP,
                        'mime' => 'image/vnd.djvu',
                        'metadata' => '<?xml version="1.0" ?>
@@ -1162,25 +1143,18 @@ class ParserTest {
                }
 
                wfMkdirParents( $dir . '/3/3a', null, __METHOD__ );
-               copy( "$IP/skins/monobook/headbg.jpg", "$dir/3/3a/Foobar.jpg" );
+               copy( "$IP/tests/phpunit/data/parser/headbg.jpg", "$dir/3/3a/Foobar.jpg" );
                wfMkdirParents( $dir . '/e/ea', null, __METHOD__ );
-               copy( "$IP/skins/monobook/wiki.png", "$dir/e/ea/Thumb.png" );
+               copy( "$IP/tests/phpunit/data/parser/wiki.png", "$dir/e/ea/Thumb.png" );
                wfMkdirParents( $dir . '/0/09', null, __METHOD__ );
-               copy( "$IP/skins/monobook/headbg.jpg", "$dir/0/09/Bad.jpg" );
+               copy( "$IP/tests/phpunit/data/parser/headbg.jpg", "$dir/0/09/Bad.jpg" );
                wfMkdirParents( $dir . '/f/ff', null, __METHOD__ );
                file_put_contents( "$dir/f/ff/Foobar.svg",
                        '<?xml version="1.0" encoding="utf-8"?>' .
                        '<svg xmlns="http://www.w3.org/2000/svg"' .
                        ' version="1.1" width="240" height="180"/>' );
-               wfMkdirParents( $dir . '/9/93', null, __METHOD__ );
-               copy( "$IP/tests/phpunit/data/media/Portrait.png", "$dir/9/93/Portrait.png" );
-               wfMkdirParents( $dir . '/f/fc', null, __METHOD__ );
-               file_put_contents( "$dir/f/fc/Portrait.svg",
-                       '<?xml version="1.0" encoding="utf-8"?>' .
-                       '<svg xmlns="http://www.w3.org/2000/svg"' .
-                       ' version="1.1" width="180" height="240"/>' );
                wfMkdirParents( $dir . '/5/5f', null, __METHOD__ );
-               copy( "$IP/tests/phpunit/data/media/LoremIpsum.djvu", "$dir/5/5f/LoremIpsum.djvu" );
+               copy( "$IP/tests/phpunit/data/parser/LoremIpsum.djvu", "$dir/5/5f/LoremIpsum.djvu" );
 
                return $dir;
        }
@@ -1265,17 +1239,6 @@ class ParserTest {
                                "$dir/thumb/f/ff/Foobar.svg/langde-270px-Foobar.svg.png",
                                "$dir/thumb/f/ff/Foobar.svg/langde-360px-Foobar.svg.png",
 
-                               "$dir/9/93/Portrait.png",
-                               "$dir/thumb/9/93/Portrait.png/165px-Portrait.png",
-
-                               "$dir/f/fc/Portrait.svg",
-                               "$dir/thumb/f/fc/Portrait.svg/165px-Portrait.svg.png",
-                               "$dir/thumb/f/fc/Portrait.svg/225px-Portrait.svg.png",
-                               "$dir/thumb/f/fc/Portrait.svg/247px-Portrait.svg.png",
-                               "$dir/thumb/f/fc/Portrait.svg/330px-Portrait.svg.png",
-                               "$dir/thumb/f/fc/Portrait.svg/337px-Portrait.svg.png",
-                               "$dir/thumb/f/fc/Portrait.svg/450px-Portrait.svg.png",
-
                                "$dir/math/f/a/5/fa50b8b616463173474302ca3e63586b.png",
                        )
                );
@@ -1287,18 +1250,10 @@ class ParserTest {
                                "$dir/thumb/3/3a/Foobar.jpg",
                                "$dir/thumb/3/3a",
                                "$dir/thumb/3",
-                               "$dir/9/93",
-                               "$dir/9",
-                               "$dir/thumb/9/93/Portrait.png",
-                               "$dir/thumb/9/93/",
-                               "$dir/thumb/9/",
                                "$dir/e/ea",
                                "$dir/e",
-                               "$dir/f/fc/",
                                "$dir/f/ff/",
                                "$dir/f/",
-                               "$dir/thumb/f/fc/Portrait.svg",
-                               "$dir/thumb/f/fc/",
                                "$dir/thumb/f/ff/Foobar.svg",
                                "$dir/thumb/f/ff/",
                                "$dir/thumb/f/",
@@ -1576,6 +1531,29 @@ class ParserTest {
                return true;
        }
 
+       /**
+        * Steal a callback function from the primary parser, save it for
+        * application to our scary parser. If the hook is not installed,
+        * abort processing of this file.
+        *
+        * @param string $name
+        * @return bool True if function hook is present
+        */
+       public function requireTransparentHook( $name ) {
+               global $wgParser;
+
+               $wgParser->firstCallInit(); // make sure hooks are loaded.
+
+               if ( isset( $wgParser->mTransparentTagHooks[$name] ) ) {
+                       $this->transparentHooks[$name] = $wgParser->mTransparentTagHooks[$name];
+               } else {
+                       echo "   This test suite requires the '$name' transparent hook extension, skipping.\n";
+                       return false;
+               }
+
+               return true;
+       }
+
        /**
         * Run the "tidy" command on text if the $wgUseTidy
         * global is true