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 set_include_path( get_include_path() . PATH_SEPARATOR
. 'PHPUnit' );
12 set_include_path( get_include_path() . PATH_SEPARATOR
. '..' );
13 require_once( 'PHPUnit.php' );
21 'postgresql' => array(
28 if( file_exists( 'LocalTestSettings.php' ) ) {
29 include( './LocalTestSettings.php' );
41 if( isset( $_SERVER['argv'][1] ) ) {
43 $tests = array( $_SERVER['argv'][1] );
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();
54 * @param string $serverType
55 * @param array $tables
57 function &buildTestDatabase( $serverType, $tables ) {
58 global $testOptions, $wgDBprefix;
59 $wgDBprefix = 'parsertest';
61 $testOptions[$serverType]['server'],
62 $testOptions[$serverType]['user'],
63 $testOptions[$serverType]['password'],
64 $testOptions[$serverType]['database'] );
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];
72 $db->query("CREATE TEMPORARY TABLE $newTableName (LIKE $tableName INCLUDING DEFAULTS)");
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);
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" );
89 $db->query($create_tmp);