Revert r74286, r74287 -- broke parserTests completely; mixed lots of formatting and...
[lhc/web/wiklou.git] / maintenance / tests / phpunit / bootstrap.php
1 <?php
2 /**
3 * Bootstrapping for MediaWiki PHPUnit tests
4 *
5 * @file
6 */
7
8 /* Configuration */
9
10 // This file is not included in the global scope, but rather within a function, so we must global anything we need to
11 // have access to in the global scope explicitly
12 global $wgCommandLineMode, $IP, $optionsWithArgs, $wgProfiler, $wgAutoloadClasses;
13
14 // Evaluate the include path relative to this file
15 $IP = dirname( dirname( dirname( dirname( __FILE__ ) ) ) );
16
17 // Set a flag which can be used to detect when other scripts have been entered through this entry point or not
18 define( 'MW_PHPUNIT_TEST', true );
19
20 // Start up MediaWiki in command-line mode
21 require_once( "$IP/maintenance/commandLine.inc" );
22
23 // Assume UTC for testing purposes
24 $wgLocaltimezone = 'UTC';
25
26 // To prevent tests from failing with SQLite, we need to turn database caching off
27 global $wgCaches;
28 $wgCaches[CACHE_DB] = false;
29
30 // Output a notice when running with older versions of PHPUnit
31 if ( !version_compare( PHPUnit_Runner_Version::id(), "3.4.1", ">" ) ) {
32 echo <<<EOF
33 ********************************************************************************
34
35 These tests run best with version PHPUnit 3.4.2 or better. Earlier versions may
36 show failures because earlier versions of PHPUnit do not properly implement
37 dependencies.
38
39 ********************************************************************************
40
41 EOF;
42 }
43
44 /* Classes */
45
46 abstract class MediaWikiTestSetup extends PHPUnit_Framework_TestCase {
47
48 protected function buildTestDatabase( $tables ) {
49 global $wgDBprefix;
50
51 $db = wfGetDB( DB_MASTER );
52 $oldTableNames = array();
53 foreach ( $tables as $table )
54 $oldTableNames[$table] = $db->tableName( $table );
55 if ( $db->getType() == 'oracle' ) {
56 $wgDBprefix = 'pt_';
57 } else {
58 $wgDBprefix = 'parsertest_';
59 }
60
61 $db->tablePrefix( $wgDBprefix );
62
63 if ( $db->isOpen() ) {
64 foreach ( $tables as $tbl ) {
65 $newTableName = $db->tableName( $tbl );
66 $tableName = $oldTableNames[$tbl];
67 $db->query( "DROP TABLE IF EXISTS $newTableName", __METHOD__ );
68 $db->duplicateTableStructure( $tableName, $newTableName, __METHOD__ );
69 }
70 return $db;
71 } else {
72 // Something amiss
73 return null;
74 }
75 }
76 }