MediaWiki
1.27.1
|
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 | 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 | |
$maxFuzzTestLength = 300 | |
$memoryLimit = 50 | |
$savedGlobals = [] | |
$showOutput | |
TidySupport | $tidySupport |
$uploadDir = null | |
$useTemporaryTables = true | |
Definition at line 34 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 90 of file parserTest.inc.
References $options, color, hooks, Maintenance\posix_isatty(), setUp(), setupRecorder(), showFailure(), term(), wfIsWindows(), and wfTempDir().
ParserTest::abort | ( | ) |
Definition at line 492 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 1510 of file parserTest.inc.
References $name, $page, $title, $wgCapitalLinks, EDIT_NEW, WikiPage\factory(), global, ContentHandler\makeContent(), and Title\newFromText().
Referenced by NewParserTest\publishTestArticles().
|
static |
Remove last character if it is a newline utility.
string | $s |
Definition at line 352 of file parserTest.inc.
References $s.
Referenced by TestFileIterator\readNextTest(), and TestFileIterator\setupCurrentTest().
|
private |
Definition at line 799 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 1481 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 1344 of file parserTest.inc.
|
staticprivate |
Delete the specified files, if they exist.
array | $files | Full paths to files to delete. |
Definition at line 1330 of file parserTest.inc.
|
private |
Write the given string to a file, adding a final newline.
string | $data | |
string | $filename |
Definition at line 1468 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 365 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 1662 of file parserTest.inc.
ParserTest::getFuzzInput | ( | $filenames | ) |
Get an input dictionary from a set of parser test files.
array | $filenames |
Definition at line 437 of file parserTest.inc.
Referenced by fuzzTest().
ParserTest::getMemoryBreakdown | ( | ) |
Get a memory usage breakdown.
Definition at line 460 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 717 of file parserTest.inc.
References $key.
ParserTest::getParser | ( | $preprocessor = null | ) |
Get a Parser object.
string | $preprocessor |
Definition at line 559 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 968 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 1434 of file parserTest.inc.
References $output, 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 1572 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 1549 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 1595 of file parserTest.inc.
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 595 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(), parseOptions(), ParserOutput\setTOCEnabled(), setupGlobals(), showSkipped(), showTesting(), showTestResult(), and teardownGlobals().
Referenced by runTests().
ParserTest::runTests | ( | $tests | ) |
Definition at line 536 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 507 of file parserTest.inc.
References $e, $GLOBALS, as, Language\factory(), runTests(), setupDatabase(), and teardownDatabase().
ParserTest::setUp | ( | ) |
Definition at line 166 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 995 of file parserTest.inc.
References $image, ObjectCache\$instances, $user, $wgDBprefix, CACHE_DB, User\createNew(), DB_MASTER, Language\getLocalisationCache(), global, listTables(), Title\makeTitle(), 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 821 of file parserTest.inc.
References $context, $GLOBALS, $IP, $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 262 of file parserTest.inc.
References Hooks\register().
Referenced by NewParserTest\setUpBeforeClass().
ParserTest::setupRecorder | ( | $options | ) |
Definition at line 334 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 1209 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 1385 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 1494 of file parserTest.inc.
|
protected |
Print a skipped message.
Definition at line 1416 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 1368 of file parserTest.inc.
Referenced by showTestResult().
|
protected |
"Running test $desc..."
string | $desc |
Definition at line 1356 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 700 of file parserTest.inc.
References ParserTestResult\isSuccess(), showFailure(), and showSuccess().
Referenced by runTest().
ParserTest::teardownDatabase | ( | ) |
Definition at line 1163 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 1246 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 330 of file parserTest.inc.
References Hooks\clear().
Referenced by NewParserTest\tearDownAfterClass().
|
private |
Remove the dummy uploads directory.
string | $dir |
Definition at line 1262 of file parserTest.inc.
Referenced by teardownDatabase().
|
private |
Definition at line 1610 of file parserTest.inc.
References $html, $parser, extractFragment(), and Sanitizer\hackDocType().
Referenced by showFailure().
|
private |
Definition at line 38 of file parserTest.inc.
|
private |
Definition at line 53 of file parserTest.inc.
|
private |
Our connection to the database.
Definition at line 59 of file parserTest.inc.
|
private |
Database clone helper.
Definition at line 65 of file parserTest.inc.
|
private |
Definition at line 70 of file parserTest.inc.
|
private |
Definition at line 78 of file parserTest.inc.
|
private |
Definition at line 77 of file parserTest.inc.
|
private |
Definition at line 79 of file parserTest.inc.
ParserTest::$regex = "" |
Definition at line 82 of file parserTest.inc.
Referenced by parseOptions().
|
private |
Definition at line 83 of file parserTest.inc.
|
private |
Definition at line 43 of file parserTest.inc.
|
private |
Definition at line 75 of file parserTest.inc.
|
private |
Definition at line 80 of file parserTest.inc.
Referenced by setupUploadDir().
|
private |
Definition at line 48 of file parserTest.inc.