3 class SiteConfigurationTest
extends MediaWikiTestCase
{
6 * @var SiteConfiguration
10 protected function 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(
27 'default' => 'default',
33 'default' => '$lang $site $wiki',
62 'default' => 'default',
76 $GLOBALS['global'] = array( 'global' => 'global' );
80 * This function is used as a callback within the tests below
82 public static function getSiteParamsCallback( $conf, $wiki ) {
85 foreach ( $conf->suffixes
as $suffix ) {
86 if ( substr( $wiki, -strlen( $suffix ) ) == $suffix ) {
88 $lang = substr( $wiki, 0, -strlen( $suffix ) );
101 'tags' => array( 'tag' ),
106 * @covers SiteConfiguration::siteFromDB
108 public function testSiteFromDb() {
110 array( 'wikipedia', 'en' ),
111 $this->mConf
->siteFromDB( 'enwiki' ),
115 array( 'wikipedia', '' ),
116 $this->mConf
->siteFromDB( 'wiki' ),
117 'siteFromDB() on a suffix'
121 $this->mConf
->siteFromDB( 'wikien' ),
122 'siteFromDB() on a non-existing wiki'
125 $this->mConf
->suffixes
= array( 'wiki', '' );
127 array( '', 'wikien' ),
128 $this->mConf
->siteFromDB( 'wikien' ),
129 'siteFromDB() on a non-existing wiki (2)'
134 * @covers SiteConfiguration::getLocalDatabases
136 public function testGetLocalDatabases() {
138 array( 'enwiki', 'dewiki', 'frwiki' ),
139 $this->mConf
->getLocalDatabases(),
140 'getLocalDatabases()'
145 * @covers SiteConfiguration::get
147 public function testGetConfVariables() {
150 $this->mConf
->get( 'simple', 'enwiki', 'wiki' ),
151 'get(): simple setting on an existing wiki'
155 $this->mConf
->get( 'simple', 'dewiki', 'wiki' ),
156 'get(): simple setting on an existing wiki (2)'
160 $this->mConf
->get( 'simple', 'frwiki', 'wiki' ),
161 'get(): simple setting on an existing wiki (3)'
165 $this->mConf
->get( 'simple', 'wiki', 'wiki' ),
166 'get(): simple setting on an suffix'
170 $this->mConf
->get( 'simple', 'eswiki', 'wiki' ),
171 'get(): simple setting on an non-existing wiki'
176 $this->mConf
->get( 'fallback', 'enwiki', 'wiki' ),
177 'get(): fallback setting on an existing wiki'
181 $this->mConf
->get( 'fallback', 'dewiki', 'wiki', array(), array( 'tag' ) ),
182 'get(): fallback setting on an existing wiki (with wiki tag)'
186 $this->mConf
->get( 'fallback', 'wiki', 'wiki' ),
187 'get(): fallback setting on an suffix'
191 $this->mConf
->get( 'fallback', 'wiki', 'wiki', array(), array( 'tag' ) ),
192 'get(): fallback setting on an suffix (with wiki tag)'
196 $this->mConf
->get( 'fallback', 'eswiki', 'wiki' ),
197 'get(): fallback setting on an non-existing wiki'
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' );
208 array( 'enwiki' => 'enwiki' ) +
$common,
209 $this->mConf
->get( 'merge', 'enwiki', 'wiki' ),
210 'get(): merging setting on an existing wiki'
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)'
218 array( 'dewiki' => 'dewiki' ) +
$common,
219 $this->mConf
->get( 'merge', 'dewiki', 'wiki' ),
220 'get(): merging setting on an existing wiki (2)'
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)'
228 array( 'frwiki' => 'frwiki' ) +
$common,
229 $this->mConf
->get( 'merge', 'frwiki', 'wiki' ),
230 'get(): merging setting on an existing wiki (3)'
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)'
238 array( 'wiki' => 'wiki' ) +
$common,
239 $this->mConf
->get( 'merge', 'wiki', 'wiki' ),
240 'get(): merging setting on an suffix'
243 array( 'wiki' => 'wiki' ) +
$commonTag,
244 $this->mConf
->get( 'merge', 'wiki', 'wiki', array(), array( 'tag' ) ),
245 'get(): merging setting on an suffix (with tag)'
249 $this->mConf
->get( 'merge', 'eswiki', 'wiki' ),
250 'get(): merging setting on an non-existing wiki'
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';
266 array( 'wiki', 'en' ),
267 $this->mConf
->siteFromDB( 'enwiki' ),
268 'siteFromDB() with callback'
272 $this->mConf
->siteFromDB( 'wiki' ),
273 'siteFromDB() with callback on a suffix'
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';
290 $this->mConf
->get( 'params', 'enwiki', 'wiki' ),
291 'get(): parameter replacement on an existing wiki'
295 $this->mConf
->get( 'params', 'dewiki', 'wiki' ),
296 'get(): parameter replacement on an existing wiki (2)'
300 $this->mConf
->get( 'params', 'frwiki', 'wiki' ),
301 'get(): parameter replacement on an existing wiki (3)'
305 $this->mConf
->get( 'params', 'wiki', 'wiki' ),
306 'get(): parameter replacement on an suffix'
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';
322 'simple' => 'enwiki',
324 'params' => 'en wiki enwiki',
325 'global' => array( 'enwiki' => 'enwiki' ) +
$GLOBALS['global'],
327 'enwiki' => 'enwiki',
330 'default' => 'default'
333 $this->assertEquals( $getall, $this->mConf
->getAll( 'enwiki' ), 'getAll()' );
335 $this->mConf
->extractAllGlobals( 'enwiki', 'wiki' );
340 'extractAllGlobals(): simple setting'
344 $GLOBALS['fallback'],
345 'extractAllGlobals(): fallback setting'
350 'extractAllGlobals(): parameter replacement'
355 'extractAllGlobals(): merging with global'
360 'extractAllGlobals(): merging setting'