3 class GlobalVarConfigTest
extends MediaWikiTestCase
{
6 * @covers GlobalVarConfig::newInstance
8 public function testNewInstance() {
9 $config = GlobalVarConfig
::newInstance();
10 $this->assertInstanceOf( GlobalVarConfig
::class, $config );
11 $this->setMwGlobals( 'wgBaz', 'somevalue' );
12 // Check prefix is set to 'wg'
13 $this->assertEquals( 'somevalue', $config->get( 'Baz' ) );
17 * @covers GlobalVarConfig::__construct
18 * @dataProvider provideConstructor
20 public function testConstructor( $prefix ) {
21 $var = $prefix . 'GlobalVarConfigTest';
22 $this->setMwGlobals( $var, 'testvalue' );
23 $config = new GlobalVarConfig( $prefix );
24 $this->assertInstanceOf( GlobalVarConfig
::class, $config );
25 $this->assertEquals( 'testvalue', $config->get( 'GlobalVarConfigTest' ) );
28 public static function provideConstructor() {
33 [ 'blahblahblahblah' ],
39 * @covers GlobalVarConfig::has
40 * @covers GlobalVarConfig::hasWithPrefix
42 public function testHas() {
43 $this->setMwGlobals( 'wgGlobalVarConfigTestHas', 'testvalue' );
44 $config = new GlobalVarConfig();
45 $this->assertTrue( $config->has( 'GlobalVarConfigTestHas' ) );
46 $this->assertFalse( $config->has( 'GlobalVarConfigTestNotHas' ) );
49 public static function provideGet() {
51 'wgSomething' => 'default1',
52 'wgFoo' => 'default2',
53 'efVariable' => 'default3',
57 foreach ( $set as $var => $value ) {
58 $GLOBALS[$var] = $value;
62 [ 'Something', 'wg', 'default1' ],
63 [ 'Foo', 'wg', 'default2' ],
64 [ 'Variable', 'ef', 'default3' ],
65 [ 'BAR', '', 'default4' ],
66 [ 'ThisGlobalWasNotSetAbove', 'wg', false ]
71 * @dataProvider provideGet
72 * @covers GlobalVarConfig::get
73 * @covers GlobalVarConfig::getWithPrefix
75 * @param string $prefix
76 * @param string $expected
78 public function testGet( $name, $prefix, $expected ) {
79 $config = new GlobalVarConfig( $prefix );
80 if ( $expected === false ) {
81 $this->setExpectedException( ConfigException
::class, 'GlobalVarConfig::get: undefined option:' );
83 $this->assertEquals( $config->get( $name ), $expected );