* Replace wfMungeToUtf8 and do_html_entity_decode with a single function
[lhc/web/wiklou.git] / tests / RunTests.php
1 <?php
2
3 if( php_sapi_name() != 'cli' ) {
4 die( 'Must be run from the command line.' );
5 }
6
7 error_reporting( E_ALL );
8 define( "MEDIAWIKI", true );
9
10 require_once( 'PHPUnit.php' );
11
12 $testOptions = array(
13 'mysql3' => array(
14 'server' => null,
15 'user' => null,
16 'password' => null,
17 'database' => null ),
18 'mysql4' => array(
19 'server' => null,
20 'user' => null,
21 'password' => null,
22 'database' => null ),
23 'postgresql' => array(
24 'server' => null,
25 'user' => null,
26 'password' => null,
27 'database' => null ),
28 );
29
30 if( file_exists( 'LocalTestSettings.php' ) ) {
31 include( './LocalTestSettings.php' );
32 }
33
34 $tests = array(
35 'GlobalTest',
36 'DatabaseTest',
37 'SearchMySQL3Test',
38 'SearchMySQL4Test',
39 'ArticleTest',
40 'SanitizerTest',
41 );
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();
47 }
48
49 /**
50 * @param string $serverType
51 * @param array $tables
52 */
53 function &buildTestDatabase( $serverType, $tables ) {
54 global $testOptions, $wgDBprefix;
55 $wgDBprefix = 'parsertest';
56 $db =& new Database(
57 $testOptions[$serverType]['server'],
58 $testOptions[$serverType]['user'],
59 $testOptions[$serverType]['password'],
60 $testOptions[$serverType]['database'] );
61 if( $db->isOpen() ) {
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];
67 $tableName = $tbl;
68 $db->query("CREATE TEMPORARY TABLE $newTableName (LIKE $tableName INCLUDING DEFAULTS)");
69 }
70 } else {
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);
78 $create = $row[1];
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");
84 }
85 $db->query($create_tmp);
86 }
87
88 }
89 return $db;
90 } else {
91 // Something amiss
92 return null;
93 }
94 }
95
96 ?>