3 function getSiteParams( $conf, $wiki ) {
6 foreach ( $conf->suffixes
as $suffix ) {
7 if ( substr( $wiki, -strlen( $suffix ) ) == $suffix ) {
9 $lang = substr( $wiki, 0, -strlen( $suffix ) );
22 'tags' => array( 'tag' ),
26 class SiteConfigurationTest
extends MediaWikiTestCase
{
29 protected function 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(
46 'default' => 'default',
52 'default' => '$lang $site $wiki',
81 'default' => 'default',
95 $GLOBALS['global'] = array( 'global' => 'global' );
98 function testSiteFromDb() {
100 array( 'wikipedia', 'en' ),
101 $this->mConf
->siteFromDB( 'enwiki' ),
105 array( 'wikipedia', '' ),
106 $this->mConf
->siteFromDB( 'wiki' ),
107 'siteFromDB() on a suffix'
111 $this->mConf
->siteFromDB( 'wikien' ),
112 'siteFromDB() on a non-existing wiki'
115 $this->mConf
->suffixes
= array( 'wiki', '' );
117 array( '', 'wikien' ),
118 $this->mConf
->siteFromDB( 'wikien' ),
119 'siteFromDB() on a non-existing wiki (2)'
123 function testGetLocalDatabases() {
125 array( 'enwiki', 'dewiki', 'frwiki' ),
126 $this->mConf
->getLocalDatabases(),
127 'getLocalDatabases()'
131 function testGetConfVariables() {
134 $this->mConf
->get( 'simple', 'enwiki', 'wiki' ),
135 'get(): simple setting on an existing wiki'
139 $this->mConf
->get( 'simple', 'dewiki', 'wiki' ),
140 'get(): simple setting on an existing wiki (2)'
144 $this->mConf
->get( 'simple', 'frwiki', 'wiki' ),
145 'get(): simple setting on an existing wiki (3)'
149 $this->mConf
->get( 'simple', 'wiki', 'wiki' ),
150 'get(): simple setting on an suffix'
154 $this->mConf
->get( 'simple', 'eswiki', 'wiki' ),
155 'get(): simple setting on an non-existing wiki'
160 $this->mConf
->get( 'fallback', 'enwiki', 'wiki' ),
161 'get(): fallback setting on an existing wiki'
165 $this->mConf
->get( 'fallback', 'dewiki', 'wiki', array(), array( 'tag' ) ),
166 'get(): fallback setting on an existing wiki (with wiki tag)'
170 $this->mConf
->get( 'fallback', 'wiki', 'wiki' ),
171 'get(): fallback setting on an suffix'
175 $this->mConf
->get( 'fallback', 'wiki', 'wiki', array(), array( 'tag' ) ),
176 'get(): fallback setting on an suffix (with wiki tag)'
180 $this->mConf
->get( 'fallback', 'eswiki', 'wiki' ),
181 'get(): fallback setting on an non-existing wiki'
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' );
192 array( 'enwiki' => 'enwiki' ) +
$common,
193 $this->mConf
->get( 'merge', 'enwiki', 'wiki' ),
194 'get(): merging setting on an existing wiki'
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)'
202 array( 'dewiki' => 'dewiki' ) +
$common,
203 $this->mConf
->get( 'merge', 'dewiki', 'wiki' ),
204 'get(): merging setting on an existing wiki (2)'
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)'
212 array( 'frwiki' => 'frwiki' ) +
$common,
213 $this->mConf
->get( 'merge', 'frwiki', 'wiki' ),
214 'get(): merging setting on an existing wiki (3)'
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)'
222 array( 'wiki' => 'wiki' ) +
$common,
223 $this->mConf
->get( 'merge', 'wiki', 'wiki' ),
224 'get(): merging setting on an suffix'
227 array( 'wiki' => 'wiki' ) +
$commonTag,
228 $this->mConf
->get( 'merge', 'wiki', 'wiki', array(), array( 'tag' ) ),
229 'get(): merging setting on an suffix (with tag)'
233 $this->mConf
->get( 'merge', 'eswiki', 'wiki' ),
234 'get(): merging setting on an non-existing wiki'
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';
247 array( 'wiki', 'en' ),
248 $this->mConf
->siteFromDB( 'enwiki' ),
249 'siteFromDB() with callback'
253 $this->mConf
->siteFromDB( 'wiki' ),
254 'siteFromDB() with callback on a suffix'
258 $this->mConf
->siteFromDB( 'wikien' ),
259 'siteFromDB() with callback on a non-existing wiki'
263 function testParameterReplacement() {
264 $this->mConf
->siteParamsCallback
= 'getSiteParams';
268 $this->mConf
->get( 'params', 'enwiki', 'wiki' ),
269 'get(): parameter replacement on an existing wiki'
273 $this->mConf
->get( 'params', 'dewiki', 'wiki' ),
274 'get(): parameter replacement on an existing wiki (2)'
278 $this->mConf
->get( 'params', 'frwiki', 'wiki' ),
279 'get(): parameter replacement on an existing wiki (3)'
283 $this->mConf
->get( 'params', 'wiki', 'wiki' ),
284 'get(): parameter replacement on an suffix'
288 $this->mConf
->get( 'params', 'eswiki', 'wiki' ),
289 'get(): parameter replacement on an non-existing wiki'
293 function testGetAllGlobals() {
294 $this->mConf
->siteParamsCallback
= 'getSiteParams';
297 'simple' => 'enwiki',
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' );