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