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' );
41 foreach( $tests as $test ) {
42 require_once( $test . '.php' );
43 $suite = new PHPUnit_TestSuite( $test );
44 $result = PHPUnit
::run( $suite );
45 echo $result->toString();
49 * @param string $serverType
50 * @param array $tables
52 function &buildTestDatabase( $serverType, $tables ) {
53 global $testOptions, $wgDBprefix;
54 $wgDBprefix = 'parsertest';
56 $testOptions[$serverType]['server'],
57 $testOptions[$serverType]['user'],
58 $testOptions[$serverType]['password'],
59 $testOptions[$serverType]['database'] );
61 if (!(strcmp($db->getServerVersion(), '4.1') < 0 and stristr($db->getSoftwareLink(), 'MySQL'))) {
62 # Database that supports CREATE TABLE ... LIKE
63 foreach ($tables as $tbl) {
64 $newTableName = $db->tableName( $tbl );
65 #$tableName = $this->oldTableNames[$tbl];
67 $db->query("CREATE TEMPORARY TABLE $newTableName (LIKE $tableName INCLUDING DEFAULTS)");
70 # Hack for MySQL versions < 4.1, which don't support
71 # "CREATE TABLE ... LIKE". Note that
72 # "CREATE TEMPORARY TABLE ... SELECT * FROM ... LIMIT 0"
73 # would not create the indexes we need....
74 foreach ($tables as $tbl) {
75 $res = $db->query("SHOW CREATE TABLE $tbl");
76 $row = $db->fetchRow($res);
78 $create_tmp = preg_replace('/CREATE TABLE `(.*?)`/', 'CREATE TEMPORARY TABLE `'
79 . $wgDBprefix . '\\1`', $create);
80 if ($create === $create_tmp) {
81 # Couldn't do replacement
82 die("could not create temporary table $tbl");
84 $db->query($create_tmp);