Merge "DatabaseMssql: Don't duplicate body of makeList()"
[mediawiki.git] / tests / phpunit / includes / config / GlobalVarConfigTest.php
blob28068d5e2734e676f2a4b36a71b2fa147bc36eaf
1 <?php
3 class GlobalVarConfigTest extends MediaWikiTestCase {
5 /**
6 * @covers GlobalVarConfig::newInstance
7 */
8 public function testNewInstance() {
9 $config = GlobalVarConfig::newInstance();
10 $this->assertInstanceOf( 'GlobalVarConfig', $config );
11 $this->maybeStashGlobal( 'wgBaz' );
12 $GLOBALS['wgBaz'] = 'somevalue';
13 // Check prefix is set to 'wg'
14 $this->assertEquals( 'somevalue', $config->get( 'Baz' ) );
17 /**
18 * @covers GlobalVarConfig::__construct
19 * @dataProvider provideConstructor
21 public function testConstructor( $prefix ) {
22 $var = $prefix . 'GlobalVarConfigTest';
23 $rand = wfRandomString();
24 $this->maybeStashGlobal( $var );
25 $GLOBALS[$var] = $rand;
26 $config = new GlobalVarConfig( $prefix );
27 $this->assertInstanceOf( 'GlobalVarConfig', $config );
28 $this->assertEquals( $rand, $config->get( 'GlobalVarConfigTest' ) );
31 public static function provideConstructor() {
32 return array(
33 array( 'wg' ),
34 array( 'ef' ),
35 array( 'smw' ),
36 array( 'blahblahblahblah' ),
37 array( '' ),
41 /**
42 * @covers GlobalVarConfig::has
44 public function testHas() {
45 $this->maybeStashGlobal( 'wgGlobalVarConfigTestHas' );
46 $GLOBALS['wgGlobalVarConfigTestHas'] = wfRandomString();
47 $this->maybeStashGlobal( 'wgGlobalVarConfigTestNotHas' );
48 $config = new GlobalVarConfig();
49 $this->assertTrue( $config->has( 'GlobalVarConfigTestHas' ) );
50 $this->assertFalse( $config->has( 'GlobalVarConfigTestNotHas' ) );
53 public static function provideGet() {
54 $set = array(
55 'wgSomething' => 'default1',
56 'wgFoo' => 'default2',
57 'efVariable' => 'default3',
58 'BAR' => 'default4',
61 foreach ( $set as $var => $value ) {
62 $GLOBALS[$var] = $value;
65 return array(
66 array( 'Something', 'wg', 'default1' ),
67 array( 'Foo', 'wg', 'default2' ),
68 array( 'Variable', 'ef', 'default3' ),
69 array( 'BAR', '', 'default4' ),
70 array( 'ThisGlobalWasNotSetAbove', 'wg', false )
74 /**
75 * @param string $name
76 * @param string $prefix
77 * @param string $expected
78 * @dataProvider provideGet
79 * @covers GlobalVarConfig::get
80 * @covers GlobalVarConfig::getWithPrefix
82 public function testGet( $name, $prefix, $expected ) {
83 $config = new GlobalVarConfig( $prefix );
84 if ( $expected === false ) {
85 $this->setExpectedException( 'ConfigException', 'GlobalVarConfig::get: undefined option:' );
87 $this->assertEquals( $config->get( $name ), $expected );
90 private function maybeStashGlobal( $var ) {
91 if ( array_key_exists( $var, $GLOBALS ) ) {
92 // Will be reset after this test is over
93 $this->stashMwGlobals( $var );