Merge "DifferenceEngine: Remove broken comment"
[lhc/web/wiklou.git] / tests / phpunit / includes / parser / NewParserTest.php
index 8cee07b..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;
@@ -102,6 +107,10 @@ class NewParserTest extends MediaWikiTestCase {
 
                $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,6 +122,8 @@ class NewParserTest extends MediaWikiTestCase {
                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';
@@ -149,50 +160,9 @@ class NewParserTest extends MediaWikiTestCase {
 
        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 ),
@@ -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,
@@ -440,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"
+               ) );
        }
 
        /**
@@ -492,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",
                        )
                );
@@ -575,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'] ) ) {