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