Merge "maintenance: Script to rename titles for Unicode uppercasing changes"
[lhc/web/wiklou.git] / tests / phpunit / includes / config / GlobalVarConfigTest.php
1 <?php
2
3 class GlobalVarConfigTest extends MediaWikiTestCase {
4
5 /**
6 * @covers GlobalVarConfig::newInstance
7 */
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' ) );
14 }
15
16 /**
17 * @covers GlobalVarConfig::__construct
18 * @dataProvider provideConstructor
19 */
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' ) );
26 }
27
28 public static function provideConstructor() {
29 return [
30 [ 'wg' ],
31 [ 'ef' ],
32 [ 'smw' ],
33 [ 'blahblahblahblah' ],
34 [ '' ],
35 ];
36 }
37
38 /**
39 * @covers GlobalVarConfig::has
40 * @covers GlobalVarConfig::hasWithPrefix
41 */
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' ) );
47 }
48
49 public static function provideGet() {
50 $set = [
51 'wgSomething' => 'default1',
52 'wgFoo' => 'default2',
53 'efVariable' => 'default3',
54 'BAR' => 'default4',
55 ];
56
57 foreach ( $set as $var => $value ) {
58 $GLOBALS[$var] = $value;
59 }
60
61 return [
62 [ 'Something', 'wg', 'default1' ],
63 [ 'Foo', 'wg', 'default2' ],
64 [ 'Variable', 'ef', 'default3' ],
65 [ 'BAR', '', 'default4' ],
66 [ 'ThisGlobalWasNotSetAbove', 'wg', false ]
67 ];
68 }
69
70 /**
71 * @dataProvider provideGet
72 * @covers GlobalVarConfig::get
73 * @covers GlobalVarConfig::getWithPrefix
74 * @param string $name
75 * @param string $prefix
76 * @param string $expected
77 */
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:' );
82 }
83 $this->assertEquals( $config->get( $name ), $expected );
84 }
85 }