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