test: coverage recording now needs to be explicit
[mediawiki.git] / tests / phpunit / includes / SiteConfigurationTest.php
blob4cdf0201befa705d9acbd1c193070d1214c56831
1 <?php
3 function getSiteParams( $conf, $wiki ) {
4 $site = null;
5 $lang = null;
6 foreach ( $conf->suffixes as $suffix ) {
7 if ( substr( $wiki, -strlen( $suffix ) ) == $suffix ) {
8 $site = $suffix;
9 $lang = substr( $wiki, 0, -strlen( $suffix ) );
10 break;
14 return array(
15 'suffix' => $site,
16 'lang' => $lang,
17 'params' => array(
18 'lang' => $lang,
19 'site' => $site,
20 'wiki' => $wiki,
22 'tags' => array( 'tag' ),
26 class SiteConfigurationTest extends MediaWikiTestCase {
27 var $mConf;
29 protected function setUp() {
30 parent::setUp();
32 $this->mConf = new SiteConfiguration;
34 $this->mConf->suffixes = array( 'wiki' );
35 $this->mConf->wikis = array( 'enwiki', 'dewiki', 'frwiki' );
36 $this->mConf->settings = array(
37 'simple' => array(
38 'wiki' => 'wiki',
39 'tag' => 'tag',
40 'enwiki' => 'enwiki',
41 'dewiki' => 'dewiki',
42 'frwiki' => 'frwiki',
45 'fallback' => array(
46 'default' => 'default',
47 'wiki' => 'wiki',
48 'tag' => 'tag',
51 'params' => array(
52 'default' => '$lang $site $wiki',
55 '+global' => array(
56 'wiki' => array(
57 'wiki' => 'wiki',
59 'tag' => array(
60 'tag' => 'tag',
62 'enwiki' => array(
63 'enwiki' => 'enwiki',
65 'dewiki' => array(
66 'dewiki' => 'dewiki',
68 'frwiki' => array(
69 'frwiki' => 'frwiki',
73 'merge' => array(
74 '+wiki' => array(
75 'wiki' => 'wiki',
77 '+tag' => array(
78 'tag' => 'tag',
80 'default' => array(
81 'default' => 'default',
83 '+enwiki' => array(
84 'enwiki' => 'enwiki',
86 '+dewiki' => array(
87 'dewiki' => 'dewiki',
89 '+frwiki' => array(
90 'frwiki' => 'frwiki',
95 $GLOBALS['global'] = array( 'global' => 'global' );
98 function testSiteFromDb() {
99 $this->assertEquals(
100 array( 'wikipedia', 'en' ),
101 $this->mConf->siteFromDB( 'enwiki' ),
102 'siteFromDB()'
104 $this->assertEquals(
105 array( 'wikipedia', '' ),
106 $this->mConf->siteFromDB( 'wiki' ),
107 'siteFromDB() on a suffix'
109 $this->assertEquals(
110 array( null, null ),
111 $this->mConf->siteFromDB( 'wikien' ),
112 'siteFromDB() on a non-existing wiki'
115 $this->mConf->suffixes = array( 'wiki', '' );
116 $this->assertEquals(
117 array( '', 'wikien' ),
118 $this->mConf->siteFromDB( 'wikien' ),
119 'siteFromDB() on a non-existing wiki (2)'
123 function testGetLocalDatabases() {
124 $this->assertEquals(
125 array( 'enwiki', 'dewiki', 'frwiki' ),
126 $this->mConf->getLocalDatabases(),
127 'getLocalDatabases()'
131 function testGetConfVariables() {
132 $this->assertEquals(
133 'enwiki',
134 $this->mConf->get( 'simple', 'enwiki', 'wiki' ),
135 'get(): simple setting on an existing wiki'
137 $this->assertEquals(
138 'dewiki',
139 $this->mConf->get( 'simple', 'dewiki', 'wiki' ),
140 'get(): simple setting on an existing wiki (2)'
142 $this->assertEquals(
143 'frwiki',
144 $this->mConf->get( 'simple', 'frwiki', 'wiki' ),
145 'get(): simple setting on an existing wiki (3)'
147 $this->assertEquals(
148 'wiki',
149 $this->mConf->get( 'simple', 'wiki', 'wiki' ),
150 'get(): simple setting on an suffix'
152 $this->assertEquals(
153 'wiki',
154 $this->mConf->get( 'simple', 'eswiki', 'wiki' ),
155 'get(): simple setting on an non-existing wiki'
158 $this->assertEquals(
159 'wiki',
160 $this->mConf->get( 'fallback', 'enwiki', 'wiki' ),
161 'get(): fallback setting on an existing wiki'
163 $this->assertEquals(
164 'tag',
165 $this->mConf->get( 'fallback', 'dewiki', 'wiki', array(), array( 'tag' ) ),
166 'get(): fallback setting on an existing wiki (with wiki tag)'
168 $this->assertEquals(
169 'wiki',
170 $this->mConf->get( 'fallback', 'wiki', 'wiki' ),
171 'get(): fallback setting on an suffix'
173 $this->assertEquals(
174 'wiki',
175 $this->mConf->get( 'fallback', 'wiki', 'wiki', array(), array( 'tag' ) ),
176 'get(): fallback setting on an suffix (with wiki tag)'
178 $this->assertEquals(
179 'wiki',
180 $this->mConf->get( 'fallback', 'eswiki', 'wiki' ),
181 'get(): fallback setting on an non-existing wiki'
183 $this->assertEquals(
184 'tag',
185 $this->mConf->get( 'fallback', 'eswiki', 'wiki', array(), array( 'tag' ) ),
186 'get(): fallback setting on an non-existing wiki (with wiki tag)'
189 $common = array( 'wiki' => 'wiki', 'default' => 'default' );
190 $commonTag = array( 'tag' => 'tag', 'wiki' => 'wiki', 'default' => 'default' );
191 $this->assertEquals(
192 array( 'enwiki' => 'enwiki' ) + $common,
193 $this->mConf->get( 'merge', 'enwiki', 'wiki' ),
194 'get(): merging setting on an existing wiki'
196 $this->assertEquals(
197 array( 'enwiki' => 'enwiki' ) + $commonTag,
198 $this->mConf->get( 'merge', 'enwiki', 'wiki', array(), array( 'tag' ) ),
199 'get(): merging setting on an existing wiki (with tag)'
201 $this->assertEquals(
202 array( 'dewiki' => 'dewiki' ) + $common,
203 $this->mConf->get( 'merge', 'dewiki', 'wiki' ),
204 'get(): merging setting on an existing wiki (2)'
206 $this->assertEquals(
207 array( 'dewiki' => 'dewiki' ) + $commonTag,
208 $this->mConf->get( 'merge', 'dewiki', 'wiki', array(), array( 'tag' ) ),
209 'get(): merging setting on an existing wiki (2) (with tag)'
211 $this->assertEquals(
212 array( 'frwiki' => 'frwiki' ) + $common,
213 $this->mConf->get( 'merge', 'frwiki', 'wiki' ),
214 'get(): merging setting on an existing wiki (3)'
216 $this->assertEquals(
217 array( 'frwiki' => 'frwiki' ) + $commonTag,
218 $this->mConf->get( 'merge', 'frwiki', 'wiki', array(), array( 'tag' ) ),
219 'get(): merging setting on an existing wiki (3) (with tag)'
221 $this->assertEquals(
222 array( 'wiki' => 'wiki' ) + $common,
223 $this->mConf->get( 'merge', 'wiki', 'wiki' ),
224 'get(): merging setting on an suffix'
226 $this->assertEquals(
227 array( 'wiki' => 'wiki' ) + $commonTag,
228 $this->mConf->get( 'merge', 'wiki', 'wiki', array(), array( 'tag' ) ),
229 'get(): merging setting on an suffix (with tag)'
231 $this->assertEquals(
232 $common,
233 $this->mConf->get( 'merge', 'eswiki', 'wiki' ),
234 'get(): merging setting on an non-existing wiki'
236 $this->assertEquals(
237 $commonTag,
238 $this->mConf->get( 'merge', 'eswiki', 'wiki', array(), array( 'tag' ) ),
239 'get(): merging setting on an non-existing wiki (with tag)'
243 function testSiteFromDbWithCallback() {
244 $this->mConf->siteParamsCallback = 'getSiteParams';
246 $this->assertEquals(
247 array( 'wiki', 'en' ),
248 $this->mConf->siteFromDB( 'enwiki' ),
249 'siteFromDB() with callback'
251 $this->assertEquals(
252 array( 'wiki', '' ),
253 $this->mConf->siteFromDB( 'wiki' ),
254 'siteFromDB() with callback on a suffix'
256 $this->assertEquals(
257 array( null, null ),
258 $this->mConf->siteFromDB( 'wikien' ),
259 'siteFromDB() with callback on a non-existing wiki'
263 function testParameterReplacement() {
264 $this->mConf->siteParamsCallback = 'getSiteParams';
266 $this->assertEquals(
267 'en wiki enwiki',
268 $this->mConf->get( 'params', 'enwiki', 'wiki' ),
269 'get(): parameter replacement on an existing wiki'
271 $this->assertEquals(
272 'de wiki dewiki',
273 $this->mConf->get( 'params', 'dewiki', 'wiki' ),
274 'get(): parameter replacement on an existing wiki (2)'
276 $this->assertEquals(
277 'fr wiki frwiki',
278 $this->mConf->get( 'params', 'frwiki', 'wiki' ),
279 'get(): parameter replacement on an existing wiki (3)'
281 $this->assertEquals(
282 ' wiki wiki',
283 $this->mConf->get( 'params', 'wiki', 'wiki' ),
284 'get(): parameter replacement on an suffix'
286 $this->assertEquals(
287 'es wiki eswiki',
288 $this->mConf->get( 'params', 'eswiki', 'wiki' ),
289 'get(): parameter replacement on an non-existing wiki'
293 function testGetAllGlobals() {
294 $this->mConf->siteParamsCallback = 'getSiteParams';
296 $getall = array(
297 'simple' => 'enwiki',
298 'fallback' => 'tag',
299 'params' => 'en wiki enwiki',
300 'global' => array( 'enwiki' => 'enwiki' ) + $GLOBALS['global'],
301 'merge' => array( 'enwiki' => 'enwiki', 'tag' => 'tag', 'wiki' => 'wiki', 'default' => 'default' ),
303 $this->assertEquals( $getall, $this->mConf->getAll( 'enwiki' ), 'getAll()' );
305 $this->mConf->extractAllGlobals( 'enwiki', 'wiki' );
307 $this->assertEquals( $getall['simple'], $GLOBALS['simple'], 'extractAllGlobals(): simple setting' );
308 $this->assertEquals( $getall['fallback'], $GLOBALS['fallback'], 'extractAllGlobals(): fallback setting' );
309 $this->assertEquals( $getall['params'], $GLOBALS['params'], 'extractAllGlobals(): parameter replacement' );
310 $this->assertEquals( $getall['global'], $GLOBALS['global'], 'extractAllGlobals(): merging with global' );
311 $this->assertEquals( $getall['merge'], $GLOBALS['merge'], 'extractAllGlobals(): merging setting' );