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