MediaWiki
master
|
Public Member Functions | |
__construct ($options=[]) | |
Sets terminal colorization and diff/quick modes depending on OS and command-line options (–color and –quick). More... | |
abort () | |
fuzzTest ($filenames) | |
Run a fuzz test series Draw input from a set of test files. More... | |
getFuzzInput ($filenames) | |
Get an input dictionary from a set of parser test files. More... | |
getMemoryBreakdown () | |
Get a memory usage breakdown. More... | |
getParser ($preprocessor=null) | |
Get a Parser object. More... | |
requireFunctionHook ($name) | |
Steal a callback function from the primary parser, save it for application to our scary parser. More... | |
requireHook ($name) | |
Steal a callback function from the primary parser, save it for application to our scary parser. More... | |
requireTransparentHook ($name) | |
Steal a callback function from the primary parser, save it for application to our scary parser. More... | |
runTest ($desc, $input, $result, $opts, $config) | |
Run a given wikitext input through a freshly-constructed wiki parser, and compare the output against the expected results. More... | |
runTests ($tests) | |
runTestsFromFiles ($filenames) | |
Run a series of tests listed in the given text files. More... | |
setUp () | |
setupDatabase () | |
Set up a temporary set of wiki tables to work with for the tests. More... | |
setupRecorder ($options) | |
showRunFile ($path) | |
Show "Reading tests from ...". More... | |
showTestResult (ParserTestResult $testResult) | |
Refactored in 1.22 to use ParserTestResult. More... | |
teardownDatabase () | |
Static Public Member Functions | |
static | addArticle ($name, $text, $line= 'unknown', $ignoreDuplicate= '') |
Insert a temporary test article. More... | |
static | chomp ($s) |
Remove last character if it is a newline utility. More... | |
static | getFakeTimestamp (&$parser, &$ts) |
static | resetTitleServices () |
Reset the Title-related services that need resetting for each test. More... | |
static | setupInterwikis () |
Insert hardcoded interwiki in the lookup table. More... | |
static | tearDownInterwikis () |
Remove the hardcoded interwiki lookup table. More... | |
Public Attributes | |
$regex = "" | |
Protected Member Functions | |
colorDiff ($text) | |
Colorize unified diff output if set for ANSI color output. More... | |
quickDiff ($input, $output, $inFileTail= 'expected', $outFileTail= 'actual') | |
Run given strings through a diff and return the (colorized) output. More... | |
showFailure (ParserTestResult $testResult) | |
Print a failure message and provide some explanatory output about what went wrong if so configured. More... | |
showSkipped () | |
Print a skipped message. More... | |
showSuccess (ParserTestResult $testResult) | |
Print a happy success message. More... | |
showTesting ($desc) | |
"Running test $desc..." More... | |
Private Member Functions | |
cleanupOption ($opt) | |
dumpToFile ($data, $filename) | |
Write the given string to a file, adding a final newline. More... | |
extractFragment ($text, $position) | |
listTables () | |
List of temporary tables to create, without prefix. More... | |
parseOptions ($instring) | |
setupGlobals ($opts= '', $config= '') | |
Set up the global variables for a consistent environment for each test. More... | |
setupUploadDir () | |
Create a dummy uploads directory which will contain a couple of files in order to pass existence tests. More... | |
teardownGlobals () | |
Restore default values and perform any necessary clean-up after each test runs. More... | |
teardownUploadDir ($dir) | |
Remove the dummy uploads directory. More... | |
wellFormed ($text) | |
Static Private Member Functions | |
static | deleteDirs ($dirs) |
Delete the specified directories, if they exist. More... | |
static | deleteFiles ($files) |
Delete the specified files, if they exist. More... | |
static | getOptionValue ($key, $opts, $default) |
Use a regex to find out the value of an option. More... | |
Private Attributes | |
$color | |
$databaseSetupDone = false | |
DatabaseBase | $db |
Our connection to the database. More... | |
CloneDatabase | $dbClone |
Database clone helper. More... | |
DjVuSupport | $djVuSupport |
$fuzzSeed = 0 | |
$markWhitespace = false | |
$maxFuzzTestLength = 300 | |
$memoryLimit = 50 | |
$normalizationFunctions = [] | |
ITestRecorder | $recorder |
$savedGlobals = [] | |
$showOutput | |
TidySupport | $tidySupport |
$uploadDir = null | |
$useDwdiff = false | |
$useTemporaryTables = true | |
Definition at line 35 of file parserTest.inc.
ParserTest::__construct | ( | $options = [] | ) |
Sets terminal colorization and diff/quick modes depending on OS and command-line options (–color and –quick).
array | $options |
Definition at line 99 of file parserTest.inc.
References $options, as, color, hooks, Maintenance\posix_isatty(), setUp(), setupRecorder(), showFailure(), term(), wfIsWindows(), and wfTempDir().
ParserTest::abort | ( | ) |
Definition at line 527 of file parserTest.inc.
Referenced by fuzzTest().
|
static |
Insert a temporary test article.
string | $name | The title, including any prefix |
string | $text | The article text |
int | string | $line | The input line number, for reporting errors |
bool | string | $ignoreDuplicate | Whether to silently ignore duplicate pages |
Exception | |
MWException |
Definition at line 1582 of file parserTest.inc.
References $name, $page, $title, $wgCapitalLinks, EDIT_NEW, WikiPage\factory(), global, and Title\newFromText().
Referenced by NewParserTest\publishTestArticles().
|
static |
Remove last character if it is a newline utility.
string | $s |
Definition at line 387 of file parserTest.inc.
References $s.
Referenced by TestFileIterator\readNextTest(), and TestFileIterator\setupCurrentTest().
|
private |
Definition at line 839 of file parserTest.inc.
References FormatJson\decode().
|
protected |
Colorize unified diff output if set for ANSI color output.
Subtractions are colored blue, additions red.
string | $text |
Definition at line 1553 of file parserTest.inc.
References term().
Referenced by quickDiff().
|
staticprivate |
Delete the specified directories, if they exist.
Must be empty.
array | $dirs | Full paths to directories to delete. |
Definition at line 1398 of file parserTest.inc.
|
staticprivate |
Delete the specified files, if they exist.
array | $files | Full paths to files to delete. |
Definition at line 1384 of file parserTest.inc.
|
private |
Write the given string to a file, adding a final newline.
string | $data | |
string | $filename |
Definition at line 1540 of file parserTest.inc.
Referenced by quickDiff().
|
private |
ParserTest::fuzzTest | ( | $filenames | ) |
Run a fuzz test series Draw input from a set of test files.
array | $filenames |
Definition at line 400 of file parserTest.inc.
References $GLOBALS, $name, $parser, $title, $user, abort(), as, Language\factory(), getFuzzInput(), getMemoryBreakdown(), getParser(), Title\makeTitle(), ParserOptions\newFromUser(), NS_MAIN, setupDatabase(), setupGlobals(), teardownGlobals(), and User.
|
static |
Definition at line 1734 of file parserTest.inc.
ParserTest::getFuzzInput | ( | $filenames | ) |
Get an input dictionary from a set of parser test files.
array | $filenames |
Definition at line 472 of file parserTest.inc.
Referenced by fuzzTest().
ParserTest::getMemoryBreakdown | ( | ) |
Get a memory usage breakdown.
Definition at line 495 of file parserTest.inc.
References $GLOBALS, $name, $value, as, and serialize().
Referenced by fuzzTest().
|
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 757 of file parserTest.inc.
ParserTest::getParser | ( | $preprocessor = null | ) |
Get a Parser object.
string | $preprocessor |
Definition at line 594 of file parserTest.inc.
References $flags, $parser, $tag, as, global, hooks, list, and Hooks\run().
Referenced by fuzzTest(), and runTest().
|
private |
List of temporary tables to create, without prefix.
Some of these probably aren't necessary.
Definition at line 1004 of file parserTest.inc.
References $tables, and Hooks\run().
Referenced by setupDatabase(), and teardownDatabase().
|
private |
|
protected |
Run given strings through a diff and return the (colorized) output.
Requires writable /tmp directory and a 'diff' command in the PATH.
string | $input | |
string | $output | |
string | $inFileTail | Tailing for the input file name |
string | $outFileTail | Tailing for the output file name |
Definition at line 1488 of file parserTest.inc.
References $output, $wgDiff3, colorDiff(), dumpToFile(), global, wfEscapeShellArg(), wfIsWindows(), wfShellExec(), and wfTempDir().
Referenced by showFailure().
ParserTest::requireFunctionHook | ( | $name | ) |
Steal a callback function from the primary parser, save it for application to our scary parser.
If the hook is not installed, abort processing of this file.
string | $name |
Definition at line 1644 of file parserTest.inc.
ParserTest::requireHook | ( | $name | ) |
Steal a callback function from the primary parser, save it for application to our scary parser.
If the hook is not installed, abort processing of this file.
string | $name |
Definition at line 1621 of file parserTest.inc.
ParserTest::requireTransparentHook | ( | $name | ) |
Steal a callback function from the primary parser, save it for application to our scary parser.
If the hook is not installed, abort processing of this file.
string | $name |
Definition at line 1667 of file parserTest.inc.
|
static |
Reset the Title-related services that need resetting for each test.
Definition at line 360 of file parserTest.inc.
References $services.
ParserTest::runTest | ( | $desc, | |
$input, | |||
$result, | |||
$opts, | |||
$config | |||
) |
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.
string | $desc | Test's description |
string | $input | Wikitext to try rendering |
string | $result | Result to output |
array | $opts | Test's options |
string | $config | Overrides for global variables, one per line |
Definition at line 630 of file parserTest.inc.
References $content, $context, $options, $out, $output, $parser, $section, $title, $user, as, Linker\formatComment(), ParserOutput\getCategories(), ParserOutput\getIndicators(), ParserOutput\getLanguageLinks(), ObjectCache\getMainWANInstance(), getParser(), ParserOutput\getText(), ParserOutput\getTitleText(), ParserOptions\newFromContext(), Title\newFromText(), ParserTestResultNormalizer\normalize(), parseOptions(), ParserOutput\setTOCEnabled(), setupGlobals(), showSkipped(), showTesting(), showTestResult(), and teardownGlobals().
Referenced by runTests().
ParserTest::runTests | ( | $tests | ) |
Definition at line 571 of file parserTest.inc.
References $t, as, print, and runTest().
Referenced by runTestsFromFiles().
ParserTest::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.
array | $filenames | Array of strings |
Definition at line 542 of file parserTest.inc.
References $e, $GLOBALS, as, Language\factory(), runTests(), setupDatabase(), and teardownDatabase().
ParserTest::setUp | ( | ) |
Definition at line 187 of file parserTest.inc.
References $context, $IP, $messageMemc, $parserMemc, $wgArticlePath, $wgExtensionAssetsPath, $wgExtraInterlanguageLinkPrefixes, $wgExtraNamespaces, $wgLang, $wgLocalFileRepo, $wgLocalInterwikis, $wgLockManagers, $wgMemc, $wgMessageCacheType, $wgNamespaceAliases, $wgNamespaceProtection, $wgOut, $wgParser, $wgParserCacheType, $wgRequest, $wgResourceBasePath, $wgScript, $wgScriptPath, $wgStyleDirectory, $wgStylePath, $wgThumbnailScriptPath, $wgUser, CACHE_DB, CACHE_NONE, DeferredUpdates\clearPendingUpdates(), Language\factory(), MWNamespace\getCanonicalNamespaces(), global, NS_FILE, NS_FILE_TALK, NS_MEDIAWIKI, RequestContext\resetMain(), User, wfGetMainCache(), wfGetMessageCacheStorage(), wfGetParserCacheStorage(), and wfWikiID().
Referenced by __construct().
ParserTest::setupDatabase | ( | ) |
Set up a temporary set of wiki tables to work with for the tests.
Currently this will only be done once per run, and any changes to the db will be visible to later tests in the run.
Definition at line 1031 of file parserTest.inc.
References $image, ObjectCache\$instances, $user, $wgDBprefix, CACHE_DB, User\createNew(), DB_MASTER, Language\getLocalisationCache(), global, listTables(), Title\makeTitle(), MEDIATYPE_AUDIO, MEDIATYPE_BITMAP, MEDIATYPE_DRAWING, MEDIATYPE_VIDEO, NS_FILE, serialize(), setupUploadDir(), MessageCache\singleton(), wfGetDB(), wfGetLB(), and wfLocalFile().
Referenced by fuzzTest(), and runTestsFromFiles().
|
private |
Set up the global variables for a consistent environment for each test.
Ideally this should replace the global configuration entirely.
string | $opts | |
string | $config |
Definition at line 861 of file parserTest.inc.
References $context, $GLOBALS, $lang, $line, $value, $wgHooks, as, MagicWord\clearCache(), RepoGroup\destroySingleton(), MWTidy\destroySingleton(), Language\factory(), RequestContext\getMain(), global, list, NS_MEDIAWIKI, RequestContext\resetMain(), Hooks\run(), and wfWikiID().
Referenced by fuzzTest(), and runTest().
|
static |
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 284 of file parserTest.inc.
References Hooks\register().
Referenced by NewParserTest\setUpBeforeClass().
ParserTest::setupRecorder | ( | $options | ) |
Definition at line 369 of file parserTest.inc.
References $options, and SpecialVersion\getVersion().
Referenced by __construct().
|
private |
Create a dummy uploads directory which will contain a couple of files in order to pass existence tests.
Definition at line 1258 of file parserTest.inc.
References $dir, $IP, $uploadDir, copy, global, wfDebug(), and wfMkdirParents().
Referenced by setupDatabase().
|
protected |
Print a failure message and provide some explanatory output about what went wrong if so configured.
Refactored in 1.22 to use ParserTestResult
ParserTestResult | $testResult |
Definition at line 1439 of file parserTest.inc.
References print, quickDiff(), showTesting(), term(), and wellFormed().
Referenced by __construct(), and showTestResult().
ParserTest::showRunFile | ( | $path | ) |
Show "Reading tests from ...".
string | $path |
Definition at line 1566 of file parserTest.inc.
|
protected |
Print a skipped message.
Definition at line 1470 of file parserTest.inc.
Referenced by runTest().
|
protected |
Print a happy success message.
Refactored in 1.22 to use ParserTestResult
ParserTestResult | $testResult |
Definition at line 1422 of file parserTest.inc.
Referenced by showTestResult().
|
protected |
"Running test $desc..."
string | $desc |
Definition at line 1410 of file parserTest.inc.
References print.
Referenced by runTest(), and showFailure().
ParserTest::showTestResult | ( | ParserTestResult | $testResult | ) |
Refactored in 1.22 to use ParserTestResult.
ParserTestResult | $testResult |
Definition at line 740 of file parserTest.inc.
References ParserTestResult\isSuccess(), showFailure(), and showSuccess().
Referenced by runTest().
ParserTest::teardownDatabase | ( | ) |
Definition at line 1212 of file parserTest.inc.
References $tables, as, listTables(), teardownGlobals(), teardownUploadDir(), and wfDebug().
Referenced by runTestsFromFiles().
|
private |
Restore default values and perform any necessary clean-up after each test runs.
Definition at line 1297 of file parserTest.inc.
References $GLOBALS, as, FileBackendGroup\destroySingleton(), RepoGroup\destroySingleton(), MWTidy\destroySingleton(), LockManagerGroup\destroySingletons(), and LinkCache\singleton().
Referenced by fuzzTest(), runTest(), and teardownDatabase().
|
static |
Remove the hardcoded interwiki lookup table.
Definition at line 352 of file parserTest.inc.
References Hooks\clear().
Referenced by NewParserTest\tearDownAfterClass().
|
private |
Remove the dummy uploads directory.
string | $dir |
Definition at line 1313 of file parserTest.inc.
Referenced by teardownDatabase().
|
private |
Definition at line 1682 of file parserTest.inc.
References $html, $parser, extractFragment(), and Sanitizer\hackDocType().
Referenced by showFailure().
|
private |
Definition at line 39 of file parserTest.inc.
|
private |
Definition at line 54 of file parserTest.inc.
|
private |
Our connection to the database.
Definition at line 60 of file parserTest.inc.
|
private |
Database clone helper.
Definition at line 66 of file parserTest.inc.
|
private |
Definition at line 71 of file parserTest.inc.
|
private |
Definition at line 84 of file parserTest.inc.
|
private |
Definition at line 91 of file parserTest.inc.
|
private |
Definition at line 83 of file parserTest.inc.
|
private |
Definition at line 85 of file parserTest.inc.
|
private |
Definition at line 92 of file parserTest.inc.
|
private |
Definition at line 81 of file parserTest.inc.
ParserTest::$regex = "" |
Definition at line 88 of file parserTest.inc.
Referenced by parseOptions().
|
private |
Definition at line 89 of file parserTest.inc.
|
private |
Definition at line 44 of file parserTest.inc.
|
private |
Definition at line 76 of file parserTest.inc.
|
private |
Definition at line 86 of file parserTest.inc.
Referenced by setupUploadDir().
|
private |
Definition at line 90 of file parserTest.inc.
|
private |
Definition at line 49 of file parserTest.inc.