3 use MediaWiki\Config\ConfigException
;
4 use MediaWiki\Config\GlobalVarConfig
;
7 * @covers \MediaWiki\Config\GlobalVarConfig
9 class GlobalVarConfigTest
extends MediaWikiIntegrationTestCase
{
11 public function testNewInstance() {
12 $config = GlobalVarConfig
::newInstance();
13 $this->assertInstanceOf( GlobalVarConfig
::class, $config );
14 $this->setMwGlobals( 'wgBaz', 'somevalue' );
15 // Check prefix is set to 'wg'
16 $this->assertEquals( 'somevalue', $config->get( 'Baz' ) );
20 * @dataProvider provideConstructor
22 public function testConstructor( $prefix ) {
23 $var = $prefix . 'GlobalVarConfigTest';
24 $this->setMwGlobals( $var, 'testvalue' );
25 $config = new GlobalVarConfig( $prefix );
26 $this->assertInstanceOf( GlobalVarConfig
::class, $config );
27 $this->assertEquals( 'testvalue', $config->get( 'GlobalVarConfigTest' ) );
30 public static function provideConstructor() {
35 [ 'blahblahblahblah' ],
40 public function testHas() {
41 $this->setMwGlobals( 'wgGlobalVarConfigTestHas', 'testvalue' );
42 $config = new GlobalVarConfig();
43 $this->assertTrue( $config->has( 'GlobalVarConfigTestHas' ) );
44 $this->assertFalse( $config->has( 'GlobalVarConfigTestNotHas' ) );
47 public static function provideGet() {
49 'wgSomething' => 'default1',
50 'wgFoo' => 'default2',
51 'efVariable' => 'default3',
55 foreach ( $set as $var => $value ) {
56 $GLOBALS[$var] = $value;
60 [ 'Something', 'wg', 'default1' ],
61 [ 'Foo', 'wg', 'default2' ],
62 [ 'Variable', 'ef', 'default3' ],
63 [ 'BAR', '', 'default4' ],
64 [ 'ThisGlobalWasNotSetAbove', 'wg', false ]
69 * @dataProvider provideGet
71 * @param string $prefix
72 * @param string $expected
74 public function testGet( $name, $prefix, $expected ) {
75 $config = new GlobalVarConfig( $prefix );
76 if ( $expected === false ) {
77 $this->expectException( ConfigException
::class );
78 $this->expectExceptionMessage( 'GlobalVarConfig::get: undefined option:' );
80 $this->assertEquals( $expected, $config->get( $name ) );