Merge "Show redirect fragments on Special:ListRedirects"
[lhc/web/wiklou.git] / tests / parser / ParserTestRunner.php
index 9dce73f..e578418 100644 (file)
@@ -34,6 +34,18 @@ use Wikimedia\TestingAccessWrapper;
  * @ingroup Testing
  */
 class ParserTestRunner {
+
+       /**
+        * MediaWiki core parser test files, paths
+        * will be prefixed with __DIR__ . '/'
+        *
+        * @var array
+        */
+       private static $coreTestFiles = [
+               'parserTests.txt',
+               'extraParserTests.txt',
+       ];
+
        /**
         * @var bool $useTemporaryTables Use temporary tables for the temporary database
         */
@@ -147,6 +159,43 @@ class ParserTestRunner {
                }
        }
 
+       /**
+        * Get list of filenames to extension and core parser tests
+        *
+        * @return array
+        */
+       public static function getParserTestFiles() {
+               global $wgParserTestFiles;
+
+               // Add core test files
+               $files = array_map( function ( $item ) {
+                       return __DIR__ . "/$item";
+               }, self::$coreTestFiles );
+
+               // Plus legacy global files
+               $files = array_merge( $files, $wgParserTestFiles );
+
+               // Auto-discover extension parser tests
+               $registry = ExtensionRegistry::getInstance();
+               foreach ( $registry->getAllThings() as $info ) {
+                       $dir = dirname( $info['path'] ) . '/tests/parser';
+                       if ( !file_exists( $dir ) ) {
+                               continue;
+                       }
+                       $dirIterator = new RecursiveIteratorIterator(
+                               new RecursiveDirectoryIterator( $dir )
+                       );
+                       foreach ( $dirIterator as $fileInfo ) {
+                               /** @var SplFileInfo $fileInfo */
+                               if ( substr( $fileInfo->getFilename(), -4 ) === '.txt' ) {
+                                       $files[] = $fileInfo->getPathname();
+                               }
+                       }
+               }
+
+               return array_unique( $files );
+       }
+
        public function getRecorder() {
                return $this->recorder;
        }
@@ -987,6 +1036,9 @@ class ParserTestRunner {
                $linkHolderBatchSize =
                        self::getOptionValue( 'wgLinkHolderBatchSize', $opts, 1000 );
 
+               // Default to fallback skin, but allow it to be overridden
+               $skin = self::getOptionValue( 'skin', $opts, 'fallback' );
+
                $setup = [
                        'wgEnableUploads' => self::getOptionValue( 'wgEnableUploads', $opts, true ),
                        'wgLanguageCode' => $langCode,
@@ -1003,6 +1055,8 @@ class ParserTestRunner {
                        // wgEnableMagicLinks={"ISBN":false, "PMID":false, "RFC":false}
                        'wgEnableMagicLinks' => self::getOptionValue( 'wgEnableMagicLinks', $opts, [] )
                                + [ 'ISBN' => true, 'PMID' => true, 'RFC' => true ],
+                       // Test with legacy encoding by default until HTML5 is very stable and default
+                       'wgFragmentMode' => [ 'legacy' ],
                ];
 
                if ( $config ) {
@@ -1056,7 +1110,13 @@ class ParserTestRunner {
                $context = RequestContext::getMain();
                $context->setUser( $user );
                $context->setLanguage( $lang );
-               $teardown[] = function () use ( $context ) {
+               // And the skin!
+               $oldSkin = $context->getSkin();
+               $skinFactory = MediaWikiServices::getInstance()->getSkinFactory();
+               $context->setSkin( $skinFactory->makeSkin( $skin ) );
+               $context->setOutput( new OutputPage( $context ) );
+               $setup['wgOut'] = $context->getOutput();
+               $teardown[] = function () use ( $context, $oldSkin ) {
                        // Clear language conversion tables
                        $wrapper = TestingAccessWrapper::newFromObject(
                                $context->getLanguage()->getConverter()
@@ -1065,6 +1125,8 @@ class ParserTestRunner {
                        // Reset context to the restored globals
                        $context->setUser( $GLOBALS['wgUser'] );
                        $context->setLanguage( $GLOBALS['wgContLang'] );
+                       $context->setSkin( $oldSkin );
+                       $context->setOutput( $GLOBALS['wgOut'] );
                };
 
                $teardown[] = $this->executeSetupSnippets( $setup );