MediaWiki REL1_30
GlobalVarConfigTest.php
Go to the documentation of this file.
1<?php
2
4
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' ) );
15 }
16
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' ) );
29 }
30
31 public static function provideConstructor() {
32 return [
33 [ 'wg' ],
34 [ 'ef' ],
35 [ 'smw' ],
36 [ 'blahblahblahblah' ],
37 [ '' ],
38 ];
39 }
40
45 public function testHas() {
46 $this->maybeStashGlobal( 'wgGlobalVarConfigTestHas' );
47 $GLOBALS['wgGlobalVarConfigTestHas'] = wfRandomString();
48 $this->maybeStashGlobal( 'wgGlobalVarConfigTestNotHas' );
49 $config = new GlobalVarConfig();
50 $this->assertTrue( $config->has( 'GlobalVarConfigTestHas' ) );
51 $this->assertFalse( $config->has( 'GlobalVarConfigTestNotHas' ) );
52 }
53
54 public static function provideGet() {
55 $set = [
56 'wgSomething' => 'default1',
57 'wgFoo' => 'default2',
58 'efVariable' => 'default3',
59 'BAR' => 'default4',
60 ];
61
62 foreach ( $set as $var => $value ) {
63 $GLOBALS[$var] = $value;
64 }
65
66 return [
67 [ 'Something', 'wg', 'default1' ],
68 [ 'Foo', 'wg', 'default2' ],
69 [ 'Variable', 'ef', 'default3' ],
70 [ 'BAR', '', 'default4' ],
71 [ 'ThisGlobalWasNotSetAbove', 'wg', false ]
72 ];
73 }
74
83 public function testGet( $name, $prefix, $expected ) {
84 $config = new GlobalVarConfig( $prefix );
85 if ( $expected === false ) {
86 $this->setExpectedException( 'ConfigException', 'GlobalVarConfig::get: undefined option:' );
87 }
88 $this->assertEquals( $config->get( $name ), $expected );
89 }
90
91 private function maybeStashGlobal( $var ) {
92 if ( array_key_exists( $var, $GLOBALS ) ) {
93 // Will be reset after this test is over
94 $this->stashMwGlobals( $var );
95 }
96 }
97}
$GLOBALS['wgAutoloadClasses']['LocalisationUpdate']
Definition Autoload.php:10
wfRandomString( $length=32)
Get a random string containing a number of pseudo-random hex characters.
testHas()
GlobalVarConfig::has GlobalVarConfig::hasWithPrefix.
testConstructor( $prefix)
GlobalVarConfig::__construct provideConstructor.
testNewInstance()
GlobalVarConfig::newInstance.
testGet( $name, $prefix, $expected)
provideGet GlobalVarConfig::get GlobalVarConfig::getWithPrefix
Accesses configuration settings from $GLOBALS.
stashMwGlobals( $globalKeys)
Stashes the global, will be restored in tearDown()
processing should stop and the error should be shown to the user * false
Definition hooks.txt:187