Merge "Language: s/error_log/wfWarn/"
[lhc/web/wiklou.git] / tests / parser / parserTest.inc
index a8d26d6..a9df683 100644 (file)
@@ -69,6 +69,11 @@ class ParserTest {
         */
        private $djVuSupport;
 
+       /**
+        * @var TidySupport
+        */
+       private $tidySupport;
+
        private $maxFuzzTestLength = 300;
        private $fuzzSeed = 0;
        private $memoryLimit = 50;
@@ -137,6 +142,10 @@ class ParserTest {
                $this->runParsoid = isset( $options['run-parsoid'] );
 
                $this->djVuSupport = new DjVuSupport();
+               $this->tidySupport = new TidySupport();
+               if ( !$this->tidySupport->isEnabled() ) {
+                       echo "Warning: tidy is not installed, skipping some tests\n";
+               }
 
                $this->hooks = array();
                $this->functionHooks = array();
@@ -323,6 +332,7 @@ class ParserTest {
         * Remove last character if it is a newline
         * @group utility
         * @param string $s
+        * @return string
         */
        public static function chomp( $s ) {
                if ( substr( $s, -1 ) === "\n" ) {
@@ -407,6 +417,7 @@ class ParserTest {
        /**
         * Get an input dictionary from a set of parser test files
         * @param array $filenames
+        * @return string
         */
        function getFuzzInput( $filenames ) {
                $dict = '';
@@ -429,6 +440,7 @@ class ParserTest {
 
        /**
         * Get a memory usage breakdown
+        * @return array
         */
        function getMemoryBreakdown() {
                $memStats = array();
@@ -611,6 +623,13 @@ class ParserTest {
                        $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() ) {
+                                       return $this->showSkipped();
+                               }
+                               $out = MWTidy::tidy( $out );
+                               $out = preg_replace( '/\s+$/', '', $out );
+                       }
 
                        if ( isset( $opts['showtitle'] ) ) {
                                if ( $output->getTitleText() ) {
@@ -621,20 +640,18 @@ class ParserTest {
                        }
 
                        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 = '';
                                }
                        }
-
-                       $result = $this->tidy( $result );
                }
 
                $this->teardownGlobals();
@@ -649,6 +666,7 @@ class ParserTest {
        /**
         * Refactored in 1.22 to use ParserTestResult
         * @param ParserTestResult $testResult
+        * @return bool
         */
        function showTestResult( ParserTestResult $testResult ) {
                if ( $testResult->isSuccess() ) {
@@ -665,6 +683,7 @@ class ParserTest {
         * @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
         */
        private static function getOptionValue( $key, $opts, $default ) {
                $key = strtolower( $key );
@@ -768,8 +787,11 @@ class ParserTest {
         * Ideally this should replace the global configuration entirely.
         * @param string $opts
         * @param string $config
+        * @return RequestContext
         */
        private function setupGlobals( $opts = '', $config = '' ) {
+               global $IP;
+
                # Find out values for some special options.
                $lang =
                        self::getOptionValue( 'language', $opts, 'en' );
@@ -833,7 +855,6 @@ class ParserTest {
                        'wgLocaltimezone' => 'UTC',
                        'wgAllowExternalImages' => self::getOptionValue( 'wgAllowExternalImages', $opts, true ),
                        'wgThumbLimits' => array( self::getOptionValue( 'thumbsize', $opts, 180 ) ),
-                       'wgUseTidy' => false,
                        'wgDefaultLanguageVariant' => $variant,
                        'wgVariantArticlePath' => false,
                        'wgGroupPermissions' => array( '*' => array(
@@ -849,13 +870,22 @@ class ParserTest {
                        'wgLinkHolderBatchSize' => $linkHolderBatchSize,
                        'wgExperimentalHtmlIds' => false,
                        'wgExternalLinkTarget' => false,
-                       'wgAlwaysUseTidy' => false,
                        'wgHtml5' => true,
                        'wgWellFormedXml' => true,
                        'wgAllowMicrodataAttributes' => true,
                        'wgAdaptiveMessageCache' => true,
                        'wgDisableLangConversion' => false,
                        'wgDisableTitleConversion' => false,
+                       // Tidy options.
+                       // 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.
+                       'wgUseTidy' => false,
+                       'wgAlwaysUseTidy' => false,
+                       'wgDebugTidy' => false,
+                       'wgTidyConf' => $IP . '/includes/tidy.conf',
+                       'wgTidyOpts' => '',
+                       'wgTidyInternal' => $this->tidySupport->isInternal(),
                );
 
                if ( $config ) {
@@ -905,6 +935,7 @@ class ParserTest {
        /**
         * List of temporary tables to create, without prefix.
         * Some of these probably aren't necessary.
+        * @return array
         */
        private function listTables() {
                $tables = array( 'user', 'user_properties', 'user_former_groups', 'page', 'page_restrictions',
@@ -1371,7 +1402,7 @@ class ParserTest {
        /**
         * Print a skipped message.
         *
-        * @return boolean
+        * @return bool
         */
        protected function showSkipped() {
                if ( $this->showProgress ) {
@@ -1565,23 +1596,6 @@ class ParserTest {
                return true;
        }
 
-       /**
-        * Run the "tidy" command on text if the $wgUseTidy
-        * global is true
-        *
-        * @param string $text The text to tidy
-        * @return string
-        */
-       private function tidy( $text ) {
-               global $wgUseTidy;
-
-               if ( $wgUseTidy ) {
-                       $text = MWTidy::tidy( $text );
-               }
-
-               return $text;
-       }
-
        private function wellFormed( $text ) {
                $html =
                        Sanitizer::hackDocType() .