3 if( php_sapi_name() != 'cli' ) {
4 die( 'Must be run from the command line.' );
7 error_reporting( E_ALL
);
8 define( "MEDIAWIKI", true );
10 require_once( 'PHPUnit.php' );
23 'postgresql' => array(
30 if( file_exists( 'LocalTestSettings.php' ) ) {
31 include( './LocalTestSettings.php' );
42 foreach( $tests as $test ) {
43 require_once( $test . '.php' );
44 $suite = new PHPUnit_TestSuite( $test );
45 $result = PHPUnit
::run( $suite );
46 echo $result->toString();
50 * @param string $serverType
51 * @param array $tables
53 function &buildTestDatabase( $serverType, $tables ) {
54 global $testOptions, $wgDBprefix;
55 $wgDBprefix = 'parsertest';
57 $testOptions[$serverType]['server'],
58 $testOptions[$serverType]['user'],
59 $testOptions[$serverType]['password'],
60 $testOptions[$serverType]['database'] );
62 if (!(strcmp($db->getServerVersion(), '4.1') < 0 and stristr($db->getSoftwareLink(), 'MySQL'))) {
63 # Database that supports CREATE TABLE ... LIKE
64 foreach ($tables as $tbl) {
65 $newTableName = $db->tableName( $tbl );
66 #$tableName = $this->oldTableNames[$tbl];
68 $db->query("CREATE TEMPORARY TABLE $newTableName (LIKE $tableName INCLUDING DEFAULTS)");
71 # Hack for MySQL versions < 4.1, which don't support
72 # "CREATE TABLE ... LIKE". Note that
73 # "CREATE TEMPORARY TABLE ... SELECT * FROM ... LIMIT 0"
74 # would not create the indexes we need....
75 foreach ($tables as $tbl) {
76 $res = $db->query("SHOW CREATE TABLE $tbl");
77 $row = $db->fetchRow($res);
79 $create_tmp = preg_replace('/CREATE TABLE `(.*?)`/', 'CREATE TEMPORARY TABLE `'
80 . $wgDBprefix . '\\1`', $create);
81 if ($create === $create_tmp) {
82 # Couldn't do replacement
83 die("could not create temporary table $tbl");
85 $db->query($create_tmp);