Ignore USE INDEX option.
[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 set_include_path( get_include_path() . PATH_SEPARATOR . 'PHPUnit' );
12 set_include_path( get_include_path() . PATH_SEPARATOR . '..' );
13 require_once( 'PHPUnit.php' );
14
15 $testOptions = array(
16 'mysql4' => array(
17 'server' => null,
18 'user' => null,
19 'password' => null,
20 'database' => null ),
21 'postgres' => array(
22 'server' => null,
23 'user' => null,
24 'password' => null,
25 'database' => null ),
26 );
27
28 if( file_exists( 'LocalTestSettings.php' ) ) {
29 include( './LocalTestSettings.php' );
30 }
31
32 $tests = array(
33 'GlobalTest',
34 'DatabaseTest',
35 'SearchMySQL4Test',
36 'ArticleTest',
37 'SanitizerTest',
38 'ImageTest'
39 );
40
41 if( isset( $_SERVER['argv'][1] ) ) {
42 // to override...
43 $tests = array( $_SERVER['argv'][1] );
44 }
45
46 foreach( $tests as $test ) {
47 require_once( $test . '.php' );
48 $suite = new PHPUnit_TestSuite( $test );
49 $result = PHPUnit::run( $suite );
50 echo $result->toString();
51 }
52
53 /**
54 * @param string $serverType
55 * @param array $tables
56 */
57 function &buildTestDatabase( $serverType, $tables ) {
58 global $testOptions, $wgDBprefix;
59 $wgDBprefix = 'parsertest';
60 $db = new Database(
61 $testOptions[$serverType]['server'],
62 $testOptions[$serverType]['user'],
63 $testOptions[$serverType]['password'],
64 $testOptions[$serverType]['database'] );
65 if( $db->isOpen() ) {
66 if (!(strcmp($db->getServerVersion(), '4.1') < 0 and stristr($db->getSoftwareLink(), 'MySQL'))) {
67 # Database that supports CREATE TABLE ... LIKE
68 foreach ($tables as $tbl) {
69 $newTableName = $db->tableName( $tbl );
70 #$tableName = $this->oldTableNames[$tbl];
71 $tableName = $tbl;
72 $db->query("CREATE TEMPORARY TABLE $newTableName (LIKE $tableName INCLUDING DEFAULTS)");
73 }
74 } else {
75 # Hack for MySQL versions < 4.1, which don't support
76 # "CREATE TABLE ... LIKE". Note that
77 # "CREATE TEMPORARY TABLE ... SELECT * FROM ... LIMIT 0"
78 # would not create the indexes we need....
79 foreach ($tables as $tbl) {
80 $res = $db->query("SHOW CREATE TABLE $tbl");
81 $row = $db->fetchRow($res);
82 $create = $row[1];
83 $create_tmp = preg_replace('/CREATE TABLE `(.*?)`/', 'CREATE TEMPORARY TABLE `'
84 . $wgDBprefix . '\\1`', $create);
85 if ($create === $create_tmp) {
86 # Couldn't do replacement
87 wfDie( "could not create temporary table $tbl" );
88 }
89 $db->query($create_tmp);
90 }
91
92 }
93 return $db;
94 } else {
95 // Something amiss
96 return null;
97 }
98 }
99
100 ?>