Add more tests for GlobalVarConfig
authorKunal Mehta <legoktm@gmail.com>
Wed, 20 Aug 2014 07:35:35 +0000 (00:35 -0700)
committerKunal Mehta <legoktm@gmail.com>
Thu, 21 Aug 2014 23:33:29 +0000 (16:33 -0700)
Change-Id: I31d50a0636792104e32e3f25694f45942c5c0217

tests/phpunit/includes/config/GlobalVarConfigTest.php

index 7080b02..662f268 100644 (file)
@@ -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] );
+       }
 }