Abstract and refactor Tidy support
[lhc/web/wiklou.git] / tests / phpunit / includes / parser / NewParserTest.php
index 3ce3e1f..0d2129b 100644 (file)
@@ -91,7 +91,7 @@ class NewParserTest extends MediaWikiTestCase {
                );
                $tmpGlobals['wgForeignFileRepos'] = array();
                $tmpGlobals['wgDefaultExternalStore'] = array();
-               $tmpGlobals['wgEnableParserCache'] = false;
+               $tmpGlobals['wgParserCacheType'] = CACHE_NONE;
                $tmpGlobals['wgCapitalLinks'] = true;
                $tmpGlobals['wgNoFollowLinks'] = true;
                $tmpGlobals['wgNoFollowDomainExceptions'] = array();
@@ -160,13 +160,10 @@ class NewParserTest extends MediaWikiTestCase {
                $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['wgTidyConfig'] = null;
                $tmpGlobals['wgUseTidy'] = false;
-               $tmpGlobals['wgAlwaysUseTidy'] = false;
                $tmpGlobals['wgDebugTidy'] = false;
-               $tmpGlobals['wgTidyConf'] = $IP . '/includes/tidy.conf';
+               $tmpGlobals['wgTidyConf'] = $IP . '/includes/tidy/tidy.conf';
                $tmpGlobals['wgTidyOpts'] = '';
                $tmpGlobals['wgTidyInternal'] = $this->tidySupport->isInternal();
 
@@ -188,6 +185,8 @@ class NewParserTest extends MediaWikiTestCase {
                $wgNamespaceAliases['Image'] = $this->savedWeirdGlobals['image_alias'];
                $wgNamespaceAliases['Image_talk'] = $this->savedWeirdGlobals['image_talk_alias'];
 
+               MWTidy::destroySingleton();
+
                // Restore backends
                RepoGroup::destroySingleton();
                FileBackendGroup::destroySingleton();
@@ -419,6 +418,7 @@ class NewParserTest extends MediaWikiTestCase {
                        'wgMathDirectory' => $uploadDir . '/math',
                        'wgDefaultLanguageVariant' => $variant,
                        'wgLinkHolderBatchSize' => $linkHolderBatchSize,
+                       'wgUseTidy' => isset( $opts['tidy'] ),
                );
 
                if ( $config ) {
@@ -456,6 +456,7 @@ class NewParserTest extends MediaWikiTestCase {
                        $GLOBALS[$var] = $val;
                }
 
+               MWTidy::destroySingleton();
                MagicWord::clearCache();
 
                # The entries saved into RepoGroup cache with previous globals will be wrong.
@@ -727,12 +728,21 @@ class NewParserTest extends MediaWikiTestCase {
                                        . "Current configuration is:\n\$wgTexvc = '$wgTexvc'" );
                        }
                }
+
                if ( isset( $opts['djvu'] ) ) {
                        if ( !$this->djVuSupport->isEnabled() ) {
                                $this->markTestSkipped( "SKIPPED: djvu binaries do not exist or are not executable.\n" );
                        }
                }
 
+               if ( isset( $opts['tidy'] ) ) {
+                       if ( !$this->tidySupport->isEnabled() ) {
+                               $this->markTestSkipped( "SKIPPED: tidy extension is not installed.\n" );
+                       } else {
+                               $options->setTidy( true );
+                       }
+               }
+
                if ( isset( $opts['pst'] ) ) {
                        $out = $parser->preSaveTransform( $input, $title, $user, $options );
                } elseif ( isset( $opts['msg'] ) ) {
@@ -753,12 +763,7 @@ class NewParserTest extends MediaWikiTestCase {
                        $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 );
-                               }
+                               $out = preg_replace( '/\s+$/', '', $out );
                        }
 
                        if ( isset( $opts['showtitle'] ) ) {
@@ -769,6 +774,14 @@ class NewParserTest extends MediaWikiTestCase {
                                $out = "$title\n$out";
                        }
 
+                       if ( isset( $opts['showindicators'] ) ) {
+                               $indicators = '';
+                               foreach ( $output->getIndicators() as $id => $content ) {
+                                       $indicators .= "$id=$content\n";
+                               }
+                               $out = $indicators . $out;
+                       }
+
                        if ( isset( $opts['ill'] ) ) {
                                $out = implode( ' ', $output->getLanguageLinks() );
                        } elseif ( isset( $opts['cat'] ) ) {