MediaWiki REL1_32
|
Public Member Functions | |
__construct (TestRecorder $recorder, $options=[]) | |
addArticles ( $articles) | |
Add articles to the test DB. | |
getParser ( $preprocessor=null) | |
Get a Parser object. | |
getRecorder () | |
isSetupDone ( $funcName) | |
Determine whether a particular setup function has been run. | |
meetsRequirements ( $requirements) | |
Determine whether the current parser has the hooks registered in it that are required by a file read by TestFileReader. | |
perTestSetup ( $test, $nextTeardown=null) | |
Do any required setup which is dependent on test options. | |
requireFunctionHook ( $name) | |
Check if a function hook is installed. | |
requireHook ( $name) | |
Check if a hook is installed. | |
requireTransparentHook ( $name) | |
Check if a transparent tag hook is installed. | |
runTest ( $test) | |
Run a given wikitext input through a freshly-constructed wiki parser, and compare the output against the expected results. | |
runTests ( $testFileInfo) | |
Run the tests from a single file. | |
runTestsFromFiles ( $filenames) | |
Run a series of tests listed in the given text files. | |
setDatabase (IDatabase $db) | |
setupDatabase ( $nextTeardown=null) | |
Set up temporary DB tables. | |
setupUploads ( $nextTeardown=null) | |
Add data about uploads to the new test DB, and set up the upload directory. | |
staticSetup ( $nextTeardown=null) | |
Do any setup which can be done once for all tests, independent of test options, except for database setup. | |
Static Public Member Functions | |
static | chomp ( $s) |
Remove last character if it is a newline. | |
static | getParserTestFiles () |
Get list of filenames to extension and core parser tests. | |
Protected Member Functions | |
checkSetupDone ( $funcName, $funcName2=null) | |
Ensure a given setup stage has been done, throw an exception if it has not. | |
createRepoGroup () | |
Create a RepoGroup object appropriate for the current configuration. | |
createTeardownObject ( $teardown, $nextTeardown=null) | |
Take a setup array in the same format as the one given to executeSetupSnippets(), and return a ScopedCallback which, when consumed, executes the snippets in the setup array in reverse order. | |
executeSetupSnippets ( $setup) | |
Execute an array in which elements with integer keys are taken to be callable objects, and other elements are taken to be global variable set operations, with the key giving the variable name and the value giving the new global variable value. | |
markSetupDone ( $funcName) | |
Set a setupDone flag to indicate that setup has been done, and return the teardown closure. | |
Private Member Functions | |
addArticle ( $name, $text, $file, $line) | |
Insert a temporary test article. | |
appendNamespaceSetup (&$setup, &$teardown) | |
cleanupOption ( $opt) | |
deleteFiles ( $files) | |
Delete the specified files and their parent directories. | |
getFakeTimestamp () | |
Fake constant timestamp to make sure time-related parser functions give a persistent value. | |
listTables () | |
List of temporary tables to create, without prefix. | |
parseOptions ( $instring) | |
Given the options string, return an associative array of options. | |
resetTitleServices () | |
Reset the Title-related services that need resetting for each test. | |
setupInterwikis () | |
Insert hardcoded interwiki in the lookup table. | |
setupUploadBackend () | |
Upload test files to the backend created by createRepoGroup(). | |
teardownDatabase () | |
Helper for database teardown, called from the teardown closure. | |
teardownUploadBackend () | |
Remove the dummy uploads directory. | |
Static Private Member Functions | |
static | getOptionValue ( $key, $opts, $default) |
Use a regex to find out the value of an option. | |
Private Attributes | |
Database | $db |
Our connection to the database. | |
CloneDatabase | $dbClone |
Database clone helper. | |
bool | $disableSaveParse |
Disable parse on article insertion. | |
string null | $fileBackendName |
The name of the file backend to use, or null to use MockFileBackend. | |
bool | $keepUploads |
Reuse upload directory. | |
array | $normalizationFunctions = [] |
A list of normalization functions to apply to the expected and actual output. | |
TestRecorder | $recorder |
string | $regex |
A complete regex for filtering tests. | |
bool | $runDisabled |
Run disabled parser tests. | |
bool | $runParsoid |
Run tests intended only for parsoid. | |
$setupDone | |
TidyDriverBase | $tidyDriver = null |
TidySupport | $tidySupport |
string null | $uploadDir = null |
The upload directory, or null to not set up an upload directory. | |
$useTemporaryTables = true | |
Static Private Attributes | |
static array | $coreTestFiles |
MediaWiki core parser test files, paths will be prefixed with DIR . | |
Definition at line 37 of file ParserTestRunner.php.
ParserTestRunner::__construct | ( | TestRecorder | $recorder, |
$options = [] ) |
TestRecorder | $recorder | |
array | $options |
Definition at line 147 of file ParserTestRunner.php.
References $options, $recorder, and TestRecorder\warning().
|
private |
Insert a temporary test article.
string | $name | The title, including any prefix |
string | $text | The article text |
string | $file | The input file name |
int | string | $line | The input line number, for reporting errors |
Exception | |
MWException |
Definition at line 1673 of file ParserTestRunner.php.
References $content, chomp(), EDIT_INTERNAL, EDIT_NEW, executeSetupSnippets(), NS_FILE, Revision\RAW, RepoGroup\singleton(), and wfDebug().
Referenced by addArticles().
ParserTestRunner::addArticles | ( | $articles | ) |
Add articles to the test DB.
array | $articles | Article info array from TestFileReader |
Definition at line 1623 of file ParserTestRunner.php.
References $lang, $services, addArticle(), appendNamespaceSetup(), and executeSetupSnippets().
Referenced by runTests().
|
private |
Definition at line 402 of file ParserTestRunner.php.
Referenced by addArticles(), and staticSetup().
|
protected |
Ensure a given setup stage has been done, throw an exception if it has not.
string | $funcName | |
string | null | $funcName2 |
Definition at line 549 of file ParserTestRunner.php.
References wfGetCaller().
Referenced by perTestSetup(), runTests(), setupUploads(), and teardownDatabase().
|
static |
Remove last character if it is a newline.
string | $s |
Definition at line 671 of file ParserTestRunner.php.
References $s.
Referenced by addArticle(), and TestFileReader\execute().
|
private |
Definition at line 1052 of file ParserTestRunner.php.
References $opt.
|
protected |
Create a RepoGroup object appropriate for the current configuration.
Definition at line 423 of file ParserTestRunner.php.
References $fileBackendName, $wgFileBackends, wfTempDir(), and wfWikiID().
Referenced by staticSetup().
|
protected |
Take a setup array in the same format as the one given to executeSetupSnippets(), and return a ScopedCallback which, when consumed, executes the snippets in the setup array in reverse order.
This is used to create "teardown objects" for the public API.
array | $teardown | The snippet array |
ScopedCallback | null | $nextTeardown | A ScopedCallback to consume |
Definition at line 514 of file ParserTestRunner.php.
References executeSetupSnippets().
Referenced by perTestSetup(), setupDatabase(), setupUploads(), and staticSetup().
|
private |
Delete the specified files and their parent directories.
array | $files | File backend URIs mwstore://... |
Definition at line 1599 of file ParserTestRunner.php.
References FileBackend\parentStoragePath(), and RepoGroup\singleton().
Referenced by teardownUploadBackend().
|
protected |
Execute an array in which elements with integer keys are taken to be callable objects, and other elements are taken to be global variable set operations, with the key giving the variable name and the value giving the new global variable value.
A closure is returned which, when executed, sets the global variables back to the values they had before this function was called.
array | $setup |
Definition at line 487 of file ParserTestRunner.php.
References $GLOBALS, $name, $value, and executeSetupSnippets().
Referenced by addArticle(), addArticles(), createTeardownObject(), executeSetupSnippets(), perTestSetup(), and staticSetup().
|
private |
Fake constant timestamp to make sure time-related parser functions give a persistent value.
Definition at line 1798 of file ParserTestRunner.php.
Referenced by runTest(), and staticSetup().
|
staticprivate |
Use a regex to find out the value of an option.
string | $key | Name of option val to retrieve |
array | $opts | Options array to look in |
mixed | $default | Default value returned if not found |
Definition at line 963 of file ParserTestRunner.php.
Referenced by perTestSetup().
ParserTestRunner::getParser | ( | $preprocessor = null | ) |
Get a Parser object.
string | null | $preprocessor |
Definition at line 805 of file ParserTestRunner.php.
References $parser, $wgParserConf, and ParserTestParserHook\setup().
Referenced by runTest().
|
static |
Get list of filenames to extension and core parser tests.
Definition at line 193 of file ParserTestRunner.php.
References $coreTestFiles, $name, $wgParserTestFiles, and ExtensionRegistry\getInstance().
Referenced by ParserTestTopLevelSuite\__construct(), ParserTestsMaintenance\execute(), and ParserEditTests\setupFileData().
ParserTestRunner::getRecorder | ( | ) |
Definition at line 230 of file ParserTestRunner.php.
References $recorder.
ParserTestRunner::isSetupDone | ( | $funcName | ) |
Determine whether a particular setup function has been run.
string | $funcName |
Definition at line 564 of file ParserTestRunner.php.
|
private |
List of temporary tables to create, without prefix.
Some of these probably aren't necessary.
Definition at line 1216 of file ParserTestRunner.php.
References $tables, $wgActorTableSchemaMigrationStage, $wgCommentTableSchemaMigrationStage, MIGRATION_WRITE_BOTH, and SCHEMA_COMPAT_WRITE_NEW.
Referenced by setupDatabase(), and teardownDatabase().
|
protected |
Set a setupDone flag to indicate that setup has been done, and return the teardown closure.
If the flag was already set, throw an exception.
string | $funcName | The setup function name |
Definition at line 533 of file ParserTestRunner.php.
Referenced by perTestSetup(), setupDatabase(), setupUploads(), and staticSetup().
ParserTestRunner::meetsRequirements | ( | $requirements | ) |
Determine whether the current parser has the hooks registered in it that are required by a file read by TestFileReader.
array | $requirements |
Definition at line 736 of file ParserTestRunner.php.
References requireFunctionHook(), requireHook(), and requireTransparentHook().
Referenced by runTests().
|
private |
Given the options string, return an associative array of options.
string | $instring |
Definition at line 980 of file ParserTestRunner.php.
References $matches, and $regex.
Referenced by perTestSetup(), and runTest().
ParserTestRunner::perTestSetup | ( | $test, | |
$nextTeardown = null ) |
Do any required setup which is dependent on test options.
array | $test | Test info supplied by TestFileReader |
callable | null | $nextTeardown |
Definition at line 1076 of file ParserTestRunner.php.
References $context, $GLOBALS, $lang, $line, $tidyDriver, $user, $value, checkSetupDone(), createTeardownObject(), MWTidy\destroySingleton(), executeSetupSnippets(), MWTidy\factory(), getOptionValue(), list, markSetupDone(), parseOptions(), resetTitleServices(), MWTidy\setInstance(), User\setOption(), and true.
Referenced by runTest().
ParserTestRunner::requireFunctionHook | ( | $name | ) |
Check if a function hook is installed.
string | $name |
Definition at line 1757 of file ParserTestRunner.php.
References $wgParser.
Referenced by meetsRequirements().
ParserTestRunner::requireHook | ( | $name | ) |
Check if a hook is installed.
string | $name |
Definition at line 1738 of file ParserTestRunner.php.
References $wgParser.
Referenced by meetsRequirements().
ParserTestRunner::requireTransparentHook | ( | $name | ) |
Check if a transparent tag hook is installed.
string | $name |
Definition at line 1777 of file ParserTestRunner.php.
References $wgParser.
Referenced by meetsRequirements().
|
private |
Reset the Title-related services that need resetting for each test.
Definition at line 657 of file ParserTestRunner.php.
References $services.
Referenced by perTestSetup(), and staticSetup().
ParserTestRunner::runTest | ( | $test | ) |
Run a given wikitext input through a freshly-constructed wiki parser, and compare the output against the expected results.
Prints status and explanatory messages to stdout.
staticSetup() and setupWikiData() must be called before this function is entered.
array | $test | The test parameters:
|
Definition at line 832 of file ParserTestRunner.php.
References $content, $context, $options, $out, $output, $parser, $section, Linker\formatComment(), getFakeTimestamp(), getParser(), ParserTestResultNormalizer\normalize(), parseOptions(), perTestSetup(), and wfDebug().
Referenced by runTests().
ParserTestRunner::runTests | ( | $testFileInfo | ) |
Run the tests from a single file.
staticSetup() and setupDatabase() must have been called already.
array | $testFileInfo | Parsed file info returned by TestFileReader |
Definition at line 763 of file ParserTestRunner.php.
References addArticles(), checkSetupDone(), meetsRequirements(), and runTest().
Referenced by runTestsFromFiles().
ParserTestRunner::runTestsFromFiles | ( | $filenames | ) |
Run a series of tests listed in the given text files.
Each test consists of a brief description, wikitext input, and the expected HTML output.
Prints status updates on stdout and counts up the total number and percentage of passed tests.
Handles all setup and teardown.
array | $filenames | Array of strings |
Definition at line 692 of file ParserTestRunner.php.
References $e, TestFileReader\read(), runTests(), setupDatabase(), setupUploads(), and staticSetup().
ParserTestRunner::setDatabase | ( | IDatabase | $db | ) |
Definition at line 1253 of file ParserTestRunner.php.
References $db.
ParserTestRunner::setupDatabase | ( | $nextTeardown = null | ) |
Set up temporary DB tables.
For best performance, call this once only for all tests. However, it can be called at the start of each test if more isolation is desired.
Do not call this function from a MediaWikiTestCase subclass, since MediaWikiTestCase does its own DB setup. Instead use setDatabase().
ScopedCallback | null | $nextTeardown | The next teardown object |
Definition at line 1275 of file ParserTestRunner.php.
References $wgDBprefix, CloneDatabase\changePrefix(), createTeardownObject(), DB_MASTER, listTables(), markSetupDone(), teardownDatabase(), and wfGetDB().
Referenced by runTestsFromFiles().
|
private |
Insert hardcoded interwiki in the lookup table.
This function insert a set of well known interwikis that are used in the parser tests. They can be considered has fixtures are injected in the interwiki cache by using the 'InterwikiLoadPrefix' hook. Since we are not interested in looking up interwikis in the database, the hook completely replace the existing mechanism (hook returns false).
Definition at line 579 of file ParserTestRunner.php.
Referenced by staticSetup().
|
private |
Upload test files to the backend created by createRepoGroup().
Definition at line 1525 of file ParserTestRunner.php.
References $base, $IP, RepoGroup\singleton(), and teardownUploadBackend().
Referenced by setupUploads().
ParserTestRunner::setupUploads | ( | $nextTeardown = null | ) |
Add data about uploads to the new test DB, and set up the upload directory.
This should be called after either setDatabase() or setupDatabase().
ScopedCallback | null | $nextTeardown | The next teardown object |
Definition at line 1341 of file ParserTestRunner.php.
References $image, checkSetupDone(), User\createNew(), createTeardownObject(), markSetupDone(), MEDIATYPE_AUDIO, MEDIATYPE_BITMAP, MEDIATYPE_DRAWING, MEDIATYPE_VIDEO, NS_FILE, serialize(), setupUploadBackend(), and wfLocalFile().
Referenced by runTestsFromFiles().
ParserTestRunner::staticSetup | ( | $nextTeardown = null | ) |
Do any setup which can be done once for all tests, independent of test options, except for database setup.
Public setup functions in this class return a ScopedCallback object. When this object is destroyed by going out of scope, teardown of the corresponding test setup is performed.
Teardown objects may be chained by passing a ScopedCallback from a previous setup stage as the $nextTeardown parameter. This enforces the convention that teardown actions are taken in reverse order to the corresponding setup actions. When $nextTeardown is specified, a ScopedCallback will be returned which first tears down the current setup stage, and then tears down the previous setup stage which was specified by $nextTeardown.
ScopedCallback | null | $nextTeardown |
Definition at line 253 of file ParserTestRunner.php.
References $parser, $services, $wgObjectCaches, appendNamespaceSetup(), CACHE_DB, createRepoGroup(), createTeardownObject(), RepoGroup\destroySingleton(), LockManagerGroup\destroySingletons(), executeSetupSnippets(), getFakeTimestamp(), markSetupDone(), resetTitleServices(), RepoGroup\setSingleton(), and setupInterwikis().
Referenced by runTestsFromFiles().
|
private |
Helper for database teardown, called from the teardown closure.
Destroy the database clone and fix up some things that CloneDatabase doesn't fix.
Definition at line 1488 of file ParserTestRunner.php.
References $tables, checkSetupDone(), listTables(), and wfDebug().
Referenced by setupDatabase().
|
private |
Remove the dummy uploads directory.
Definition at line 1574 of file ParserTestRunner.php.
References deleteFiles(), and RepoGroup\singleton().
Referenced by setupUploadBackend().
|
staticprivate |
MediaWiki core parser test files, paths will be prefixed with DIR .
'/'
Definition at line 45 of file ParserTestRunner.php.
Referenced by getParserTestFiles().
|
private |
Our connection to the database.
Definition at line 70 of file ParserTestRunner.php.
Referenced by setDatabase().
|
private |
Database clone helper.
Definition at line 76 of file ParserTestRunner.php.
|
private |
Disable parse on article insertion.
Definition at line 135 of file ParserTestRunner.php.
|
private |
The name of the file backend to use, or null to use MockFileBackend.
Definition at line 104 of file ParserTestRunner.php.
Referenced by createRepoGroup().
|
private |
Reuse upload directory.
Definition at line 141 of file ParserTestRunner.php.
|
private |
A list of normalization functions to apply to the expected and actual output.
Definition at line 117 of file ParserTestRunner.php.
|
private |
Definition at line 91 of file ParserTestRunner.php.
Referenced by __construct(), and getRecorder().
|
private |
A complete regex for filtering tests.
Definition at line 110 of file ParserTestRunner.php.
Referenced by parseOptions().
|
private |
Run disabled parser tests.
Definition at line 123 of file ParserTestRunner.php.
|
private |
Run tests intended only for parsoid.
Definition at line 129 of file ParserTestRunner.php.
|
private |
Definition at line 58 of file ParserTestRunner.php.
|
private |
Definition at line 86 of file ParserTestRunner.php.
Referenced by perTestSetup().
|
private |
Definition at line 81 of file ParserTestRunner.php.
|
private |
The upload directory, or null to not set up an upload directory.
Definition at line 98 of file ParserTestRunner.php.
|
private |
Definition at line 53 of file ParserTestRunner.php.