Add initial tests for Article::getRevisionText and Article::compressRevision
[lhc/web/wiklou.git] / tests / RunTests.php
1 <?php
2 error_reporting( E_ALL );
3 define( "MEDIAWIKI", true );
4
5 require_once( 'PHPUnit.php' );
6
7 $testOptions = array(
8 'mysql3' => array(
9 'server' => null,
10 'user' => null,
11 'password' => null,
12 'database' => null ),
13 'mysql4' => array(
14 'server' => null,
15 'user' => null,
16 'password' => null,
17 'database' => null ),
18 'postgresql' => array(
19 'server' => null,
20 'user' => null,
21 'password' => null,
22 'database' => null ),
23 );
24
25 if( file_exists( 'LocalTestSettings.php' ) ) {
26 include( './LocalTestSettings.php' );
27 }
28
29 $tests = array(
30 'GlobalTest',
31 'DatabaseTest',
32 'SearchMySQL3Test',
33 'SearchMySQL4Test',
34 'ArticleTest',
35 );
36 foreach( $tests as $test ) {
37 require_once( $test . '.php' );
38 $suite = new PHPUnit_TestSuite( $test );
39 $result = PHPUnit::run( $suite );
40 echo $result->toString();
41 }
42
43 /**
44 * @param string $serverType
45 * @param array $tables
46 */
47 function &buildTestDatabase( $serverType, $tables ) {
48 global $testOptions, $wgDBprefix;
49 $wgDBprefix = 'parsertest';
50 $db =& new Database(
51 $testOptions[$serverType]['server'],
52 $testOptions[$serverType]['user'],
53 $testOptions[$serverType]['password'],
54 $testOptions[$serverType]['database'] );
55 if( $db->isOpen() ) {
56 if (!(strcmp($db->getServerVersion(), '4.1') < 0 and stristr($db->getSoftwareLink(), 'MySQL'))) {
57 # Database that supports CREATE TABLE ... LIKE
58 foreach ($tables as $tbl) {
59 $newTableName = $db->tableName( $tbl );
60 #$tableName = $this->oldTableNames[$tbl];
61 $tableName = $tbl;
62 $db->query("CREATE TEMPORARY TABLE $newTableName (LIKE $tableName INCLUDING DEFAULTS)");
63 }
64 } else {
65 # Hack for MySQL versions < 4.1, which don't support
66 # "CREATE TABLE ... LIKE". Note that
67 # "CREATE TEMPORARY TABLE ... SELECT * FROM ... LIMIT 0"
68 # would not create the indexes we need....
69 foreach ($tables as $tbl) {
70 $res = $db->query("SHOW CREATE TABLE $tbl");
71 $row = $db->fetchRow($res);
72 $create = $row[1];
73 $create_tmp = preg_replace('/CREATE TABLE `(.*?)`/', 'CREATE TEMPORARY TABLE `'
74 . $wgDBprefix . '\\1`', $create);
75 if ($create === $create_tmp) {
76 # Couldn't do replacement
77 die("could not create temporary table $tbl");
78 }
79 $db->query($create_tmp);
80 }
81
82 }
83 return $db;
84 } else {
85 // Something amiss
86 return null;
87 }
88 }
89
90 ?>