* Parser test suite files to be run by parserTests.php when no specific
* filename is passed to it.
*
- * Extensions may add their own tests to this array, or site-local tests
- * may be added via LocalSettings.php
+ * Extensions using extension.json will have any *.txt file in a
+ * tests/parser/ directory automatically run.
+ *
+ * Core tests can be added to ParserTestRunner::$coreTestFiles.
*
* Use full paths.
+ *
+ * @deprecated since 1.30
*/
-$wgParserTestFiles = [
- "$IP/tests/parser/parserTests.txt",
- "$IP/tests/parser/extraParserTests.txt"
-];
+$wgParserTestFiles = [];
/**
* Allow running of javascript test suites via [[Special:JavaScriptTest]] (such as QUnit).
* @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
*/
}
}
+ /**
+ * 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;
}
}
public function execute() {
- global $wgParserTestFiles, $wgDBtype;
+ global $wgDBtype;
// Cases of weird db corruption were encountered when running tests on earlyish
// versions of SQLite
}
// Default parser tests and any set from extensions or local config
- $files = $this->getOption( 'file', $wgParserTestFiles );
+ $files = $this->getOption( 'file', ParserTestRunner::getParserTestFiles() );
$norm = $this->hasOption( 'norm' ) ? explode( ',', $this->getOption( 'norm' ) ) : [];
if ( is_string( $flags ) ) {
$flags = self::CORE_ONLY;
}
- global $wgParserTestFiles, $IP;
+ global $IP;
$mwTestDir = $IP . '/tests/';
$filesToTest = [];
# Filter out .txt files
- foreach ( $wgParserTestFiles as $parserTestFile ) {
+ $files = ParserTestRunner::getParserTestFiles();
+ foreach ( $files as $parserTestFile ) {
$isCore = ( 0 === strpos( $parserTestFile, $mwTestDir ) );
if ( $isCore && $wantsCore ) {