3 if( php_sapi_name() != 'cli' ) {
4 echo 'Must be run from the command line.';
8 error_reporting( E_ALL
);
9 define( "MEDIAWIKI", true );
11 require_once( 'PHPUnit.php' );
19 'postgresql' => array(
26 if( file_exists( 'LocalTestSettings.php' ) ) {
27 include( './LocalTestSettings.php' );
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();
45 * @param string $serverType
46 * @param array $tables
48 function &buildTestDatabase( $serverType, $tables ) {
49 global $testOptions, $wgDBprefix;
50 $wgDBprefix = 'parsertest';
52 $testOptions[$serverType]['server'],
53 $testOptions[$serverType]['user'],
54 $testOptions[$serverType]['password'],
55 $testOptions[$serverType]['database'] );
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];
63 $db->query("CREATE TEMPORARY TABLE $newTableName (LIKE $tableName INCLUDING DEFAULTS)");
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);
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" );
80 $db->query($create_tmp);