MediaWiki  1.27.2
ParserTest Class Reference
Collaboration diagram for ParserTest:

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
 

Detailed Description

Definition at line 34 of file parserTest.inc.

Constructor & Destructor Documentation

ParserTest::__construct (   $options = [])

Sets terminal colorization and diff/quick modes depending on OS and command-line options (–color and –quick).

Parameters
array$options

Definition at line 90 of file parserTest.inc.

References $options, color, hooks, Maintenance\posix_isatty(), setUp(), setupRecorder(), showFailure(), term(), wfIsWindows(), and wfTempDir().

Member Function Documentation

ParserTest::abort ( )

Definition at line 492 of file parserTest.inc.

Referenced by fuzzTest().

static ParserTest::addArticle (   $name,
  $text,
  $line = 'unknown',
  $ignoreDuplicate = '' 
)
static

Insert a temporary test article.

Parameters
string$nameThe title, including any prefix
string$textThe article text
int | string$lineThe input line number, for reporting errors
bool | string$ignoreDuplicateWhether to silently ignore duplicate pages
Exceptions
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 ParserTest::chomp (   $s)
static

Remove last character if it is a newline utility.

Parameters
string$s
Returns
string

Definition at line 352 of file parserTest.inc.

References $s.

Referenced by TestFileIterator\readNextTest(), and TestFileIterator\setupCurrentTest().

ParserTest::cleanupOption (   $opt)
private

Definition at line 799 of file parserTest.inc.

References FormatJson\decode().

ParserTest::colorDiff (   $text)
protected

Colorize unified diff output if set for ANSI color output.

Subtractions are colored blue, additions red.

Parameters
string$text
Returns
string

Definition at line 1481 of file parserTest.inc.

References term().

Referenced by quickDiff().

static ParserTest::deleteDirs (   $dirs)
staticprivate

Delete the specified directories, if they exist.

Must be empty.

Parameters
array$dirsFull paths to directories to delete.

Definition at line 1344 of file parserTest.inc.

References $dir, $dirs, and as.

static ParserTest::deleteFiles (   $files)
staticprivate

Delete the specified files, if they exist.

Parameters
array$filesFull paths to files to delete.

Definition at line 1330 of file parserTest.inc.

References $files, and as.

ParserTest::dumpToFile (   $data,
  $filename 
)
private

Write the given string to a file, adding a final newline.

Parameters
string$data
string$filename

Definition at line 1468 of file parserTest.inc.

Referenced by quickDiff().

ParserTest::extractFragment (   $text,
  $position 
)
private

Definition at line 1637 of file parserTest.inc.

References term().

Referenced by wellFormed().

ParserTest::fuzzTest (   $filenames)

Run a fuzz test series Draw input from a set of test files.

Parameters
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 ParserTest::getFakeTimestamp ( $parser,
$ts 
)
static

Definition at line 1662 of file parserTest.inc.

ParserTest::getFuzzInput (   $filenames)

Get an input dictionary from a set of parser test files.

Parameters
array$filenames
Returns
string

Definition at line 437 of file parserTest.inc.

References $matches, and as.

Referenced by fuzzTest().

ParserTest::getMemoryBreakdown ( )

Get a memory usage breakdown.

Returns
array

Definition at line 460 of file parserTest.inc.

References $GLOBALS, $name, $value, as, and serialize().

Referenced by fuzzTest().

static ParserTest::getOptionValue (   $key,
  $opts,
  $default 
)
staticprivate

Use a regex to find out the value of an option.

Parameters
string$keyName of option val to retrieve
array$optsOptions array to look in
mixed$defaultDefault value returned if not found
Returns
mixed

Definition at line 717 of file parserTest.inc.

References $key.

ParserTest::getParser (   $preprocessor = null)

Get a Parser object.

Parameters
string$preprocessor
Returns
Parser

Definition at line 559 of file parserTest.inc.

References $flags, $parser, $tag, as, global, hooks, list, and Hooks\run().

Referenced by fuzzTest(), and runTest().

ParserTest::listTables ( )
private

List of temporary tables to create, without prefix.

Some of these probably aren't necessary.

Returns
array

Definition at line 968 of file parserTest.inc.

References $tables, and Hooks\run().

Referenced by setupDatabase(), and teardownDatabase().

ParserTest::parseOptions (   $instring)
private

Definition at line 727 of file parserTest.inc.

References $key, $matches, $regex, and as.

Referenced by runTest().

ParserTest::quickDiff (   $input,
  $output,
  $inFileTail = 'expected',
  $outFileTail = 'actual' 
)
protected

Run given strings through a diff and return the (colorized) output.

Requires writable /tmp directory and a 'diff' command in the PATH.

Parameters
string$input
string$output
string$inFileTailTailing for the input file name
string$outFileTailTailing for the output file name
Returns
string

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.

