Follow-up r61938: also port SearchUpdate test
[lhc/web/wiklou.git] / tests / MediaWiki_TestCase.php
1 <?php
2
3 abstract class MediaWiki_TestCase extends PHPUnit_Framework_TestCase {
4 /**
5 * @param string $serverType
6 * @param array $tables
7 */
8 protected function buildTestDatabase( $tables ) {
9 global $testOptions, $wgDBprefix, $wgDBserver, $wgDBadminuser, $wgDBadminpassword, $wgDBname;
10 $this->markTestIncomplete("This test requires DB admin user credentials.");
11 $wgDBprefix = 'parsertest_';
12
13 $db = new DatabaseMysql(
14 $wgDBserver,
15 $wgDBadminuser,
16 $wgDBadminpassword,
17 $wgDBname );
18 if( $db->isOpen() ) {
19 if (!(strcmp($db->getServerVersion(), '4.1') < 0 and stristr($db->getSoftwareLink(), 'MySQL'))) {
20 # Database that supports CREATE TABLE ... LIKE
21 foreach ($tables as $tbl) {
22 $newTableName = $db->tableName( $tbl );
23 #$tableName = $this->oldTableNames[$tbl];
24 $tableName = $tbl;
25 $db->query("CREATE TEMPORARY TABLE $newTableName (LIKE $tableName)");
26 }
27 } else {
28 # Hack for MySQL versions < 4.1, which don't support
29 # "CREATE TABLE ... LIKE". Note that
30 # "CREATE TEMPORARY TABLE ... SELECT * FROM ... LIMIT 0"
31 # would not create the indexes we need....
32 foreach ($tables as $tbl) {
33 $res = $db->query("SHOW CREATE TABLE $tbl");
34 $row = $db->fetchRow($res);
35 $create = $row[1];
36 $create_tmp = preg_replace('/CREATE TABLE `(.*?)`/', 'CREATE TEMPORARY TABLE `'
37 . $wgDBprefix . '\\1`', $create);
38 if ($create === $create_tmp) {
39 # Couldn't do replacement
40 wfDie( "could not create temporary table $tbl" );
41 }
42 $db->query($create_tmp);
43 }
44
45 }
46 return $db;
47 } else {
48 // Something amiss
49 return null;
50 }
51 }
52 }
53