Merge "DifferenceEngine: Remove broken comment"
[lhc/web/wiklou.git] / tests / phpunit / includes / parser / NewParserTest.php
index db352de..9551b2f 100644 (file)
@@ -31,6 +31,11 @@ class NewParserTest extends MediaWikiTestCase {
 
        protected $file = false;
 
+       public static function setUpBeforeClass() {
+               // Inject ParserTest well-known interwikis
+               ParserTest::setupInterwikis();
+       }
+
        protected function setUp() {
                global $wgNamespaceAliases;
                global $wgHooks, $IP;
@@ -99,12 +104,13 @@ class NewParserTest extends MediaWikiTestCase {
                                'createtalk' => true,
                ) );
                $tmpGlobals['wgNamespaceProtection'] = array( NS_MEDIAWIKI => 'editinterface' );
-               $tmpGlobals['wgMemc'] = new EmptyBagOStuff;
-               $tmpGlobals['messageMemc'] = wfGetMessageCacheStorage();
-               $tmpGlobals['parserMemc'] = wfGetParserCacheStorage();
 
                $tmpGlobals['wgParser'] = new StubObject( 'wgParser', $GLOBALS['wgParserConf']['class'], array( $GLOBALS['wgParserConf'] ) );
 
+               $tmpGlobals['wgFileExtensions'][] = 'svg';
+               $tmpGlobals['wgSVGConverter'] = 'rsvg';
+               $tmpGlobals['wgSVGConverters']['rsvg'] = '$path/rsvg-convert -w $width -h $height $input -o $output';
+
                if ( $GLOBALS['wgStyleDirectory'] === false ) {
                        $tmpGlobals['wgStyleDirectory'] = "$IP/skins";
                }
@@ -113,9 +119,11 @@ class NewParserTest extends MediaWikiTestCase {
                # actual thumbnails to do parser testing, we only care about receiving
                # a ThumbnailImage properly initialized.
                global $wgMediaHandlers;
-               foreach( $wgMediaHandlers as $type => $handler ) {
+               foreach ( $wgMediaHandlers as $type => $handler ) {
                        $tmpGlobals['wgMediaHandlers'][$type] = 'MockBitmapHandler';
                }
+               // Vector images have to be handled slightly differently
+               $tmpGlobals['wgMediaHandlers']['image/svg+xml'] = 'MockSvgHandler';
 
                $tmpHooks = $wgHooks;
                $tmpHooks['ParserTestParser'][] = 'ParserTestParserHook::setup';
@@ -141,64 +149,26 @@ class NewParserTest extends MediaWikiTestCase {
                RepoGroup::destroySingleton();
                FileBackendGroup::destroySingleton();
 
+               // Remove temporary pages from the link cache
+               LinkCache::singleton()->clear();
+
+               // Restore message cache (temporary pages and $wgUseDatabaseMessages)
+               MessageCache::destroyInstance();
+
                parent::tearDown();
        }
 
        function addDBData() {
                $this->tablesUsed[] = 'site_stats';
-               $this->tablesUsed[] = 'interwiki';
                # disabled for performance
                #$this->tablesUsed[] = 'image';
 
-               # Hack: insert a few Wikipedia in-project interwiki prefixes,
-               # for testing inter-language links
-               $this->db->insert( 'interwiki', array(
-                               array( 'iw_prefix' => 'wikipedia',
-                                       'iw_url' => 'http://en.wikipedia.org/wiki/$1',
-                                       'iw_api' => '',
-                                       'iw_wikiid' => '',
-                                       'iw_local' => 0 ),
-                               array( 'iw_prefix' => 'meatball',
-                                       'iw_url' => 'http://www.usemod.com/cgi-bin/mb.pl?$1',
-                                       'iw_api' => '',
-                                       'iw_wikiid' => '',
-                                       'iw_local' => 0 ),
-                               array( 'iw_prefix' => 'zh',
-                                       'iw_url' => 'http://zh.wikipedia.org/wiki/$1',
-                                       'iw_api' => '',
-                                       'iw_wikiid' => '',
-                                       'iw_local' => 1 ),
-                               array( 'iw_prefix' => 'es',
-                                       'iw_url' => 'http://es.wikipedia.org/wiki/$1',
-                                       'iw_api' => '',
-                                       'iw_wikiid' => '',
-                                       'iw_local' => 1 ),
-                               array( 'iw_prefix' => 'fr',
-                                       'iw_url' => 'http://fr.wikipedia.org/wiki/$1',
-                                       'iw_api' => '',
-                                       'iw_wikiid' => '',
-                                       'iw_local' => 1 ),
-                               array( 'iw_prefix' => 'ru',
-                                       'iw_url' => 'http://ru.wikipedia.org/wiki/$1',
-                                       '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 ),
                        __METHOD__
                );
 
-               # Clear the message cache
-               MessageCache::singleton()->clear();
-
                $user = User::newFromId( 0 );
                LinkCache::singleton()->clear(); # Avoids the odd failure at creating the nullRevision
 
@@ -270,6 +240,20 @@ class NewParserTest extends MediaWikiTestCase {
                                $this->db->timestamp( '20010115123500' ), $user
                        );
                }
+               $image = wfLocalFile( Title::makeTitle( NS_FILE, 'Foobar.svg' ) );
+               if ( !$this->db->selectField( 'image', '1', array( 'img_name' => $image->getName() ) ) ) {
+                       $image->recordUpload2( '', 'Upload of some lame SVG', 'Some lame SVG', array(
+                                       'size'        => 12345,
+                                       'width'       => 200,
+                                       'height'      => 200,
+                                       'bits'        => 24,
+                                       'media_type'  => MEDIATYPE_DRAWING,
+                                       'mime'        => 'image/svg+xml',
+                                       'metadata'    => serialize( array() ),
+                                       'sha1'        => wfBaseConvert( '', 16, 36, 31 ),
+                                       'fileExists'  => true
+                       ), $this->db->timestamp( '20010115123500' ), $user );
+               }
        }
 
        //ParserTest setup/teardown functions
@@ -333,10 +317,11 @@ class NewParserTest extends MediaWikiTestCase {
                        'wgEnableUploads' => self::getOptionValue( 'wgEnableUploads', $opts, true ),
                        'wgLanguageCode' => $lang,
                        'wgDBprefix' => $this->db->getType() != 'oracle' ? 'unittest_' : 'ut_',
-                       'wgRawHtml' => isset( $opts['rawhtml'] ),
+                       'wgRawHtml' => self::getOptionValue( 'wgRawHtml', $opts, false ),
                        'wgNamespacesWithSubpages' => array( NS_MAIN => isset( $opts['subpage'] ) ),
+                       'wgAllowExternalImages' => self::getOptionValue( 'wgAllowExternalImages', $opts, true ),
                        'wgMaxTocLevel' => $maxtoclevel,
-                       'wgUseTeX' => isset( $opts['math'] ),
+                       'wgUseTeX' => isset( $opts['math'] ) || isset( $opts['texvc'] ),
                        'wgMathDirectory' => $uploadDir . '/math',
                        'wgDefaultLanguageVariant' => $variant,
                        'wgLinkHolderBatchSize' => $linkHolderBatchSize,
@@ -375,6 +360,8 @@ class NewParserTest extends MediaWikiTestCase {
                }
 
                MagicWord::clearCache();
+
+               # The entries saved into RepoGroup cache with previous globals will be wrong.
                RepoGroup::destroySingleton();
                FileBackendGroup::destroySingleton();
 
@@ -384,9 +371,6 @@ class NewParserTest extends MediaWikiTestCase {
                # 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();
-               FileBackendGroup::destroySingleton();
                MessageCache::destroyInstance();
 
                return $context;
@@ -441,6 +425,19 @@ class NewParserTest extends MediaWikiTestCase {
                $backend->store( array(
                        'src' => "$IP/skins/monobook/headbg.jpg", 'dst' => "$base/local-public/0/09/Bad.jpg"
                ) );
+
+               // No helpful SVG file to copy, so make one ourselves
+               $tmpDir = wfTempDir();
+               $tempFsFile = new TempFSFile( "$tmpDir/Foobar.svg" );
+               $tempFsFile->autocollect(); // destroy file when $tempFsFile leaves scope
+               file_put_contents( "$tmpDir/Foobar.svg",
+                       '<?xml version="1.0" encoding="utf-8"?>' .
+                       '<svg xmlns="http://www.w3.org/2000/svg" width="200" height="200"><text>Foo</text></svg>' );
+
+               $backend->prepare( array( 'dir' => "$base/local-public/f/ff" ) );
+               $backend->quickStore( array(
+                       'src' => "$tmpDir/Foobar.svg", 'dst' => "$base/local-public/f/ff/Foobar.svg"
+               ) );
        }
 
        /**
@@ -453,9 +450,6 @@ class NewParserTest extends MediaWikiTestCase {
                foreach ( $this->savedGlobals as $var => $val ) {
                        $GLOBALS[$var] = $val;
                }
-
-               RepoGroup::destroySingleton();
-               LinkCache::singleton()->clear();
        }
 
        /**
@@ -467,7 +461,7 @@ class NewParserTest extends MediaWikiTestCase {
                }
 
                $backend = RepoGroup::singleton()->getLocalRepo()->getBackend();
-               if( $backend instanceof MockFileBackend ) {
+               if ( $backend instanceof MockFileBackend ) {
                        # In memory backend, so dont bother cleaning them up.
                        return;
                }
@@ -496,6 +490,14 @@ class NewParserTest extends MediaWikiTestCase {
 
                                "$base/local-public/0/09/Bad.jpg",
 
+                               "$base/local-public/f/ff/Foobar.svg",
+                               "$base/local-thumb/f/ff/Foobar.svg/180px-Foobar.svg.jpg",
+                               "$base/local-thumb/f/ff/Foobar.svg/270px-Foobar.svg.jpg",
+                               "$base/local-thumb/f/ff/Foobar.svg/360px-Foobar.svg.jpg",
+                               "$base/local-thumb/f/ff/Foobar.svg/langde-180px-Foobar.svg.jpg",
+                               "$base/local-thumb/f/ff/Foobar.svg/langde-270px-Foobar.svg.jpg",
+                               "$base/local-thumb/f/ff/Foobar.svg/langde-360px-Foobar.svg.jpg",
+
                                "$base/local-public/math/f/a/5/fa50b8b616463173474302ca3e63586b.png",
                        )
                );
@@ -579,6 +581,20 @@ class NewParserTest extends MediaWikiTestCase {
 
                $title = Title::newFromText( $titleText );
 
+               # Parser test requiring math. Make sure texvc is executable
+               # or just skip such tests.
+               if ( isset( $opts['math'] ) || isset( $opts['texvc'] ) ) {
+                       global $wgTexvc;
+
+                       if ( !isset( $wgTexvc ) ) {
+                               $this->markTestSkipped( "SKIPPED: \$wgTexvc is not set" );
+                       } elseif ( !is_executable( $wgTexvc ) ) {
+                               $this->markTestSkipped( "SKIPPED: texvc binary does not exist"
+                                       . " or is not executable.\n"
+                                       . "Current configuration is:\n\$wgTexvc = '$wgTexvc'" );
+                       }
+               }
+
                if ( isset( $opts['pst'] ) ) {
                        $out = $parser->preSaveTransform( $input, $title, $user, $options );
                } elseif ( isset( $opts['msg'] ) ) {