From bf89df893a0dfecd347377852b75e5724d80776c Mon Sep 17 00:00:00 2001 From: Kunal Mehta Date: Wed, 20 Aug 2014 00:35:35 -0700 Subject: [PATCH] Add more tests for GlobalVarConfig Change-Id: I31d50a0636792104e32e3f25694f45942c5c0217 --- .../includes/config/GlobalVarConfigTest.php | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/tests/phpunit/includes/config/GlobalVarConfigTest.php b/tests/phpunit/includes/config/GlobalVarConfigTest.php index 7080b02335..662f268615 100644 --- a/tests/phpunit/includes/config/GlobalVarConfigTest.php +++ b/tests/phpunit/includes/config/GlobalVarConfigTest.php @@ -2,6 +2,14 @@ class GlobalVarConfigTest extends MediaWikiTestCase { + /** + * @covers GlobalVarConfig::newInstance + */ + public function testNewInstance() { + $config = GlobalVarConfig::newInstance(); + $this->assertInstanceOf( 'GlobalVarConfig', $config ); + } + public function provideGet() { $set = array( 'wgSomething' => 'default1', @@ -28,9 +36,36 @@ class GlobalVarConfigTest extends MediaWikiTestCase { * @param string $expected * @dataProvider provideGet * @covers GlobalVarConfig::get + * @covers GlobalVarConfig::getWithPrefix */ public function testGet( $name, $prefix, $expected ) { $config = new GlobalVarConfig( $prefix ); $this->assertEquals( $config->get( $name ), $expected ); } + + public static function provideSet() { + return array( + array( 'Foo', 'wg', 'wgFoo' ), + array( 'SomethingRandom', 'wg', 'wgSomethingRandom' ), + array( 'FromAnExtension', 'eg', 'egFromAnExtension' ), + array( 'NoPrefixHere', '', 'NoPrefixHere' ), + ); + } + + /** + * @dataProvider provideSet + * @covers GlobalVarConfig::set + * @covers GlobalVarConfig::setWithPrefix + */ + public function testSet( $name, $prefix, $var ) { + if ( array_key_exists( $var, $GLOBALS ) ) { + // Will be reset after this test is over + $this->stashMwGlobals( $var ); + } + $config = new GlobalVarConfig( $prefix ); + $random = wfRandomString(); + $config->set( $name, $random ); + $this->assertArrayHasKey( $var, $GLOBALS ); + $this->assertEquals( $random, $GLOBALS[$var] ); + } } -- 2.20.1