MediaWiki  1.29.1
ParserTestTopLevelSuite.php
Go to the documentation of this file.
1 <?php
2 use Wikimedia\ScopedCallback;
3 
13 class ParserTestTopLevelSuite extends PHPUnit_Framework_TestSuite {
15  private $ptRunner;
16 
19 
28  const CORE_ONLY = 1;
30  const NO_CORE = 2;
32  const WITH_ALL = 3; # CORE_ONLY | NO_CORE
33 
59  public static function suite( $flags = self::CORE_ONLY ) {
60  return new self( $flags );
61  }
62 
63  function __construct( $flags ) {
64  parent::__construct();
65 
66  $this->ptRecorder = new PhpunitTestRecorder;
67  $this->ptRunner = new ParserTestRunner( $this->ptRecorder );
68 
69  if ( is_string( $flags ) ) {
71  }
72  global $wgParserTestFiles, $IP;
73 
74  $mwTestDir = $IP . '/tests/';
75 
76  # Human friendly helpers
77  $wantsCore = ( $flags & self::CORE_ONLY );
78  $wantsRest = ( $flags & self::NO_CORE );
79 
80  # Will hold the .txt parser test files we will include
81  $filesToTest = [];
82 
83  # Filter out .txt files
84  foreach ( $wgParserTestFiles as $parserTestFile ) {
85  $isCore = ( 0 === strpos( $parserTestFile, $mwTestDir ) );
86 
87  if ( $isCore && $wantsCore ) {
88  self::debug( "included core parser tests: $parserTestFile" );
89  $filesToTest[] = $parserTestFile;
90  } elseif ( !$isCore && $wantsRest ) {
91  self::debug( "included non core parser tests: $parserTestFile" );
92  $filesToTest[] = $parserTestFile;
93  } else {
94  self::debug( "skipped parser tests: $parserTestFile" );
95  }
96  }
97  self::debug( 'parser tests files: '
98  . implode( ' ', $filesToTest ) );
99 
100  $testList = [];
101  $counter = 0;
102  foreach ( $filesToTest as $fileName ) {
103  // Call the highest level directory the extension name.
104  // It may or may not actually be, but it should be close
105  // enough to cause there to be separate names for different
106  // things, which is good enough for our purposes.
107  $extensionName = basename( dirname( $fileName ) );
108  $testsName = $extensionName . '__' . basename( $fileName, '.txt' );
109  $parserTestClassName = ucfirst( $testsName );
110 
111  // Official spec for class names: https://secure.php.net/manual/en/language.oop5.basic.php
112  // Prepend 'ParserTest_' to be paranoid about it not starting with a number
113  $parserTestClassName = 'ParserTest_' .
114  preg_replace( '/[^a-zA-Z0-9_\x7f-\xff]/', '_', $parserTestClassName );
115 
116  if ( isset( $testList[$parserTestClassName] ) ) {
117  // If there is a conflict, append a number.
118  $counter++;
119  $parserTestClassName .= $counter;
120  }
121  $testList[$parserTestClassName] = true;
122 
123  // Previously we actually created a class here, with eval(). We now
124  // just override the name.
125 
126  self::debug( "Adding test class $parserTestClassName" );
127  $this->addTest( new ParserTestFileSuite(
128  $this->ptRunner, $parserTestClassName, $fileName ) );
129  }
130  }
131 
132  public function setUp() {
133  wfDebug( __METHOD__ );
134  $db = wfGetDB( DB_MASTER );
135  $type = $db->getType();
136  $prefix = $type === 'oracle' ?
138  MediaWikiTestCase::setupTestDB( $db, $prefix );
139  $teardown = $this->ptRunner->setDatabase( $db );
140  $teardown = $this->ptRunner->setupUploads( $teardown );
141  $this->ptTeardownScope = $teardown;
142  }
143 
144  public function tearDown() {
145  wfDebug( __METHOD__ );
146  if ( $this->ptTeardownScope ) {
147  ScopedCallback::consume( $this->ptTeardownScope );
148  }
149  }
150 
155  protected static function debug( $msg ) {
156  return wfDebugLog( 'tests-parser', wfGetCaller() . ' ' . $msg );
157  }
158 }
ParserTestTopLevelSuite\debug
static debug( $msg)
Write $msg under log group 'tests-parser'.
Definition: ParserTestTopLevelSuite.php:155
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
ParserTestTopLevelSuite
The UnitTest must be either a class that inherits from MediaWikiTestCase or a class that provides a p...
Definition: ParserTestTopLevelSuite.php:13
$type
do that in ParserLimitReportFormat instead use this to modify the parameters of the image and a DIV can begin in one section and end in another Make sure your code can handle that case gracefully See the EditSectionClearerLink extension for an example zero but section is usually empty its values are the globals values before the output is cached my talk my contributions etc etc otherwise the built in rate limiting checks are if enabled allows for interception of redirect as a string mapping parameter names to values & $type
Definition: hooks.txt:2536
ParserTestTopLevelSuite\$ptTeardownScope
ScopedCallback $ptTeardownScope
Definition: ParserTestTopLevelSuite.php:18
wfDebugLog
wfDebugLog( $logGroup, $text, $dest='all', array $context=[])
Send a line to a supplementary debug log file, if configured, or main debug log if not.
Definition: GlobalFunctions.php:1092
ParserTestTopLevelSuite\suite
static suite( $flags=self::CORE_ONLY)
Get a PHPUnit test suite of parser tests.
Definition: ParserTestTopLevelSuite.php:59
php
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
ParserTestTopLevelSuite\tearDown
tearDown()
Definition: ParserTestTopLevelSuite.php:144
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:3060
ParserTestTopLevelSuite\CORE_ONLY
const CORE_ONLY
Include files shipped with MediaWiki core.
Definition: ParserTestTopLevelSuite.php:28
$IP
$IP
Definition: update.php:3
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
DB_MASTER
const DB_MASTER
Definition: defines.php:26
wfDebug
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
Definition: GlobalFunctions.php:999
ParserTestTopLevelSuite\WITH_ALL
const WITH_ALL
Include anything set via $wgParserTestFiles.
Definition: ParserTestTopLevelSuite.php:32
ParserTestTopLevelSuite\__construct
__construct( $flags)
Definition: ParserTestTopLevelSuite.php:63
MediaWikiTestCase\setupTestDB
static setupTestDB(Database $db, $prefix)
Creates an empty skeleton of the wiki database by cloning its structure to equivalent tables using th...
Definition: MediaWikiTestCase.php:1155
ParserTestFileSuite
This is the suite class for running tests within a single .txt source file.
Definition: ParserTestFileSuite.php:8
ParserTestTopLevelSuite\$ptRunner
ParserTestRunner $ptRunner
Definition: ParserTestTopLevelSuite.php:15
MediaWikiTestCase\DB_PREFIX
const DB_PREFIX
Table name prefixes.
Definition: MediaWikiTestCase.php:102
MediaWikiTestCase\ORA_DB_PREFIX
const ORA_DB_PREFIX
Definition: MediaWikiTestCase.php:103
as
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
ParserTestTopLevelSuite\NO_CORE
const NO_CORE
Include non core files as set in $wgParserTestFiles.
Definition: ParserTestTopLevelSuite.php:30
PhpunitTestRecorder
Definition: PhpunitTestRecorder.php:3
wfGetCaller
wfGetCaller( $level=2)
Get the name of the function which called this function wfGetCaller( 1 ) is the function with the wfG...
Definition: GlobalFunctions.php:1561
ParserTestTopLevelSuite\setUp
setUp()
Definition: ParserTestTopLevelSuite.php:132
$flags
it s the revision text itself In either if gzip is the revision text is gzipped $flags
Definition: hooks.txt:2749