3 class GlobalVarConfigTest
extends MediaWikiTestCase
{
6 * @covers GlobalVarConfig::newInstance
8 public function testNewInstance() {
9 $config = GlobalVarConfig
::newInstance();
10 $this->assertInstanceOf( 'GlobalVarConfig', $config );
11 $this->maybeStashGlobal( 'wgBaz' );
12 $GLOBALS['wgBaz'] = 'somevalue';
13 // Check prefix is set to 'wg'
14 $this->assertEquals( 'somevalue', $config->get( 'Baz' ) );
18 * @covers GlobalVarConfig::__construct
19 * @dataProvider provideConstructor
21 public function testConstructor( $prefix ) {
22 $var = $prefix . 'GlobalVarConfigTest';
23 $rand = wfRandomString();
24 $this->maybeStashGlobal( $var );
25 $GLOBALS[$var] = $rand;
26 $config = new GlobalVarConfig( $prefix );
27 $this->assertInstanceOf( 'GlobalVarConfig', $config );
28 $this->assertEquals( $rand, $config->get( 'GlobalVarConfigTest' ) );
31 public static function provideConstructor() {
36 array( 'blahblahblahblah' ),
42 * @covers GlobalVarConfig::has
44 public function testHas() {
45 $this->maybeStashGlobal( 'wgGlobalVarConfigTestHas' );
46 $GLOBALS['wgGlobalVarConfigTestHas'] = wfRandomString();
47 $this->maybeStashGlobal( 'wgGlobalVarConfigTestNotHas' );
48 $config = new GlobalVarConfig();
49 $this->assertTrue( $config->has( 'GlobalVarConfigTestHas' ) );
50 $this->assertFalse( $config->has( 'GlobalVarConfigTestNotHas' ) );
53 public static function provideGet() {
55 'wgSomething' => 'default1',
56 'wgFoo' => 'default2',
57 'efVariable' => 'default3',
61 foreach ( $set as $var => $value ) {
62 $GLOBALS[$var] = $value;
66 array( 'Something', 'wg', 'default1' ),
67 array( 'Foo', 'wg', 'default2' ),
68 array( 'Variable', 'ef', 'default3' ),
69 array( 'BAR', '', 'default4' ),
70 array( 'ThisGlobalWasNotSetAbove', 'wg', false )
76 * @param string $prefix
77 * @param string $expected
78 * @dataProvider provideGet
79 * @covers GlobalVarConfig::get
80 * @covers GlobalVarConfig::getWithPrefix
82 public function testGet( $name, $prefix, $expected ) {
83 $config = new GlobalVarConfig( $prefix );
84 if ( $expected === false ) {
85 $this->setExpectedException( 'ConfigException', 'GlobalVarConfig::get: undefined option:' );
87 $this->assertEquals( $config->get( $name ), $expected );
90 private function maybeStashGlobal( $var ) {
91 if ( array_key_exists( $var, $GLOBALS ) ) {
92 // Will be reset after this test is over
93 $this->stashMwGlobals( $var );