MediaWiki  REL1_20
ParserTest Class Reference
Collaboration diagram for ParserTest:

List of all members.

Public Member Functions

 __construct ($options=array())
 Sets terminal colorization and diff/quick modes depending on OS and command-line options (--color and --quick).
 abort ()
 fuzzTest ($filenames)
 Run a fuzz test series Draw input from a set of test files.
 getFuzzInput ($filenames)
 Get an input dictionary from a set of parser test files.
 getMemoryBreakdown ()
 Get a memory usage breakdown.
 getParser ($preprocessor=null)
 Get a Parser object.
 requireFunctionHook ($name)
 Steal a callback function from the primary parser, save it for application to our scary parser.
 requireHook ($name)
 Steal a callback function from the primary parser, save it for application to our scary parser.
 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.
 runTests ($tests)
 runTestsFromFiles ($filenames)
 Run a series of tests listed in the given text files.
 setupDatabase ()
 Set up a temporary set of wiki tables to work with for the tests.
 setupRecorder ($options)
 showRunFile ($path)
 Show "Reading tests from ...".
 showTestResult ($desc, $result, $out)
 teardownDatabase ()

Static Public Member Functions

static addArticle ($name, $text, $line= 'unknown', $ignoreDuplicate= '')
 Insert a temporary test article.
static chomp ($s)
 Remove last character if it is a newline utility.
static getFakeTimestamp (&$parser, &$ts)
static setUp ()

Public Attributes

 $regex = ""

Protected Member Functions

 colorDiff ($text)
 Colorize unified diff output if set for ANSI color output.
 quickDiff ($input, $output, $inFileTail= 'expected', $outFileTail= 'actual')
 Run given strings through a diff and return the (colorized) output.
 showFailure ($desc, $result, $html)
 Print a failure message and provide some explanatory output about what went wrong if so configured.
 showSuccess ($desc)
 Print a happy success message.
 showTesting ($desc)
 "Running test $desc..."

Private Member Functions

 cleanupOption ($opt)
 dumpToFile ($data, $filename)
 Write the given string to a file, adding a final newline.
 extractFragment ($text, $position)
 listTables ()
 List of temporary tables to create, without prefix.
 parseOptions ($instring)
 setupGlobals ($opts= '', $config= '')
 Set up the global variables for a consistent environment for each test.
 setupUploadDir ()
 Create a dummy uploads directory which will contain a couple of files in order to pass existence tests.
 teardownGlobals ()
 Restore default values and perform any necessary clean-up after each test runs.
 teardownUploadDir ($dir)
 Remove the dummy uploads directory.
 tidy ($text)
 Run the "tidy" command on text if the $wgUseTidy global is true.
 wellFormed ($text)

Static Private Member Functions

static deleteDirs ($dirs)
 Delete the specified directories, if they exist.
static deleteFiles ($files)
 Delete the specified files, if they exist.
static getOptionValue ($key, $opts, $default)
 Use a regex to find out the value of an option.

Private Attributes

 $color
 boolean $color whereas output should be colorized
 $databaseSetupDone = false
 boolean $databaseSetupDone True if the database has been set up
DatabaseBase $db
 Our connection to the database.
CloneDatabase $dbClone
 Database clone helper.
 $fuzzSeed = 0
 $maxFuzzTestLength = 300
 $memoryLimit = 50
 $oldTablePrefix
 string $oldTablePrefix Original table prefix
 $savedGlobals = array()
 $showOutput
 boolean $showOutput Show test output
 $uploadDir = null
 $useTemporaryTables = true
 boolean $useTemporaryTables Use temporary tables for the temporary database

Detailed Description

Definition at line 30 of file parserTest.inc.


Constructor & Destructor Documentation

ParserTest::__construct ( options = array())

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

Definition at line 77 of file parserTest.inc.


Member Function Documentation

Definition at line 356 of file parserTest.inc.

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

Insert a temporary test article.

Parameters:
$nameString: the title, including any prefix
$textString: the article text
$lineInteger: the input line number, for reporting errors
$ignoreDuplicateBoolean: whether to silently ignore duplicate pages

Definition at line 1178 of file parserTest.inc.

static ParserTest::chomp ( s) [static]

Remove last character if it is a newline utility.

Definition at line 223 of file parserTest.inc.

Referenced by TestFileIterator\readNextTest().

ParserTest::cleanupOption ( opt) [private]

Definition at line 601 of file parserTest.inc.

ParserTest::colorDiff ( text) [protected]

Colorize unified diff output if set for ANSI color output.

Subtractions are colored blue, additions red.

Parameters:
$textString
Returns:
String

Definition at line 1151 of file parserTest.inc.

static ParserTest::deleteDirs ( dirs) [static, private]

Delete the specified directories, if they exist.

Must be empty.

Parameters:
$dirsArray: full paths to directories to delete.

Definition at line 1034 of file parserTest.inc.

static ParserTest::deleteFiles ( files) [static, private]

Delete the specified files, if they exist.

Parameters:
$filesArray: full paths to files to delete.

Definition at line 1022 of file parserTest.inc.

ParserTest::dumpToFile ( data,
filename 
) [private]

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

Parameters:
$dataString
$filenameString

Definition at line 1138 of file parserTest.inc.

ParserTest::extractFragment ( text,
position 
) [private]

Definition at line 1299 of file parserTest.inc.

ParserTest::fuzzTest ( filenames)

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

Definition at line 236 of file parserTest.inc.

static ParserTest::getFakeTimestamp ( &$  parser,
&$  ts 
) [static]

Definition at line 1324 of file parserTest.inc.

ParserTest::getFuzzInput ( filenames)

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

Definition at line 306 of file parserTest.inc.

Get a memory usage breakdown.

Definition at line 324 of file parserTest.inc.

static ParserTest::getOptionValue ( key,
opts,
default 
) [static, private]

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

Parameters:
$keyString: name of option val to retrieve
$optsOptions array to look in
$defaultMixed: default value returned if not found

Definition at line 536 of file parserTest.inc.

ParserTest::getParser ( preprocessor = null)

Get a Parser object.

Definition at line 414 of file parserTest.inc.

ParserTest::listTables ( ) [private]

List of temporary tables to create, without prefix.

Some of these probably aren't necessary.

Definition at line 744 of file parserTest.inc.

ParserTest::parseOptions ( instring) [private]

Definition at line 546 of file parserTest.inc.

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:
$inputString
$outputString
$inFileTailString: tailing for the input file name
$outFileTailString: tailing for the output file name
Returns:
String

Definition at line 1107 of file parserTest.inc.

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:
$nameString
Returns:
Bool true if function hook is present

Definition at line 1240 of file parserTest.inc.

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:
$nameString
Returns:
Bool true if tag hook is present

Definition at line 1217 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.

Parameters:
$descString: test's description
$inputString: wikitext to try rendering
$resultString: result to output
$optsArray: test's options
$configString: overrides for global variables, one per line
Returns:
Boolean

Definition at line 446 of file parserTest.inc.

ParserTest::runTests ( tests)

Definition at line 394 of file parserTest.inc.

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:
$filenamesArray of strings
Returns:
Boolean: true if passed all tests, false if any tests failed.

Definition at line 371 of file parserTest.inc.

static ParserTest::setUp ( ) [static]

Definition at line 135 of file parserTest.inc.

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 771 of file parserTest.inc.

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.

Definition at line 616 of file parserTest.inc.

ParserTest::setupRecorder ( options)

Definition at line 207 of file parserTest.inc.

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 931 of file parserTest.inc.

ParserTest::showFailure ( desc,
result,
html 
) [protected]

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

Parameters:
$descString: the test name
$resultString: expected HTML output
$htmlString: actual HTML output
Returns:
Boolean

Definition at line 1072 of file parserTest.inc.

Show "Reading tests from ...".

Parameters:
$pathString

Definition at line 1164 of file parserTest.inc.

ParserTest::showSuccess ( desc) [protected]

Print a happy success message.

Parameters:
$descString: the test name
Returns:
Boolean

Definition at line 1055 of file parserTest.inc.

ParserTest::showTesting ( desc) [protected]

"Running test $desc..."

Definition at line 1045 of file parserTest.inc.

ParserTest::showTestResult ( desc,
result,
out 
)

Definition at line 520 of file parserTest.inc.

Definition at line 889 of file parserTest.inc.

Restore default values and perform any necessary clean-up after each test runs.

Definition at line 962 of file parserTest.inc.

ParserTest::teardownUploadDir ( dir) [private]

Remove the dummy uploads directory.

Definition at line 976 of file parserTest.inc.

ParserTest::tidy ( text) [private]

Run the "tidy" command on text if the $wgUseTidy global is true.

Parameters:
$textString: the text to tidy
Returns:
String

Definition at line 1262 of file parserTest.inc.

ParserTest::wellFormed ( text) [private]

Definition at line 1272 of file parserTest.inc.


Member Data Documentation

ParserTest::$color [private]

boolean $color whereas output should be colorized

Definition at line 34 of file parserTest.inc.

ParserTest::$databaseSetupDone = false [private]

boolean $databaseSetupDone True if the database has been set up

Definition at line 49 of file parserTest.inc.

DatabaseBase ParserTest::$db [private]

Our connection to the database.

Definition at line 54 of file parserTest.inc.

CloneDatabase ParserTest::$dbClone [private]

Database clone helper.

Definition at line 59 of file parserTest.inc.

ParserTest::$fuzzSeed = 0 [private]

Definition at line 67 of file parserTest.inc.

ParserTest::$maxFuzzTestLength = 300 [private]

Definition at line 66 of file parserTest.inc.

ParserTest::$memoryLimit = 50 [private]

Definition at line 68 of file parserTest.inc.

ParserTest::$oldTablePrefix [private]

string $oldTablePrefix Original table prefix

Definition at line 64 of file parserTest.inc.

ParserTest::$regex = ""

Definition at line 71 of file parserTest.inc.

ParserTest::$savedGlobals = array() [private]

Definition at line 72 of file parserTest.inc.

ParserTest::$showOutput [private]

boolean $showOutput Show test output

Definition at line 39 of file parserTest.inc.

ParserTest::$uploadDir = null [private]

Definition at line 69 of file parserTest.inc.

ParserTest::$useTemporaryTables = true [private]

boolean $useTemporaryTables Use temporary tables for the temporary database

Definition at line 44 of file parserTest.inc.


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