From: Brion Vibber Date: Thu, 23 Sep 2004 22:23:28 +0000 (+0000) Subject: Break temporary table creation out to setupDatabase() function. X-Git-Tag: 1.5.0alpha1~1837 X-Git-Url: https://git.cyclocoop.org/%7B%7B%20url_for%28%27votes%27%2C%20votes=%27waiting%27%29%20%7D%7D?a=commitdiff_plain;h=3f6f15c2cceaf3974fbf3935934ea0d1ba1b4ff3;p=lhc%2Fweb%2Fwiklou.git Break temporary table creation out to setupDatabase() function. Tweak so that the temporary prefix will actually be used. --- diff --git a/maintenance/parserTests.php b/maintenance/parserTests.php index c33b38d296..449af4655c 100644 --- a/maintenance/parserTests.php +++ b/maintenance/parserTests.php @@ -156,27 +156,6 @@ class ParserTest { print "Running test $desc... "; $this->setupGlobals(); - - # This is ugly, but we need a way to modify the database - # without breaking anything. Currently it isn't possible - # to roll back transactions, which might help with this. - # -- wtm - static $setupDB = false; - if (!$setupDB && $GLOBALS['wgDBprefix'] === 'parsertest') { - $db =& wfGetDB( DB_MASTER ); - if (0) { - # XXX CREATE TABLE ... LIKE requires MySQL 4.1 - $tables = array('cur', 'interwiki', 'brokenlinks', 'recentchanges'); - foreach ($tables as $tbl) { - $db->query('CREATE TEMPORARY TABLE ' . $GLOBALS['wgDBprefix'] . "$tbl LIKE $tbl"); - } - } - else { - # HACK, sorry - dbsource( 'maintenance/parserTests.sql', $db ); - } - $setupDB = true; - } $user =& new User(); $options =& ParserOptions::newFromUser( $user ); @@ -237,14 +216,49 @@ class ParserTest { 'wgSitename' => 'MediaWiki', 'wgLanguageCode' => 'en', 'wgUseLatin1' => false, - 'wgLang' => new LanguageUtf8(), 'wgDBprefix' => 'parsertest', + + 'wgLoadBalancer' => LoadBalancer::newFromParams( $GLOBALS['wgDBservers'] ), + 'wgLang' => new LanguageUtf8(), ); $this->savedGlobals = array(); foreach( $settings as $var => $val ) { $this->savedGlobals[$var] = $GLOBALS[$var]; $GLOBALS[$var] = $val; } + $GLOBALS['wgLoadBalancer']->loadMasterPos(); + $this->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. + * + * This is ugly, but we need a way to modify the database + * without breaking anything. Currently it isn't possible + * to roll back transactions, which might help with this. + * -- wtm + * + * @access private + */ + function setupDatabase() { + static $setupDB = false; + if (!$setupDB && $GLOBALS['wgDBprefix'] === 'parsertest') { + $db =& wfGetDB( DB_MASTER ); + if (0) { + # XXX CREATE TABLE ... LIKE requires MySQL 4.1 + $tables = array('cur', 'interwiki', 'brokenlinks', 'recentchanges'); + foreach ($tables as $tbl) { + $db->query('CREATE TEMPORARY TABLE ' . $GLOBALS['wgDBprefix'] . "$tbl LIKE $tbl"); + } + } + else { + # HACK, sorry + dbsource( 'maintenance/parserTests.sql', $db ); + } + $setupDB = true; + } } /** @@ -374,9 +388,11 @@ class ParserTest { * @access private */ function addArticle($name, $text) { + $this->setupGlobals(); $title = Title::newFromText( $name ); $art = new Article($title); $art->insertNewArticle($text, '', false, false ); + $this->teardownGlobals(); } }