Import: Handle uploads with sha1 starting with 0 properly
[mediawiki.git] / tests / phpunit / includes / SiteConfigurationTest.php
blob6547c873a0792e38888dd56ea258d969663d1067
1 <?php
3 class SiteConfigurationTest extends MediaWikiTestCase {
5 /**
6 * @var SiteConfiguration
7 */
8 protected $mConf;
10 protected function setUp() {
11 parent::setUp();
13 $this->mConf = new SiteConfiguration;
15 $this->mConf->suffixes = array( 'wikipedia' => 'wiki' );
16 $this->mConf->wikis = array( 'enwiki', 'dewiki', 'frwiki' );
17 $this->mConf->settings = array(
18 'simple' => array(
19 'wiki' => 'wiki',
20 'tag' => 'tag',
21 'enwiki' => 'enwiki',
22 'dewiki' => 'dewiki',
23 'frwiki' => 'frwiki',
26 'fallback' => array(
27 'default' => 'default',
28 'wiki' => 'wiki',
29 'tag' => 'tag',
32 'params' => array(
33 'default' => '$lang $site $wiki',
36 '+global' => array(
37 'wiki' => array(
38 'wiki' => 'wiki',
40 'tag' => array(
41 'tag' => 'tag',
43 'enwiki' => array(
44 'enwiki' => 'enwiki',
46 'dewiki' => array(
47 'dewiki' => 'dewiki',
49 'frwiki' => array(
50 'frwiki' => 'frwiki',
54 'merge' => array(
55 '+wiki' => array(
56 'wiki' => 'wiki',
58 '+tag' => array(
59 'tag' => 'tag',
61 'default' => array(
62 'default' => 'default',
64 '+enwiki' => array(
65 'enwiki' => 'enwiki',
67 '+dewiki' => array(
68 'dewiki' => 'dewiki',
70 '+frwiki' => array(
71 'frwiki' => 'frwiki',
76 $GLOBALS['global'] = array( 'global' => 'global' );
79 /**
80 * This function is used as a callback within the tests below
82 public static function getSiteParamsCallback( $conf, $wiki ) {
83 $site = null;
84 $lang = null;
85 foreach ( $conf->suffixes as $suffix ) {
86 if ( substr( $wiki, -strlen( $suffix ) ) == $suffix ) {
87 $site = $suffix;
88 $lang = substr( $wiki, 0, -strlen( $suffix ) );
89 break;
93 return array(
94 'suffix' => $site,
95 'lang' => $lang,
96 'params' => array(
97 'lang' => $lang,
98 'site' => $site,
99 'wiki' => $wiki,
101 'tags' => array( 'tag' ),
106 * @covers SiteConfiguration::siteFromDB
108 public function testSiteFromDb() {
109 $this->assertEquals(
110 array( 'wikipedia', 'en' ),
111 $this->mConf->siteFromDB( 'enwiki' ),
112 'siteFromDB()'
114 $this->assertEquals(
115 array( 'wikipedia', '' ),
116 $this->mConf->siteFromDB( 'wiki' ),
117 'siteFromDB() on a suffix'
119 $this->assertEquals(
120 array( null, null ),
121 $this->mConf->siteFromDB( 'wikien' ),
122 'siteFromDB() on a non-existing wiki'
125 $this->mConf->suffixes = array( 'wiki', '' );
126 $this->assertEquals(
127 array( '', 'wikien' ),
128 $this->mConf->siteFromDB( 'wikien' ),
129 'siteFromDB() on a non-existing wiki (2)'
134 * @covers SiteConfiguration::getLocalDatabases
136 public function testGetLocalDatabases() {
137 $this->assertEquals(
138 array( 'enwiki', 'dewiki', 'frwiki' ),
139 $this->mConf->getLocalDatabases(),
140 'getLocalDatabases()'
145 * @covers SiteConfiguration::get
147 public function testGetConfVariables() {
148 $this->assertEquals(
149 'enwiki',
150 $this->mConf->get( 'simple', 'enwiki', 'wiki' ),
151 'get(): simple setting on an existing wiki'
153 $this->assertEquals(
154 'dewiki',
155 $this->mConf->get( 'simple', 'dewiki', 'wiki' ),
156 'get(): simple setting on an existing wiki (2)'
158 $this->assertEquals(
159 'frwiki',
160 $this->mConf->get( 'simple', 'frwiki', 'wiki' ),
161 'get(): simple setting on an existing wiki (3)'
163 $this->assertEquals(
164 'wiki',
165 $this->mConf->get( 'simple', 'wiki', 'wiki' ),
166 'get(): simple setting on an suffix'
168 $this->assertEquals(
169 'wiki',
170 $this->mConf->get( 'simple', 'eswiki', 'wiki' ),
171 'get(): simple setting on an non-existing wiki'
174 $this->assertEquals(
175 'wiki',
176 $this->mConf->get( 'fallback', 'enwiki', 'wiki' ),
177 'get(): fallback setting on an existing wiki'
179 $this->assertEquals(
180 'tag',
181 $this->mConf->get( 'fallback', 'dewiki', 'wiki', array(), array( 'tag' ) ),
182 'get(): fallback setting on an existing wiki (with wiki tag)'
184 $this->assertEquals(
185 'wiki',
186 $this->mConf->get( 'fallback', 'wiki', 'wiki' ),
187 'get(): fallback setting on an suffix'
189 $this->assertEquals(
190 'wiki',
191 $this->mConf->get( 'fallback', 'wiki', 'wiki', array(), array( 'tag' ) ),
192 'get(): fallback setting on an suffix (with wiki tag)'
194 $this->assertEquals(
195 'wiki',
196 $this->mConf->get( 'fallback', 'eswiki', 'wiki' ),
197 'get(): fallback setting on an non-existing wiki'
199 $this->assertEquals(
200 'tag',
201 $this->mConf->get( 'fallback', 'eswiki', 'wiki', array(), array( 'tag' ) ),
202 'get(): fallback setting on an non-existing wiki (with wiki tag)'
205 $common = array( 'wiki' => 'wiki', 'default' => 'default' );
206 $commonTag = array( 'tag' => 'tag', 'wiki' => 'wiki', 'default' => 'default' );
207 $this->assertEquals(
208 array( 'enwiki' => 'enwiki' ) + $common,
209 $this->mConf->get( 'merge', 'enwiki', 'wiki' ),
210 'get(): merging setting on an existing wiki'
212 $this->assertEquals(
213 array( 'enwiki' => 'enwiki' ) + $commonTag,
214 $this->mConf->get( 'merge', 'enwiki', 'wiki', array(), array( 'tag' ) ),
215 'get(): merging setting on an existing wiki (with tag)'
217 $this->assertEquals(
218 array( 'dewiki' => 'dewiki' ) + $common,
219 $this->mConf->get( 'merge', 'dewiki', 'wiki' ),
220 'get(): merging setting on an existing wiki (2)'
222 $this->assertEquals(
223 array( 'dewiki' => 'dewiki' ) + $commonTag,
224 $this->mConf->get( 'merge', 'dewiki', 'wiki', array(), array( 'tag' ) ),
225 'get(): merging setting on an existing wiki (2) (with tag)'
227 $this->assertEquals(
228 array( 'frwiki' => 'frwiki' ) + $common,
229 $this->mConf->get( 'merge', 'frwiki', 'wiki' ),
230 'get(): merging setting on an existing wiki (3)'
232 $this->assertEquals(
233 array( 'frwiki' => 'frwiki' ) + $commonTag,
234 $this->mConf->get( 'merge', 'frwiki', 'wiki', array(), array( 'tag' ) ),
235 'get(): merging setting on an existing wiki (3) (with tag)'
237 $this->assertEquals(
238 array( 'wiki' => 'wiki' ) + $common,
239 $this->mConf->get( 'merge', 'wiki', 'wiki' ),
240 'get(): merging setting on an suffix'
242 $this->assertEquals(
243 array( 'wiki' => 'wiki' ) + $commonTag,
244 $this->mConf->get( 'merge', 'wiki', 'wiki', array(), array( 'tag' ) ),
245 'get(): merging setting on an suffix (with tag)'
247 $this->assertEquals(
248 $common,
249 $this->mConf->get( 'merge', 'eswiki', 'wiki' ),
250 'get(): merging setting on an non-existing wiki'
252 $this->assertEquals(
253 $commonTag,
254 $this->mConf->get( 'merge', 'eswiki', 'wiki', array(), array( 'tag' ) ),
255 'get(): merging setting on an non-existing wiki (with tag)'
260 * @covers SiteConfiguration::siteFromDB
262 public function testSiteFromDbWithCallback() {
263 $this->mConf->siteParamsCallback = 'SiteConfigurationTest::getSiteParamsCallback';
265 $this->assertEquals(
266 array( 'wiki', 'en' ),
267 $this->mConf->siteFromDB( 'enwiki' ),
268 'siteFromDB() with callback'
270 $this->assertEquals(
271 array( 'wiki', '' ),
272 $this->mConf->siteFromDB( 'wiki' ),
273 'siteFromDB() with callback on a suffix'
275 $this->assertEquals(
276 array( null, null ),
277 $this->mConf->siteFromDB( 'wikien' ),
278 'siteFromDB() with callback on a non-existing wiki'
283 * @covers SiteConfiguration::get
285 public function testParameterReplacement() {
286 $this->mConf->siteParamsCallback = 'SiteConfigurationTest::getSiteParamsCallback';
288 $this->assertEquals(
289 'en wiki enwiki',
290 $this->mConf->get( 'params', 'enwiki', 'wiki' ),
291 'get(): parameter replacement on an existing wiki'
293 $this->assertEquals(
294 'de wiki dewiki',
295 $this->mConf->get( 'params', 'dewiki', 'wiki' ),
296 'get(): parameter replacement on an existing wiki (2)'
298 $this->assertEquals(
299 'fr wiki frwiki',
300 $this->mConf->get( 'params', 'frwiki', 'wiki' ),
301 'get(): parameter replacement on an existing wiki (3)'
303 $this->assertEquals(
304 ' wiki wiki',
305 $this->mConf->get( 'params', 'wiki', 'wiki' ),
306 'get(): parameter replacement on an suffix'
308 $this->assertEquals(
309 'es wiki eswiki',
310 $this->mConf->get( 'params', 'eswiki', 'wiki' ),
311 'get(): parameter replacement on an non-existing wiki'
316 * @covers SiteConfiguration::getAll
318 public function testGetAllGlobals() {
319 $this->mConf->siteParamsCallback = 'SiteConfigurationTest::getSiteParamsCallback';
321 $getall = array(
322 'simple' => 'enwiki',
323 'fallback' => 'tag',
324 'params' => 'en wiki enwiki',
325 'global' => array( 'enwiki' => 'enwiki' ) + $GLOBALS['global'],
326 'merge' => array(
327 'enwiki' => 'enwiki',
328 'tag' => 'tag',
329 'wiki' => 'wiki',
330 'default' => 'default'
333 $this->assertEquals( $getall, $this->mConf->getAll( 'enwiki' ), 'getAll()' );
335 $this->mConf->extractAllGlobals( 'enwiki', 'wiki' );
337 $this->assertEquals(
338 $getall['simple'],
339 $GLOBALS['simple'],
340 'extractAllGlobals(): simple setting'
342 $this->assertEquals(
343 $getall['fallback'],
344 $GLOBALS['fallback'],
345 'extractAllGlobals(): fallback setting'
347 $this->assertEquals(
348 $getall['params'],
349 $GLOBALS['params'],
350 'extractAllGlobals(): parameter replacement'
352 $this->assertEquals(
353 $getall['global'],
354 $GLOBALS['global'],
355 'extractAllGlobals(): merging with global'
357 $this->assertEquals(
358 $getall['merge'],
359 $GLOBALS['merge'],
360 'extractAllGlobals(): merging setting'