3 * Bootstrapping for MediaWiki PHPUnit tests
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;
14 // Evaluate the include path relative to this file
15 $IP = dirname( dirname( dirname( dirname( __FILE__
) ) ) );
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 );
20 // Start up MediaWiki in command-line mode
21 require_once( "$IP/maintenance/commandLine.inc" );
23 // Assume UTC for testing purposes
24 $wgLocaltimezone = 'UTC';
26 // To prevent tests from failing with SQLite, we need to turn database caching off
28 $wgCaches[CACHE_DB
] = false;
30 // Output a notice when running with older versions of PHPUnit
31 if ( !version_compare( PHPUnit_Runner_Version
::id(), "3.4.1", ">" ) ) {
33 ********************************************************************************
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
39 ********************************************************************************
46 abstract class MediaWikiTestSetup
extends PHPUnit_Framework_TestCase
{
48 protected function buildTestDatabase( $tables ) {
51 $db = wfGetDB( DB_MASTER
);
52 $oldTableNames = array();
53 foreach ( $tables as $table )
54 $oldTableNames[$table] = $db->tableName( $table );
55 if ( $db->getType() == 'oracle' ) {
58 $wgDBprefix = 'parsertest_';
61 $db->tablePrefix( $wgDBprefix );
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__
);