wiki.techinc.nl/tests/phpunit/includes/config/GlobalConfigTest.php
Kunal Mehta fbfe789b98 Config: Add Config and GlobalConfig classes
Allows configuration options to be fetched from context.

Only one implementation, GlobalConfig, is provided, which
simply returns $GLOBALS[$name]. There can be more classes
in the future, possibly a database-based one. For convinience
the "wg" prefix is automatically added.

Ironically, this adds the $wgConfigClass global variable
which is used to determine which implementation of Config
to use by default.

The ContextSource getConfig and setConfig methods were introduced
in I23194d1ba (1.23), but have no uses in Gerrit, so they can safely
be re-purposed.

Change-Id: I13baec0b6d4ea7badf20b9c5f9b40846348838e4
2014-01-27 21:10:30 -08:00

38 lines
878 B
PHP

<?php
class GlobalConfigTest extends MediaWikiTestCase {
/** @var GlobalConfig $config */
protected $config;
protected function setUp() {
parent::setUp();
$this->config = new GlobalConfig;
}
public static function provideGet() {
return array(
array( 'wgSitename', array( 'Sitename' ) ),
array( 'wgFoo', array( 'Foo' ) ),
array( 'efVariable', array( 'Variable', 'ef' ) ),
array( 'Foo', array( 'Foo', '' ) ),
);
}
/**
* @param string $name
* @param array $params
* @dataProvider provideGet
* @covers GlobalConfig::get
*/
public function testGet( $name, $params ) {
$rand = wfRandom();
$old = isset( $GLOBALS[$name] ) ? $GLOBALS[$name] : null;
$GLOBALS[$name] = $rand;
$out = call_user_func_array( array( $this->config, 'get' ), $params );
$this->assertEquals( $rand, $out );
if ( $old ) {
$GLOBALS[$name] = $old;
}
}
}