3 class GlobalVarConfigTest
extends MediaWikiTestCase
{
6 * @covers GlobalVarConfig::newInstance
8 public function testNewInstance() {
9 $config = GlobalVarConfig
::newInstance();
10 $this->assertInstanceOf( 'GlobalVarConfig', $config );
13 public function provideGet() {
15 'wgSomething' => 'default1',
16 'wgFoo' => 'default2',
17 'efVariable' => 'default3',
21 foreach ( $set as $var => $value ) {
22 $GLOBALS[$var] = $value;
26 array( 'Something', 'wg', 'default1' ),
27 array( 'Foo', 'wg', 'default2' ),
28 array( 'Variable', 'ef', 'default3' ),
29 array( 'BAR', '', 'default4' ),
35 * @param string $prefix
36 * @param string $expected
37 * @dataProvider provideGet
38 * @covers GlobalVarConfig::get
39 * @covers GlobalVarConfig::getWithPrefix
41 public function testGet( $name, $prefix, $expected ) {
42 $config = new GlobalVarConfig( $prefix );
43 $this->assertEquals( $config->get( $name ), $expected );
46 public static function provideSet() {
48 array( 'Foo', 'wg', 'wgFoo' ),
49 array( 'SomethingRandom', 'wg', 'wgSomethingRandom' ),
50 array( 'FromAnExtension', 'eg', 'egFromAnExtension' ),
51 array( 'NoPrefixHere', '', 'NoPrefixHere' ),
56 * @dataProvider provideSet
57 * @covers GlobalVarConfig::set
58 * @covers GlobalVarConfig::setWithPrefix
60 public function testSet( $name, $prefix, $var ) {
61 if ( array_key_exists( $var, $GLOBALS ) ) {
62 // Will be reset after this test is over
63 $this->stashMwGlobals( $var );
65 $config = new GlobalVarConfig( $prefix );
66 $random = wfRandomString();
67 $config->set( $name, $random );
68 $this->assertArrayHasKey( $var, $GLOBALS );
69 $this->assertEquals( $random, $GLOBALS[$var] );