Use 'rsvg-convert' binary rather than 'rsvg' everywhere
[lhc/web/wiklou.git] / tests / phpunit / includes / parser / NewParserTest.php
index 0499f88..713c32d 100644 (file)
@@ -36,6 +36,10 @@ class NewParserTest extends MediaWikiTestCase {
         * @var DjVuSupport
         */
        private $djVuSupport;
+       /**
+        * @var TidySupport
+        */
+       private $tidySupport;
 
        protected $file = false;
 
@@ -75,6 +79,7 @@ class NewParserTest extends MediaWikiTestCase {
                $tmpGlobals['wgExtensionAssetsPath'] = '/extensions';
                $tmpGlobals['wgStylePath'] = '/skins';
                $tmpGlobals['wgEnableUploads'] = true;
+               $tmpGlobals['wgUploadNavigationUrl'] = false;
                $tmpGlobals['wgThumbnailScriptPath'] = false;
                $tmpGlobals['wgLocalFileRepo'] = array(
                        'class' => 'LocalRepo',
@@ -95,8 +100,6 @@ class NewParserTest extends MediaWikiTestCase {
                $tmpGlobals['wgUseImageResize'] = true;
                $tmpGlobals['wgAllowExternalImages'] = true;
                $tmpGlobals['wgRawHtml'] = false;
-               $tmpGlobals['wgUseTidy'] = false;
-               $tmpGlobals['wgAlwaysUseTidy'] = false;
                $tmpGlobals['wgWellFormedXml'] = true;
                $tmpGlobals['wgAllowMicrodataAttributes'] = true;
                $tmpGlobals['wgExperimentalHtmlIds'] = false;
@@ -121,7 +124,7 @@ class NewParserTest extends MediaWikiTestCase {
                $tmpGlobals['wgFileExtensions'][] = 'svg';
                $tmpGlobals['wgSVGConverter'] = 'rsvg';
                $tmpGlobals['wgSVGConverters']['rsvg'] =
-                       '$path/rsvg-convert -w $width -h $height $input -o $output';
+                       '$path/rsvg-convert -w $width -h $height -o $output $input';
 
                if ( $GLOBALS['wgStyleDirectory'] === false ) {
                        $tmpGlobals['wgStyleDirectory'] = "$IP/skins";
@@ -153,8 +156,19 @@ class NewParserTest extends MediaWikiTestCase {
                # see https://gerrit.wikimedia.org/r/111390
                $tmpGlobals['wgExtraInterlanguageLinkPrefixes'] = array( 'mul' );
 
-               //DjVu support
+               // DjVu support
                $this->djVuSupport = new DjVuSupport();
+               // Tidy support
+               $this->tidySupport = new TidySupport();
+               // We always set 'wgUseTidy' to false when parsing, but certain
+               // test-running modes still use tidy if available, so ensure
+               // that the tidy-related options are all set to their defaults.
+               $tmpGlobals['wgUseTidy'] = false;
+               $tmpGlobals['wgAlwaysUseTidy'] = false;
+               $tmpGlobals['wgDebugTidy'] = false;
+               $tmpGlobals['wgTidyConf'] = $IP . '/includes/tidy.conf';
+               $tmpGlobals['wgTidyOpts'] = '';
+               $tmpGlobals['wgTidyInternal'] = $this->tidySupport->isInternal();
 
                $this->setMwGlobals( $tmpGlobals );
 
@@ -339,6 +353,9 @@ class NewParserTest extends MediaWikiTestCase {
        /**
         * Set up the global variables for a consistent environment for each test.
         * Ideally this should replace the global configuration entirely.
+        * @param array $opts
+        * @param string $config
+        * @return RequestContext
         */
        protected function setupGlobals( $opts = array(), $config = '' ) {
                global $wgFileBackends;
@@ -417,7 +434,7 @@ class NewParserTest extends MediaWikiTestCase {
                $this->savedGlobals = array();
 
                /** @since 1.20 */
-               wfRunHooks( 'ParserTestGlobals', array( &$settings ) );
+               Hooks::run( 'ParserTestGlobals', array( &$settings ) );
 
                $langObj = Language::factory( $lang );
                $settings['wgContLang'] = $langObj;
@@ -735,6 +752,14 @@ class NewParserTest extends MediaWikiTestCase {
                        $output = $parser->parse( $input, $title, $options, true, true, 1337 );
                        $output->setTOCEnabled( !isset( $opts['notoc'] ) );
                        $out = $output->getText();
+                       if ( isset( $opts['tidy'] ) ) {
+                               if ( !$this->tidySupport->isEnabled() ) {
+                                       $this->markTestSkipped( "SKIPPED: tidy extension is not installed.\n" );
+                               } else {
+                                       $out = MWTidy::tidy( $out );
+                                       $out = preg_replace( '/\s+$/', '', $out );
+                               }
+                       }
 
                        if ( isset( $opts['showtitle'] ) ) {
                                if ( $output->getTitleText() ) {
@@ -745,21 +770,19 @@ class NewParserTest extends MediaWikiTestCase {
                        }
 
                        if ( isset( $opts['ill'] ) ) {
-                               $out = $this->tidy( implode( ' ', $output->getLanguageLinks() ) );
+                               $out = implode( ' ', $output->getLanguageLinks() );
                        } elseif ( isset( $opts['cat'] ) ) {
                                $outputPage = $context->getOutput();
                                $outputPage->addCategoryLinks( $output->getCategories() );
                                $cats = $outputPage->getCategoryLinks();
 
                                if ( isset( $cats['normal'] ) ) {
-                                       $out = $this->tidy( implode( ' ', $cats['normal'] ) );
+                                       $out = implode( ' ', $cats['normal'] );
                                } else {
                                        $out = '';
                                }
                        }
                        $parser->mPreprocessor = null;
-
-                       $result = $this->tidy( $result );
                }
 
                $this->teardownGlobals();
@@ -852,6 +875,7 @@ class NewParserTest extends MediaWikiTestCase {
        /**
         * Get an input dictionary from a set of parser test files
         * @param array $filenames
+        * @return string
         */
        function getFuzzInput( $filenames ) {
                $dict = '';
@@ -870,6 +894,7 @@ class NewParserTest extends MediaWikiTestCase {
 
        /**
         * Get a memory usage breakdown
+        * @return array
         */
        function getMemoryBreakdown() {
                $memStats = array();
@@ -906,6 +931,7 @@ class NewParserTest extends MediaWikiTestCase {
        /**
         * Get a Parser object
         * @param Preprocessor $preprocessor
+        * @return Parser
         */
        function getParser( $preprocessor = null ) {
                global $wgParserConf;
@@ -913,7 +939,7 @@ class NewParserTest extends MediaWikiTestCase {
                $class = $wgParserConf['class'];
                $parser = new $class( array( 'preprocessorClass' => $preprocessor ) + $wgParserConf );
 
-               wfRunHooks( 'ParserTestParser', array( &$parser ) );
+               Hooks::run( 'ParserTestParser', array( &$parser ) );
 
                return $parser;
        }
@@ -963,26 +989,10 @@ class NewParserTest extends MediaWikiTestCase {
 
        //Various "cleanup" functions
 
-       /**
-        * Run the "tidy" command on text if the $wgUseTidy
-        * global is true
-        *
-        * @param string $text The text to tidy
-        * @return string
-        */
-       protected function tidy( $text ) {
-               global $wgUseTidy;
-
-               if ( $wgUseTidy ) {
-                       $text = MWTidy::tidy( $text );
-               }
-
-               return $text;
-       }
-
        /**
         * Remove last character if it is a newline
         * @param string $s
+        * @return string
         */
        public function removeEndingNewline( $s ) {
                if ( substr( $s, -1 ) === "\n" ) {
@@ -1067,6 +1077,7 @@ class NewParserTest extends MediaWikiTestCase {
         * @param string $key Name of option val to retrieve
         * @param array $opts Options array to look in
         * @param mixed $default Default value returned if not found
+        * @return mixed
         */
        protected static function getOptionValue( $key, $opts, $default ) {
                $key = strtolower( $key );