Merged filerepo-work branch:
[lhc/web/wiklou.git] / tests / RunTests.php
1 <?php
2
3 die( "This is broken, use run-test.php for now.\n" );
4
5 require_once( dirname( __FILE__ ) . '/../maintenance/commandLine.inc' );
6 ini_set( 'include_path', get_include_path() . PATH_SEPARATOR . /*$_SERVER['PHP_PEAR_INSTALL_DIR']*/ 'C:\php\pear' );
7 error_reporting( E_ALL );
8 require_once( 'PHPUnit/Framework.php' );
9
10 $testOptions = array(
11 'mysql4' => array(
12 'server' => null,
13 'user' => null,
14 'password' => null,
15 'database' => null ),
16 'postgres' => array(
17 'server' => null,
18 'user' => null,
19 'password' => null,
20 'database' => null ),
21 );
22
23 $tests = array(
24 'GlobalTest',
25 'DatabaseTest',
26 'SearchMySQL4Test',
27 'ArticleTest',
28 'SanitizerTest',
29 'ImageTest'
30 );
31
32 if( count( $args ) ) {
33 // to override...
34 $tests = $args;
35 }
36
37 foreach( $tests as $test ) {
38 require_once( $test . '.php' );
39 $suite = new PHPUnit_Framework_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 ?>