MediaWiki  1.27.2
MediaWikiParserTest.php
Go to the documentation of this file.
1 <?php
2 require_once __DIR__ . '/NewParserTest.php';
3 
14 
23  const CORE_ONLY = 1;
25  const NO_CORE = 2;
27  const WITH_ALL = 3; # CORE_ONLY | NO_CORE
28 
54  public static function suite( $flags = self::CORE_ONLY ) {
55  if ( is_string( $flags ) ) {
56  $flags = self::CORE_ONLY;
57  }
58  global $wgParserTestFiles, $IP;
59 
60  $mwTestDir = $IP . '/tests/';
61 
62  # Human friendly helpers
63  $wantsCore = ( $flags & self::CORE_ONLY );
64  $wantsRest = ( $flags & self::NO_CORE );
65 
66  # Will hold the .txt parser test files we will include
67  $filesToTest = [];
68 
69  # Filter out .txt files
70  foreach ( $wgParserTestFiles as $parserTestFile ) {
71  $isCore = ( 0 === strpos( $parserTestFile, $mwTestDir ) );
72 
73  if ( $isCore && $wantsCore ) {
74  self::debug( "included core parser tests: $parserTestFile" );
75  $filesToTest[] = $parserTestFile;
76  } elseif ( !$isCore && $wantsRest ) {
77  self::debug( "included non core parser tests: $parserTestFile" );
78  $filesToTest[] = $parserTestFile;
79  } else {
80  self::debug( "skipped parser tests: $parserTestFile" );
81  }
82  }
83  self::debug( 'parser tests files: '
84  . implode( ' ', $filesToTest ) );
85 
86  $suite = new PHPUnit_Framework_TestSuite;
87  $testList = [];
88  $counter = 0;
89  foreach ( $filesToTest as $fileName ) {
90  // Call the highest level directory the extension name.
91  // It may or may not actually be, but it should be close
92  // enough to cause there to be separate names for different
93  // things, which is good enough for our purposes.
94  $extensionName = basename( dirname( $fileName ) );
95  $testsName = $extensionName . '__' . basename( $fileName, '.txt' );
96  $escapedFileName = strtr( $fileName, [ "'" => "\\'", '\\' => '\\\\' ] );
97  $parserTestClassName = ucfirst( $testsName );
98 
99  // Official spec for class names: http://php.net/manual/en/language.oop5.basic.php
100  // Prepend 'ParserTest_' to be paranoid about it not starting with a number
101  $parserTestClassName = 'ParserTest_' .
102  preg_replace( '/[^a-zA-Z0-9_\x7f-\xff]/', '_', $parserTestClassName );
103 
104  if ( isset( $testList[$parserTestClassName] ) ) {
105  // If a conflict happens, gives a very unclear fatal.
106  // So as a last ditch effort to prevent that eventuality, if there
107  // is a conflict, append a number.
108  $counter++;
109  $parserTestClassName .= $counter;
110  }
111  $testList[$parserTestClassName] = true;
112  $parserTestClassDefinition = <<<EOT
119 class $parserTestClassName extends NewParserTest {
120  protected \$file = '$escapedFileName';
121 }
122 EOT;
123 
124  eval( $parserTestClassDefinition );
125  self::debug( "Adding test class $parserTestClassName" );
126  $suite->addTestSuite( $parserTestClassName );
127  }
128  return $suite;
129  }
135  protected static function debug( $msg ) {
136  return wfDebugLog( 'tests-parser', wfGetCaller() . ' ' . $msg );
137  }
138 }
static debug($msg)
Write $msg under log group 'tests-parser'.
$IP
Definition: WebStart.php:58
const NO_CORE
Include non core files as set in $wgParserTestFiles.
it s the revision text itself In either if gzip is the revision text is gzipped $flags
Definition: hooks.txt:2548
static suite($flags=self::CORE_ONLY)
Get a PHPUnit test suite of parser tests.
when a variable name is used in a it is silently declared as a new local masking the global
Definition: design.txt:93
const CORE_ONLY
Include files shipped with MediaWiki core.
wfDebugLog($logGroup, $text, $dest= 'all', array $context=[])
Send a line to a supplementary debug log file, if configured, or main debug log if not...
The UnitTest must be either a class that inherits from MediaWikiTestCase or a class that provides a p...
Although marked as a stub, can work independently.
const WITH_ALL
Include anything set via $wgParserTestFiles.
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
wfGetCaller($level=2)
Get the name of the function which called this function wfGetCaller( 1 ) is the function with the wfG...