Parameters
string$name
Returns
bool True if function hook is present

Definition at line 1572 of file parserTest.inc.

References $name, $wgParser, and global.

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.

Parameters
string$name
Returns
bool True if tag hook is present

Definition at line 1549 of file parserTest.inc.

References $name, $wgParser, global, and hooks.

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.

Parameters
string$name
Returns
bool True if function hook is present

Definition at line 1595 of file parserTest.inc.

References $name, $wgParser, and global.

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.

Parameters
string$descTest's description
string$inputWikitext to try rendering
string$resultResult to output
array$optsTest's options
string$configOverrides for global variables, one per line
Returns
bool

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.

Parameters
array$filenamesArray of strings
Returns
bool True if passed all tests, false if any tests failed.

Definition at line 507 of file parserTest.inc.

References $e, $GLOBALS, as, Language\factory(), runTests(), setupDatabase(), and teardownDatabase().

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().

ParserTest::setupGlobals (   $opts = '',
  $config = '' 
)
private

Set up the global variables for a consistent environment for each test.

Ideally this should replace the global configuration entirely.

Parameters
string$opts
string$config
Returns
RequestContext

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 ParserTest::setupInterwikis ( )
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().

ParserTest::setupUploadDir ( )
private

Create a dummy uploads directory which will contain a couple of files in order to pass existence tests.

Returns
string The directory

Definition at line 1209 of file parserTest.inc.

References $dir, $IP, $uploadDir, copy, global, wfDebug(), and wfMkdirParents().

Referenced by setupDatabase().

ParserTest::showFailure ( ParserTestResult  $testResult)
protected

Print a failure message and provide some explanatory output about what went wrong if so configured.

Refactored in 1.22 to use ParserTestResult

Parameters
ParserTestResult$testResult
Returns
bool

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 ...".

Parameters
string$path

Definition at line 1494 of file parserTest.inc.

References print, and term().

ParserTest::showSkipped ( )
protected

Print a skipped message.

Returns
bool

Definition at line 1416 of file parserTest.inc.

References print, and term().

Referenced by runTest().

ParserTest::showSuccess ( ParserTestResult  $testResult)
protected

Print a happy success message.

Refactored in 1.22 to use ParserTestResult

Parameters
ParserTestResult$testResult
Returns
bool

Definition at line 1368 of file parserTest.inc.

References print, and term().

Referenced by showTestResult().

ParserTest::showTesting (   $desc)
protected

"Running test $desc..."

Parameters
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.

Parameters
ParserTestResult$testResult
Returns
bool

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().

ParserTest::teardownGlobals ( )
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 ParserTest::tearDownInterwikis ( )
static

Remove the hardcoded interwiki lookup table.

Definition at line 330 of file parserTest.inc.

References Hooks\clear().

Referenced by NewParserTest\tearDownAfterClass().

ParserTest::teardownUploadDir (   $dir)
private

Remove the dummy uploads directory.

Parameters
string$dir

Definition at line 1262 of file parserTest.inc.

Referenced by teardownDatabase().

ParserTest::wellFormed (   $text)
private

Definition at line 1610 of file parserTest.inc.

References $html, $parser, extractFragment(), and Sanitizer\hackDocType().

Referenced by showFailure().

Member Data Documentation

ParserTest::$color
private

Definition at line 38 of file parserTest.inc.

ParserTest::$databaseSetupDone = false
private

Definition at line 53 of file parserTest.inc.

DatabaseBase ParserTest::$db
private

Our connection to the database.

Definition at line 59 of file parserTest.inc.

CloneDatabase ParserTest::$dbClone
private

Database clone helper.

Definition at line 65 of file parserTest.inc.

DjVuSupport ParserTest::$djVuSupport
private

Definition at line 70 of file parserTest.inc.

ParserTest::$fuzzSeed = 0
private

Definition at line 78 of file parserTest.inc.

ParserTest::$maxFuzzTestLength = 300
private

Definition at line 77 of file parserTest.inc.

ParserTest::$memoryLimit = 50
private

Definition at line 79 of file parserTest.inc.

ParserTest::$regex = ""

Definition at line 82 of file parserTest.inc.

Referenced by parseOptions().

ParserTest::$savedGlobals = []
private

Definition at line 83 of file parserTest.inc.

ParserTest::$showOutput
private

Definition at line 43 of file parserTest.inc.

TidySupport ParserTest::$tidySupport
private

Definition at line 75 of file parserTest.inc.

ParserTest::$uploadDir = null
private

Definition at line 80 of file parserTest.inc.

Referenced by setupUploadDir().

ParserTest::$useTemporaryTables = true
private

Definition at line 48 of file parserTest.inc.


The documentation for this class was generated from the following file: