* Sets terminal colorization and diff/quick modes depending on OS and
* command-line options (--color and --quick).
*/
- public function ParserTest() {
- global $options;
-
+ public function ParserTest( $options = array() ) {
# Only colorize output if stdout is a terminal.
$this->color = !wfIsWindows() && posix_isatty( 1 );
$this->regex = '';
}
- $this->setupRecorder();
+ $this->setupRecorder( $options );
$this->keepUploads = isset( $options['keep-uploads'] );
if ( isset( $options['seed'] ) ) {
$this->functionHooks = array();
}
- public function setupRecorder() {
+ public function setupRecorder ( $options ) {
if ( isset( $options['record'] ) ) {
$this->recorder = new DbTestRecorder( $this );
+ $this->recorder->version = isset( $options['setversion'] ) ?
+ $options['setversion'] : SpecialVersion::getVersion();
} elseif ( isset( $options['compare'] ) ) {
$this->recorder = new DbTestPreviewer( $this );
} elseif ( isset( $options['upload'] ) ) {
* Draw input from a set of test files
*/
function fuzzTest( $filenames ) {
+ $GLOBALS['wgContLang'] = Language::factory( 'en' );
$dict = $this->getFuzzInput( $filenames );
$dictSize = strlen( $dict );
$logMaxLength = log( $this->maxFuzzTestLength );
* @return Boolean: true if passed all tests, false if any tests failed.
*/
public function runTestsFromFiles( $filenames ) {
+ $GLOBALS['wgContLang'] = Language::factory( 'en' );
$this->recorder->start();
$this->setupDatabase();
$ok = true;
$user = new User();
$options = ParserOptions::newFromUser( $user );
- $m = array();
if ( isset( $opts['title'] ) ) {
$titleText = $opts['title'];
}
$parser = $this->getParser( $preprocessor );
$title = Title::newFromText( $titleText );
- $matches = array();
if ( isset( $opts['pst'] ) ) {
$out = $parser->preSaveTransform( $input, $title, $user, $options );
} elseif ( isset( $opts['msg'] ) ) {
*/
private function setupGlobals( $opts = '', $config = '' ) {
global $wgDBtype;
- if ( !isset( $this->uploadDir ) ) {
- $this->uploadDir = $this->setupUploadDir();
- }
# Find out values for some special options.
$lang =
*/
private function listTables() {
global $wgDBtype;
- $tables = array( 'user', 'page', 'page_restrictions',
+ $tables = array( 'user', 'user_properties', 'page', 'page_restrictions',
'protected_titles', 'revision', 'text', 'pagelinks', 'imagelinks',
'categorylinks', 'templatelinks', 'externallinks', 'langlinks', 'iwlinks',
'site_stats', 'hitcounter', 'ipblocks', 'image', 'oldimage',
- 'recentchanges', 'watchlist', 'math', 'interwiki',
+ 'recentchanges', 'watchlist', 'math', 'interwiki', 'logging',
'querycache', 'objectcache', 'job', 'l10n_cache', 'redirect', 'querycachetwo',
- 'archive', 'user_groups', 'page_props', 'category'
+ 'archive', 'user_groups', 'page_props', 'category',
);
- if ( $wgDBtype === 'mysql' )
+ if ( in_array( $wgDBtype, array( 'mysql', 'sqlite' ) ) )
array_push( $tables, 'searchindex' );
// Allow extensions to add to the list of tables to duplicate;
$this->changePrefix( $wgDBtype != 'oracle' ? 'parsertest_' : 'pt_' );
$newTableName = $db->tableName( $tbl );
- if ( $db->tableExists( $tbl ) && $wgDBtype != 'postgres' && $wgDBtype != 'oracle' ) {
+ if ( $wgDBtype == 'mysql' ) {
+ $db->query( "DROP TABLE IF EXISTS $newTableName" );
+ } elseif ( in_array( $wgDBtype, array( 'postgres', 'oracle' ) ) ) {
+ /* DROPs wouldn't work due to Foreign Key Constraints (bug 14990, r58669)
+ * Use "DROP TABLE IF EXISTS $newTableName CASCADE" for postgres? That
+ * syntax would also work for mysql.
+ */
+ } elseif ( $db->tableExists( $tbl ) ) {
$db->query( "DROP TABLE $newTableName" );
}
# Create new table
$db->insert( 'interwiki', array(
array( 'iw_prefix' => 'wikipedia',
'iw_url' => 'http://en.wikipedia.org/wiki/$1',
+ 'iw_api' => '',
+ 'iw_wikiid' => '',
'iw_local' => 0 ),
array( 'iw_prefix' => 'meatball',
'iw_url' => 'http://www.usemod.com/cgi-bin/mb.pl?$1',
+ 'iw_api' => '',
+ 'iw_wikiid' => '',
'iw_local' => 0 ),
array( 'iw_prefix' => 'zh',
'iw_url' => 'http://zh.wikipedia.org/wiki/$1',
+ 'iw_api' => '',
+ 'iw_wikiid' => '',
'iw_local' => 1 ),
array( 'iw_prefix' => 'es',
'iw_url' => 'http://es.wikipedia.org/wiki/$1',
+ 'iw_api' => '',
+ 'iw_wikiid' => '',
'iw_local' => 1 ),
array( 'iw_prefix' => 'fr',
'iw_url' => 'http://fr.wikipedia.org/wiki/$1',
+ 'iw_api' => '',
+ 'iw_wikiid' => '',
'iw_local' => 1 ),
array( 'iw_prefix' => 'ru',
'iw_url' => 'http://ru.wikipedia.org/wiki/$1',
+ 'iw_api' => '',
+ 'iw_wikiid' => '',
'iw_local' => 1 ),
) );
if ( $wgDBtype == 'oracle' ) {
- # Insert 0 and 1 user_ids to prevent FK violations
+ # Insert 0 user to prevent FK violations
# Anonymous user
$db->insert( 'user', array(
'user_id' => 0,
'user_name' => 'Anonymous' ) );
-
- # Hack-on-Hack: Insert a test user to be able to insert an image
- $db->insert( 'user', array(
- 'user_id' => 1,
- 'user_name' => 'Tester' ) );
- }
-
- # Hack: Insert an image to work with
- $db->insert( 'image', array(
- 'img_name' => 'Foobar.jpg',
- 'img_size' => 12345,
- 'img_description' => 'Some lame file',
- 'img_user' => 1,
- 'img_user_text' => 'WikiSysop',
- 'img_timestamp' => $db->timestamp( '20010115123500' ),
- 'img_width' => 1941,
- 'img_height' => 220,
- 'img_bits' => 24,
- 'img_media_type' => MEDIATYPE_BITMAP,
- 'img_major_mime' => "image",
- 'img_minor_mime' => "jpeg",
- 'img_metadata' => serialize( array() ),
- ) );
-
- # This image will be blacklisted in [[MediaWiki:Bad image list]]
- $db->insert( 'image', array(
- 'img_name' => 'Bad.jpg',
- 'img_size' => 12345,
- 'img_description' => 'zomgnotcensored',
- 'img_user' => 1,
- 'img_user_text' => 'WikiSysop',
- 'img_timestamp' => $db->timestamp( '20010115123500' ),
- 'img_width' => 320,
- 'img_height' => 240,
- 'img_bits' => 24,
- 'img_media_type' => MEDIATYPE_BITMAP,
- 'img_major_mime' => "image",
- 'img_minor_mime' => "jpeg",
- 'img_metadata' => serialize( array() ),
- ) );
+ }
# Update certain things in site_stats
$db->insert( 'site_stats', array( 'ss_row_id' => 1, 'ss_images' => 2, 'ss_good_articles' => 1 ) );
# Make a new message cache
global $wgMessageCache, $wgMemc;
- $wgMessageCache = new MessageCache( $wgMemc, true, 3600, '' );
+ $wgMessageCache = new MessageCache( $wgMemc, true, 3600 );
+
+ $this->uploadDir = $this->setupUploadDir();
+ $user = User::createNew( 'WikiSysop' );
+ $image = wfLocalFile( Title::makeTitle( NS_FILE, 'Foobar.jpg' ) );
+ $image->recordUpload2( '', 'Upload of some lame file', 'Some lame file', array(
+ 'size' => 12345,
+ 'width' => 1941,
+ 'height' => 220,
+ 'bits' => 24,
+ 'media_type' => MEDIATYPE_BITMAP,
+ 'mime' => 'image/jpeg',
+ 'metadata' => serialize( array() ),
+ 'sha1' => sha1(''),
+ 'fileExists' => true
+ ), $db->timestamp( '20010115123500' ), $user );
+
+ # This image will be blacklisted in [[MediaWiki:Bad image list]]
+ $image = wfLocalFile( Title::makeTitle( NS_FILE, 'Bad.jpg' ) );
+ $image->recordUpload2( '', 'zomgnotcensored', 'Borderline image', array(
+ 'size' => 12345,
+ 'width' => 320,
+ 'height' => 240,
+ 'bits' => 24,
+ 'media_type' => MEDIATYPE_BITMAP,
+ 'mime' => 'image/jpeg',
+ 'metadata' => serialize( array() ),
+ 'sha1' => sha1(''),
+ 'fileExists' => true
+ ), $db->timestamp( '20010115123500' ), $user );
}
/**
if ( !$this->databaseSetupDone ) {
return;
}
+ $this->teardownUploadDir( $this->uploadDir );
+
$this->changePrefix( $this->oldTablePrefix );
$this->databaseSetupDone = false;
if ( $this->useTemporaryTables ) {
return;
}
- /*
$tables = $this->listTables();
$db = wfGetDB( DB_MASTER );
foreach ( $tables as $table ) {
}
if ($wgDBtype == 'oracle')
$db->query('BEGIN FILL_WIKI_INFO; END;');
- */
}
/**
$dir = wfTempDir() . "/mwParser-" . mt_rand() . "-images";
}
- wfDebug( "Creating upload directory $dir\n" );
+ //wfDebug( "Creating upload directory $dir\n" );
if ( file_exists( $dir ) ) {
wfDebug( "Already exists!\n" );
return $dir;
}
wfMkdirParents( $dir . '/3/3a' );
copy( "$IP/skins/monobook/headbg.jpg", "$dir/3/3a/Foobar.jpg" );
-
wfMkdirParents( $dir . '/0/09' );
copy( "$IP/skins/monobook/headbg.jpg", "$dir/0/09/Bad.jpg" );
return $dir;
foreach ( $this->savedGlobals as $var => $val ) {
$GLOBALS[$var] = $val;
}
- if ( isset( $this->uploadDir ) ) {
- $this->teardownUploadDir( $this->uploadDir );
- unset( $this->uploadDir );
- }
}
/**
return preg_replace(
array( '/^(-.*)$/m', '/^(\+.*)$/m' ),
array( $this->term->color( 34 ) . '$1' . $this->term->reset(),
- $this->term->color( 31 ) . '$1' . $this->term->reset() ),
+ $this->term->color( 31 ) . '$1' . $this->term->reset() ),
$text );
}
* @param $line Integer: the input line number, for reporting errors
*/
public function addArticle( $name, $text, $line ) {
- $this->setupGlobals();
+ global $wgCapitalLinks;
+ $oldCapitalLinks = $wgCapitalLinks;
+ $wgCapitalLinks = true; // We only need this from SetupGlobals() See r70917#c8637
+
$title = Title::newFromText( $name );
if ( is_null( $title ) ) {
wfDie( "invalid title at line $line\n" );
$art = new Article( $title );
$art->insertNewArticle( $text, '', false, false );
- $this->teardownGlobals();
+ $wgCapitalLinks = $oldCapitalLinks;
}
/**
* Steal a callback function from the primary parser, save it for
* application to our scary parser. If the hook is not installed,
- * die a painful dead to warn the others.
+ * abort processing of this file.
*
* @param $name String
+ * @return Bool true if tag hook is present
*/
public function requireHook( $name ) {
global $wgParser;
if ( isset( $wgParser->mTagHooks[$name] ) ) {
$this->hooks[$name] = $wgParser->mTagHooks[$name];
} else {
- wfDie( "This test suite requires the '$name' hook extension.\n" );
+ echo " This test suite requires the '$name' hook extension, skipping.\n";
+ return false;
}
+ return true;
}
/**
* Steal a callback function from the primary parser, save it for
* application to our scary parser. If the hook is not installed,
- * die a painful dead to warn the others.
+ * abort processing of this file.
*
* @param $name String
+ * @return Bool true if function hook is present
*/
public function requireFunctionHook( $name ) {
global $wgParser;
if ( isset( $wgParser->mFunctionHooks[$name] ) ) {
$this->functionHooks[$name] = $wgParser->mFunctionHooks[$name];
} else {
- wfDie( "This test suite requires the '$name' function hook extension.\n" );
+ echo " This test suite requires the '$name' function hook extension, skipping.\n";
+ return false;
}
+ return true;
}
/*
private function tidy( $text ) {
global $wgUseTidy;
if ( $wgUseTidy ) {
- $text = Parser::tidy( $text );
+ $text = MWTidy::tidy( $text );
}
return $text;
}
return "$display\n$caret";
}
- function getFakeTimestamp( &$parser, &$ts ) {
+ static function getFakeTimestamp( &$parser, &$ts ) {
$ts = 123;
return true;
}
* and all that fun stuff
*/
function start() {
- global $wgDBtype;
parent::start();
if ( ! $this->db->tableExists( 'testrun' )
}
/**
- ** Returns a string giving information about when a test last had a status change.
- ** Could help to track down when regressions were introduced, as distinct from tests
- ** which have never passed (which are more change requests than regressions).
+ * Returns a string giving information about when a test last had a status change.
+ * Could help to track down when regressions were introduced, as distinct from tests
+ * which have never passed (which are more change requests than regressions).
*/
private function getTestStatusInfo( $testname, $after ) {
// If we're looking at a test that has just been removed, then say when it first appeared.
if ( $after == 'n' ) {
$changedRun = $this->db->selectField ( 'testitem',
- 'MIN(ti_run)',
- array( 'ti_name' => $testname ),
- __METHOD__ );
+ 'MIN(ti_run)',
+ array( 'ti_name' => $testname ),
+ __METHOD__ );
$appear = $this->db->selectRow ( 'testrun',
- array( 'tr_date', 'tr_mw_version' ),
- array( 'tr_id' => $changedRun ),
- __METHOD__ );
+ array( 'tr_date', 'tr_mw_version' ),
+ array( 'tr_id' => $changedRun ),
+ __METHOD__ );
return "First recorded appearance: "
- . date( "d-M-Y H:i:s", strtotime ( $appear->tr_date ) )
- . ", " . $appear->tr_mw_version;
+ . date( "d-M-Y H:i:s", strtotime ( $appear->tr_date ) )
+ . ", " . $appear->tr_mw_version;
}
// Otherwise, this test has previous recorded results.
// (i.e. it used to work, but now doesn't; or used to fail, but is now fixed.)
// In this situation, give as much info as we can as to when it changed status.
$pre = $this->db->selectRow ( 'testrun',
- array( 'tr_date', 'tr_mw_version' ),
- array( 'tr_id' => $changedRun ),
- __METHOD__ );
+ array( 'tr_date', 'tr_mw_version' ),
+ array( 'tr_id' => $changedRun ),
+ __METHOD__ );
$post = $this->db->selectRow ( 'testrun',
- array( 'tr_date', 'tr_mw_version' ),
- array( "tr_id > " . $this->db->addQuotes ( $changedRun ) ),
- __METHOD__,
- array( "LIMIT" => 1, "ORDER BY" => 'tr_id' )
- );
+ array( 'tr_date', 'tr_mw_version' ),
+ array( "tr_id > " . $this->db->addQuotes ( $changedRun ) ),
+ __METHOD__,
+ array( "LIMIT" => 1, "ORDER BY" => 'tr_id' )
+ );
if ( $post ) {
$postDate = date( "d-M-Y H:i:s", strtotime ( $post->tr_date ) ) . ", {$post->tr_mw_version}";
}
class DbTestRecorder extends DbTestPreviewer {
+ var $version;
+
/**
* Set up result recording; insert a record for the run with the date
* and all that fun stuff
*/
function start() {
- global $wgDBtype, $options;
+ global $wgDBtype;
$this->db->begin();
if ( ! $this->db->tableExists( 'testrun' )
$this->db->insert( 'testrun',
array(
'tr_date' => $this->db->timestamp(),
- 'tr_mw_version' => isset( $options['setversion'] ) ?
- $options['setversion'] : SpecialVersion::getVersion(),
+ 'tr_mw_version' => $this->version,
'tr_php_version' => phpversion(),
'tr_db_version' => $this->db->getServerVersion(),
'tr_uname' => php_uname()
$remote = $wgParserTestRemote;
$revId = SpecialVersion::getSvnRevision( $IP );
- $jsonResults = json_encode( $results );
+ $jsonResults = FormatJson::encode( $results );
if ( !$remote ) {
print "Can't do remote upload without configuring \$wgParserTestRemote!\n";
}
class TestFileIterator implements Iterator {
- private $file;
- private $fh;
- private $parser;
- private $index = 0;
- private $test;
+ private $file;
+ private $fh;
+ private $parser;
+ private $index = 0;
+ private $test;
private $lineNum;
private $eof;
global $IP;
$this->file = $file;
- $this->fh = fopen( $this->file, "rt" );
- if ( !$this->fh ) {
+ $this->fh = fopen( $this->file, "rt" );
+ if ( !$this->fh ) {
wfDie( "Couldn't open file '$file'\n" );
}
$this->next();
return true;
- }
+ }
- function current() {
+ function current() {
return $this->test;
- }
+ }
- function key() {
+ function key() {
return $this->index;
- }
+ }
- function next() {
- if ( $this->readNextTest() ) {
+ function next() {
+ if ( $this->readNextTest() ) {
$this->index++;
return true;
} else {
$this->eof = true;
}
- }
+ }
- function valid() {
+ function valid() {
return $this->eof != true;
- }
+ }
function readNextTest() {
$data = array();
foreach ( explode( "\n", $data['hooks'] ) as $line ) {
$line = trim( $line );
if ( $line ) {
- if ( $this->parser ) $this->parser->requireHook( $line );
+ if ( $this->parser && !$this->parser->requireHook( $line ) ) {
+ return false;
+ }
}
}
$data = array();
foreach ( explode( "\n", $data['functionhooks'] ) as $line ) {
$line = trim( $line );
if ( $line ) {
- if ( $this->parser ) $this->parser->requireFunctionHook( $line );
+ if ( $this->parser && !$this->parser->requireFunctionHook( $line ) ) {
+ return false;
+ }
}
}
$data = array();
$section = null;
continue;
}
+ global $wgUseTeX;
if ( $this->parser &&
- preg_match( '/\\bmath\\b/i', $data['options'] ) && !$this->parser->savedGlobals['wgUseTeX'] ) {
+ preg_match( '/\\bmath\\b/i', $data['options'] ) && !$wgUseTeX ) {
# don't run math tests if $wgUseTeX is set to false in LocalSettings
$data = array();
$section = null;