Merge "OutputPage: addParserOutput*() family doesn't need to take a reference"
[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', $config );
11 }
12
13 public function provideGet() {
14 $set = array(
15 'wgSomething' => 'default1',
16 'wgFoo' => 'default2',
17 'efVariable' => 'default3',
18 'BAR' => 'default4',
19 );
20
21 foreach ( $set as $var => $value ) {
22 $GLOBALS[$var] = $value;
23 }
24
25 return array(
26 array( 'Something', 'wg', 'default1' ),
27 array( 'Foo', 'wg', 'default2' ),
28 array( 'Variable', 'ef', 'default3' ),
29 array( 'BAR', '', 'default4' ),
30 );
31 }
32
33 /**
34 * @param string $name
35 * @param string $prefix
36 * @param string $expected
37 * @dataProvider provideGet
38 * @covers GlobalVarConfig::get
39 * @covers GlobalVarConfig::getWithPrefix
40 */
41 public function testGet( $name, $prefix, $expected ) {
42 $config = new GlobalVarConfig( $prefix );
43 $this->assertEquals( $config->get( $name ), $expected );
44 }
45
46 public static function provideSet() {
47 return array(
48 array( 'Foo', 'wg', 'wgFoo' ),
49 array( 'SomethingRandom', 'wg', 'wgSomethingRandom' ),
50 array( 'FromAnExtension', 'eg', 'egFromAnExtension' ),
51 array( 'NoPrefixHere', '', 'NoPrefixHere' ),
52 );
53 }
54
55 /**
56 * @dataProvider provideSet
57 * @covers GlobalVarConfig::set
58 * @covers GlobalVarConfig::setWithPrefix
59 */
60 public function testSet( $name, $prefix, $var ) {
61 if ( array_key_exists( $var, $GLOBALS ) ) {
62 // Will be reset after this test is over
63 $this->stashMwGlobals( $var );
64 }
65 $config = new GlobalVarConfig( $prefix );
66 $random = wfRandomString();
67 $config->set( $name, $random );
68 $this->assertArrayHasKey( $var, $GLOBALS );
69 $this->assertEquals( $random, $GLOBALS[$var] );
70 }
71 }