Merge "Add support for fragments to WikiMap"
[lhc/web/wiklou.git] / tests / phpunit / includes / SiteConfigurationTest.php
index 181a913..6547c87 100644 (file)
@@ -1,30 +1,11 @@
 <?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();
@@ -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'
+               );
        }
 }