Reorganization of SearchEngine for legibility
[lhc/web/wiklou.git] / tests / RunTests.php
1 <?php
2 error_reporting( E_ALL );
3 define( "MEDIAWIKI", true );
4
5 require_once( 'PHPUnit.php' );
6
7 $testOptions = array(
8 'mysql3' => array(
9 'server' => null,
10 'user' => null,
11 'password' => null,
12 'database' => null ),
13 'mysql4' => array(
14 'server' => null,
15 'user' => null,
16 'password' => null,
17 'database' => null ),
18 'postgresql' => array(
19 'server' => null,
20 'user' => null,
21 'password' => null,
22 'database' => null ),
23 );
24
25 if( file_exists( 'LocalTestSettings.php' ) ) {
26 include( './LocalTestSettings.php' );
27 }
28
29 $tests = array(
30 'GlobalTest',
31 'DatabaseTest',
32 'SearchMySQL3Test',
33 'SearchMySQL4Test',
34 );
35 foreach( $tests as $test ) {
36 require_once( $test . '.php' );
37 $suite = new PHPUnit_TestSuite( $test );
38 $result = PHPUnit::run( $suite );
39 echo $result->toString();
40 }
41
42 /**
43 * @param string $serverType
44 * @param array $tables
45 */
46 function &buildTestDatabase( $serverType, $tables ) {
47 global $testOptions, $wgDBprefix;
48 $wgDBprefix = 'parsertest';
49 $db =& new Database(
50 $testOptions[$serverType]['server'],
51 $testOptions[$serverType]['user'],
52 $testOptions[$serverType]['password'],
53 $testOptions[$serverType]['database'] );
54 if( $db->isOpen() ) {
55 if (!(strcmp($db->getServerVersion(), '4.1') < 0 and stristr($db->getSoftwareLink(), 'MySQL'))) {
56 # Database that supports CREATE TABLE ... LIKE
57 foreach ($tables as $tbl) {
58 $newTableName = $db->tableName( $tbl );
59 #$tableName = $this->oldTableNames[$tbl];
60 $tableName = $tbl;
61 $db->query("CREATE TEMPORARY TABLE $newTableName (LIKE $tableName INCLUDING DEFAULTS)");
62 }
63 } else {
64 # Hack for MySQL versions < 4.1, which don't support
65 # "CREATE TABLE ... LIKE". Note that
66 # "CREATE TEMPORARY TABLE ... SELECT * FROM ... LIMIT 0"
67 # would not create the indexes we need....
68 foreach ($tables as $tbl) {
69 $res = $db->query("SHOW CREATE TABLE $tbl");
70 $row = $db->fetchRow($res);
71 $create = $row[1];
72 $create_tmp = preg_replace('/CREATE TABLE `(.*?)`/', 'CREATE TEMPORARY TABLE `'
73 . $wgDBprefix . '\\1`', $create);
74 if ($create === $create_tmp) {
75 # Couldn't do replacement
76 die("could not create temporary table $tbl");
77 }
78 $db->query($create_tmp);
79 }
80
81 }
82 return $db;
83 } else {
84 // Something amiss
85 return null;
86 }
87 }
88
89 ?>