Separate MediaWiki unit and integration tests
[lhc/web/wiklou.git] / tests / common / TestSetup.php
1 <?php
2
3 /**
4 * Common code for test environment initialisation and teardown
5 */
6 class TestSetup {
7 /**
8 * This should be called before Setup.php, e.g. from the finalSetup() method
9 * of a Maintenance subclass
10 */
11 public static function applyInitialConfig() {
12 global $wgMainCacheType, $wgMessageCacheType, $wgParserCacheType, $wgMainWANCache;
13 global $wgMainStash;
14 global $wgLanguageConverterCacheType, $wgUseDatabaseMessages;
15 global $wgLocaltimezone, $wgLocalisationCacheConf;
16 global $wgSearchType;
17 global $wgDevelopmentWarnings;
18 global $wgSessionProviders, $wgSessionPbkdf2Iterations;
19 global $wgJobTypeConf;
20 global $wgAuthManagerConfig;
21 global $wgSecretKey;
22
23 $wgSecretKey = 'secretsecretsecretsecretsecretsecretsecretsecretsecretsecretsecretsecretsecret';
24
25 // wfWarn should cause tests to fail
26 $wgDevelopmentWarnings = true;
27
28 // Make sure all caches and stashes are either disabled or use
29 // in-process cache only to prevent tests from using any preconfigured
30 // cache meant for the local wiki from outside the test run.
31 // See also MediaWikiTestCase::run() which mocks CACHE_DB and APC.
32
33 // Disabled in DefaultSettings, override local settings
34 $wgMainWANCache =
35 $wgMainCacheType = CACHE_NONE;
36 // Uses CACHE_ANYTHING in DefaultSettings, use hash instead of db
37 $wgMessageCacheType =
38 $wgParserCacheType =
39 $wgSessionCacheType =
40 $wgLanguageConverterCacheType = 'hash';
41 // Uses db-replicated in DefaultSettings
42 $wgMainStash = 'hash';
43 // Use memory job queue
44 $wgJobTypeConf = [
45 'default' => [ 'class' => JobQueueMemory::class, 'order' => 'fifo' ],
46 ];
47
48 $wgUseDatabaseMessages = false; # Set for future resets
49
50 // Assume UTC for testing purposes
51 $wgLocaltimezone = 'UTC';
52
53 $wgLocalisationCacheConf['storeClass'] = LCStoreNull::class;
54
55 // Do not bother updating search tables
56 $wgSearchType = SearchEngineDummy::class;
57
58 // Generic MediaWiki\Session\SessionManager configuration for tests
59 // We use CookieSessionProvider because things might be expecting
60 // cookies to show up in a FauxRequest somewhere.
61 $wgSessionProviders = [
62 [
63 'class' => MediaWiki\Session\CookieSessionProvider::class,
64 'args' => [ [
65 'priority' => 30,
66 'callUserSetCookiesHook' => true,
67 ] ],
68 ],
69 ];
70
71 // Single-iteration PBKDF2 session secret derivation, for speed.
72 $wgSessionPbkdf2Iterations = 1;
73
74 // Generic AuthManager configuration for testing
75 $wgAuthManagerConfig = [
76 'preauth' => [],
77 'primaryauth' => [
78 [
79 'class' => MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProvider::class,
80 'args' => [ [
81 'authoritative' => false,
82 ] ],
83 ],
84 [
85 'class' => MediaWiki\Auth\LocalPasswordPrimaryAuthenticationProvider::class,
86 'args' => [ [
87 'authoritative' => true,
88 ] ],
89 ],
90 ],
91 'secondaryauth' => [],
92 ];
93
94 // T46192 Do not attempt to send a real e-mail
95 Hooks::clear( 'AlternateUserMailer' );
96 Hooks::register(
97 'AlternateUserMailer',
98 function () {
99 return false;
100 }
101 );
102 // xdebug's default of 100 is too low for MediaWiki
103 ini_set( 'xdebug.max_nesting_level', 1000 );
104
105 // Bug T116683 serialize_precision of 100
106 // may break testing against floating point values
107 // treated with PHP's serialize()
108 ini_set( 'serialize_precision', 17 );
109 }
110
111 }