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