X-Git-Url: https://git.cyclocoop.org/?a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2FSiteConfigurationTest.php;h=6547c873a0792e38888dd56ea258d969663d1067;hb=2bcbc311b49af248b9f4882ae5da787a8b91a8a5;hp=181a9132e6d67ee19f387a14f49931b40fa4ad9e;hpb=5c3fecdb372bbd96301a1c21d8fae3219c55a356;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/SiteConfigurationTest.php b/tests/phpunit/includes/SiteConfigurationTest.php index 181a9132e6..6547c873a0 100644 --- a/tests/phpunit/includes/SiteConfigurationTest.php +++ b/tests/phpunit/includes/SiteConfigurationTest.php @@ -1,30 +1,11 @@ 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(); @@ -95,7 +76,36 @@ class SiteConfigurationTest extends MediaWikiTestCase { $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' ), @@ -120,7 +130,10 @@ class SiteConfigurationTest extends MediaWikiTestCase { ); } - function testGetLocalDatabases() { + /** + * @covers SiteConfiguration::getLocalDatabases + */ + public function testGetLocalDatabases() { $this->assertEquals( array( 'enwiki', 'dewiki', 'frwiki' ), $this->mConf->getLocalDatabases(), @@ -128,7 +141,10 @@ class SiteConfigurationTest extends MediaWikiTestCase { ); } - function testGetConfVariables() { + /** + * @covers SiteConfiguration::get + */ + public function testGetConfVariables() { $this->assertEquals( 'enwiki', $this->mConf->get( 'simple', 'enwiki', 'wiki' ), @@ -240,8 +256,11 @@ class SiteConfigurationTest extends MediaWikiTestCase { ); } - function testSiteFromDbWithCallback() { - $this->mConf->siteParamsCallback = 'getSiteParams'; + /** + * @covers SiteConfiguration::siteFromDB + */ + public function testSiteFromDbWithCallback() { + $this->mConf->siteParamsCallback = 'SiteConfigurationTest::getSiteParamsCallback'; $this->assertEquals( array( 'wiki', 'en' ), @@ -260,8 +279,11 @@ class SiteConfigurationTest extends MediaWikiTestCase { ); } - function testParameterReplacement() { - $this->mConf->siteParamsCallback = 'getSiteParams'; + /** + * @covers SiteConfiguration::get + */ + public function testParameterReplacement() { + $this->mConf->siteParamsCallback = 'SiteConfigurationTest::getSiteParamsCallback'; $this->assertEquals( 'en wiki enwiki', @@ -290,24 +312,52 @@ class SiteConfigurationTest extends MediaWikiTestCase { ); } - 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' + ); } }