mediawiki.api: Adopt async-await and assert.rejects() in various tests
[mediawiki.git] / tests / phpunit / includes / config / GlobalVarConfigTest.php
blobb0197ac63297333859187e356675dd5356f0077e
1 <?php
3 use MediaWiki\Config\ConfigException;
4 use MediaWiki\Config\GlobalVarConfig;
6 /**
7 * @covers \MediaWiki\Config\GlobalVarConfig
8 */
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' ) );
19 /**
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() {
31 return [
32 [ 'wg' ],
33 [ 'ef' ],
34 [ 'smw' ],
35 [ 'blahblahblahblah' ],
36 [ '' ],
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() {
48 $set = [
49 'wgSomething' => 'default1',
50 'wgFoo' => 'default2',
51 'efVariable' => 'default3',
52 'BAR' => 'default4',
55 foreach ( $set as $var => $value ) {
56 $GLOBALS[$var] = $value;
59 return [
60 [ 'Something', 'wg', 'default1' ],
61 [ 'Foo', 'wg', 'default2' ],
62 [ 'Variable', 'ef', 'default3' ],
63 [ 'BAR', '', 'default4' ],
64 [ 'ThisGlobalWasNotSetAbove', 'wg', false ]
68 /**
69 * @dataProvider provideGet
70 * @param string $name
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 ) );