00001 <?php
00002
00003 abstract class MediaWiki_TestCase extends PHPUnit_Framework_TestCase {
00008 protected function buildTestDatabase( $tables ) {
00009 global $testOptions, $wgDBprefix, $wgDBserver, $wgDBadminuser, $wgDBadminpassword, $wgDBname;
00010 $wgDBprefix = 'parsertest_';
00011 $db = new Database(
00012 $wgDBserver,
00013 $wgDBadminuser,
00014 $wgDBadminpassword,
00015 $wgDBname );
00016 if( $db->isOpen() ) {
00017 if (!(strcmp($db->getServerVersion(), '4.1') < 0 and stristr($db->getSoftwareLink(), 'MySQL'))) {
00018 # Database that supports CREATE TABLE ... LIKE
00019 foreach ($tables as $tbl) {
00020 $newTableName = $db->tableName( $tbl );
00021 #$tableName = $this->oldTableNames[$tbl];
00022 $tableName = $tbl;
00023 $db->query("CREATE TEMPORARY TABLE $newTableName (LIKE $tableName)");
00024 }
00025 } else {
00026 # Hack for MySQL versions < 4.1, which don't support
00027 # "CREATE TABLE ... LIKE". Note that
00028 # "CREATE TEMPORARY TABLE ... SELECT * FROM ... LIMIT 0"
00029 # would not create the indexes we need....
00030 foreach ($tables as $tbl) {
00031 $res = $db->query("SHOW CREATE TABLE $tbl");
00032 $row = $db->fetchRow($res);
00033 $create = $row[1];
00034 $create_tmp = preg_replace('/CREATE TABLE `(.*?)`/', 'CREATE TEMPORARY TABLE `'
00035 . $wgDBprefix . '\\1`', $create);
00036 if ($create === $create_tmp) {
00037 # Couldn't do replacement
00038 wfDie( "could not create temporary table $tbl" );
00039 }
00040 $db->query($create_tmp);
00041 }
00042
00043 }
00044 return $db;
00045 } else {
00046
00047 return null;
00048 }
00049 }
00050 }
00051