MediaWiki REL1_33
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::class, $config );
11 $this->setMwGlobals( 'wgBaz', 'somevalue' );
12 // Check prefix is set to 'wg'
13 $this->assertEquals( 'somevalue', $config->get( 'Baz' ) );
14 }
15
20 public function testConstructor( $prefix ) {
21 $var = $prefix . 'GlobalVarConfigTest';
22 $rand = wfRandomString();
23 $this->setMwGlobals( $var, $rand );
24 $config = new GlobalVarConfig( $prefix );
25 $this->assertInstanceOf( GlobalVarConfig::class, $config );
26 $this->assertEquals( $rand, $config->get( 'GlobalVarConfigTest' ) );
27 }
28
29 public static function provideConstructor() {
30 return [
31 [ 'wg' ],
32 [ 'ef' ],
33 [ 'smw' ],
34 [ 'blahblahblahblah' ],
35 [ '' ],
36 ];
37 }
38
43 public function testHas() {
44 $this->setMwGlobals( 'wgGlobalVarConfigTestHas', wfRandomString() );
45 $config = new GlobalVarConfig();
46 $this->assertTrue( $config->has( 'GlobalVarConfigTestHas' ) );
47 $this->assertFalse( $config->has( 'GlobalVarConfigTestNotHas' ) );
48 }
49
50 public static function provideGet() {
51 $set = [
52 'wgSomething' => 'default1',
53 'wgFoo' => 'default2',
54 'efVariable' => 'default3',
55 'BAR' => 'default4',
56 ];
57
58 foreach ( $set as $var => $value ) {
60 }
61
62 return [
63 [ 'Something', 'wg', 'default1' ],
64 [ 'Foo', 'wg', 'default2' ],
65 [ 'Variable', 'ef', 'default3' ],
66 [ 'BAR', '', 'default4' ],
67 [ 'ThisGlobalWasNotSetAbove', 'wg', false ]
68 ];
69 }
70
79 public function testGet( $name, $prefix, $expected ) {
80 $config = new GlobalVarConfig( $prefix );
81 if ( $expected === false ) {
82 $this->setExpectedException( ConfigException::class, 'GlobalVarConfig::get: undefined option:' );
83 }
84 $this->assertEquals( $config->get( $name ), $expected );
85 }
86}
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
$GLOBALS['IP']
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.
setMwGlobals( $pairs, $value=null)
Sets a global, maintaining a stashed version of the previous global to be restored in tearDown.
processing should stop and the error should be shown to the user * false
Definition hooks.txt:187