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' );
30 if( file_exists( 'LocalTestSettings.php' ) ) {
31 include( './LocalTestSettings.php' );
43 if( isset( $_SERVER['argv'][1] ) ) {
45 $tests = array( $_SERVER['argv'][1] );
48 foreach( $tests as $test ) {
49 require_once( $test . '.php' );
50 $suite = new PHPUnit_TestSuite( $test );
51 $result = PHPUnit
::run( $suite );
52 echo $result->toString();
56 * @param string $serverType
57 * @param array $tables
59 function &buildTestDatabase( $serverType, $tables ) {
60 global $testOptions, $wgDBprefix;
61 $wgDBprefix = 'parsertest';
63 $testOptions[$serverType]['server'],
64 $testOptions[$serverType]['user'],
65 $testOptions[$serverType]['password'],
66 $testOptions[$serverType]['database'] );
68 if (!(strcmp($db->getServerVersion(), '4.1') < 0 and stristr($db->getSoftwareLink(), 'MySQL'))) {
69 # Database that supports CREATE TABLE ... LIKE
70 foreach ($tables as $tbl) {
71 $newTableName = $db->tableName( $tbl );
72 #$tableName = $this->oldTableNames[$tbl];
74 $db->query("CREATE TEMPORARY TABLE $newTableName (LIKE $tableName INCLUDING DEFAULTS)");
77 # Hack for MySQL versions < 4.1, which don't support
78 # "CREATE TABLE ... LIKE". Note that
79 # "CREATE TEMPORARY TABLE ... SELECT * FROM ... LIMIT 0"
80 # would not create the indexes we need....
81 foreach ($tables as $tbl) {
82 $res = $db->query("SHOW CREATE TABLE $tbl");
83 $row = $db->fetchRow($res);
85 $create_tmp = preg_replace('/CREATE TABLE `(.*?)`/', 'CREATE TEMPORARY TABLE `'
86 . $wgDBprefix . '\\1`', $create);
87 if ($create === $create_tmp) {
88 # Couldn't do replacement
89 wfDie( "could not create temporary table $tbl" );
91 $db->query($create_tmp);