<?php
-function getSiteParams( $conf, $wiki ) {
- $site = null;
- $lang = null;
- foreach ( $conf->suffixes as $suffix ) {
- if ( substr( $wiki, -strlen( $suffix ) ) == $suffix ) {
- $site = $suffix;
- $lang = substr( $wiki, 0, -strlen( $suffix ) );
- break;
- }
- }
- return array(
- 'suffix' => $site,
- 'lang' => $lang,
- 'params' => array(
- 'lang' => $lang,
- 'site' => $site,
- 'wiki' => $wiki,
- ),
- 'tags' => array( 'tag' ),
- );
-}
-
class SiteConfigurationTest extends MediaWikiTestCase {
- var $mConf;
+
+ /**
+ * @var SiteConfiguration
+ */
+ protected $mConf;
protected function setUp() {
parent::setUp();
$this->mConf = new SiteConfiguration;
- $this->mConf->suffixes = array( 'wiki' );
+ $this->mConf->suffixes = array( 'wikipedia' => 'wiki' );
$this->mConf->wikis = array( 'enwiki', 'dewiki', 'frwiki' );
$this->mConf->settings = array(
'simple' => array(
$GLOBALS['global'] = array( 'global' => 'global' );
}
- function testSiteFromDb() {
+ /**
+ * This function is used as a callback within the tests below
+ */
+ public static function getSiteParamsCallback( $conf, $wiki ) {
+ $site = null;
+ $lang = null;
+ foreach ( $conf->suffixes as $suffix ) {
+ if ( substr( $wiki, -strlen( $suffix ) ) == $suffix ) {
+ $site = $suffix;
+ $lang = substr( $wiki, 0, -strlen( $suffix ) );
+ break;
+ }
+ }
+
+ return array(
+ 'suffix' => $site,
+ 'lang' => $lang,
+ 'params' => array(
+ 'lang' => $lang,
+ 'site' => $site,
+ 'wiki' => $wiki,
+ ),
+ 'tags' => array( 'tag' ),
+ );
+ }
+
+ /**
+ * @covers SiteConfiguration::siteFromDB
+ */
+ public function testSiteFromDb() {
$this->assertEquals(
array( 'wikipedia', 'en' ),
$this->mConf->siteFromDB( 'enwiki' ),
);
}
- function testGetLocalDatabases() {
+ /**
+ * @covers SiteConfiguration::getLocalDatabases
+ */
+ public function testGetLocalDatabases() {
$this->assertEquals(
array( 'enwiki', 'dewiki', 'frwiki' ),
$this->mConf->getLocalDatabases(),
);
}
- function testGetConfVariables() {
+ /**
+ * @covers SiteConfiguration::get
+ */
+ public function testGetConfVariables() {
$this->assertEquals(
'enwiki',
$this->mConf->get( 'simple', 'enwiki', 'wiki' ),
);
}
- function testSiteFromDbWithCallback() {
- $this->mConf->siteParamsCallback = 'getSiteParams';
+ /**
+ * @covers SiteConfiguration::siteFromDB
+ */
+ public function testSiteFromDbWithCallback() {
+ $this->mConf->siteParamsCallback = 'SiteConfigurationTest::getSiteParamsCallback';
$this->assertEquals(
array( 'wiki', 'en' ),
);
}
- function testParameterReplacement() {
- $this->mConf->siteParamsCallback = 'getSiteParams';
+ /**
+ * @covers SiteConfiguration::get
+ */
+ public function testParameterReplacement() {
+ $this->mConf->siteParamsCallback = 'SiteConfigurationTest::getSiteParamsCallback';
$this->assertEquals(
'en wiki enwiki',
);
}
- function testGetAllGlobals() {
- $this->mConf->siteParamsCallback = 'getSiteParams';
+ /**
+ * @covers SiteConfiguration::getAll
+ */
+ public function testGetAllGlobals() {
+ $this->mConf->siteParamsCallback = 'SiteConfigurationTest::getSiteParamsCallback';
$getall = array(
'simple' => 'enwiki',
'fallback' => 'tag',
'params' => 'en wiki enwiki',
'global' => array( 'enwiki' => 'enwiki' ) + $GLOBALS['global'],
- 'merge' => array( 'enwiki' => 'enwiki', 'tag' => 'tag', 'wiki' => 'wiki', 'default' => 'default' ),
+ 'merge' => array(
+ 'enwiki' => 'enwiki',
+ 'tag' => 'tag',
+ 'wiki' => 'wiki',
+ 'default' => 'default'
+ ),
);
$this->assertEquals( $getall, $this->mConf->getAll( 'enwiki' ), 'getAll()' );
$this->mConf->extractAllGlobals( 'enwiki', 'wiki' );
- $this->assertEquals( $getall['simple'], $GLOBALS['simple'], 'extractAllGlobals(): simple setting' );
- $this->assertEquals( $getall['fallback'], $GLOBALS['fallback'], 'extractAllGlobals(): fallback setting' );
- $this->assertEquals( $getall['params'], $GLOBALS['params'], 'extractAllGlobals(): parameter replacement' );
- $this->assertEquals( $getall['global'], $GLOBALS['global'], 'extractAllGlobals(): merging with global' );
- $this->assertEquals( $getall['merge'], $GLOBALS['merge'], 'extractAllGlobals(): merging setting' );
+ $this->assertEquals(
+ $getall['simple'],
+ $GLOBALS['simple'],
+ 'extractAllGlobals(): simple setting'
+ );
+ $this->assertEquals(
+ $getall['fallback'],
+ $GLOBALS['fallback'],
+ 'extractAllGlobals(): fallback setting'
+ );
+ $this->assertEquals(
+ $getall['params'],
+ $GLOBALS['params'],
+ 'extractAllGlobals(): parameter replacement'
+ );
+ $this->assertEquals(
+ $getall['global'],
+ $GLOBALS['global'],
+ 'extractAllGlobals(): merging with global'
+ );
+ $this->assertEquals(
+ $getall['merge'],
+ $GLOBALS['merge'],
+ 'extractAllGlobals(): merging setting'
+ );
}
}