MediaWiki  1.32.5
GlobalVarConfigTest.php
Go to the documentation of this file.
1 <?php
2 
4 
8  public function testNewInstance() {
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 ) {
59  $GLOBALS[$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 }
GlobalVarConfigTest\testHas
testHas()
GlobalVarConfig::has GlobalVarConfig::hasWithPrefix.
Definition: GlobalVarConfigTest.php:43
false
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:187
GlobalVarConfigTest\provideGet
static provideGet()
Definition: GlobalVarConfigTest.php:50
GlobalVarConfigTest
Definition: GlobalVarConfigTest.php:3
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
MediaWikiTestCase\setMwGlobals
setMwGlobals( $pairs, $value=null)
Sets a global, maintaining a stashed version of the previous global to be restored in tearDown.
Definition: MediaWikiTestCase.php:706
MediaWikiTestCase
Definition: MediaWikiTestCase.php:16
GlobalVarConfig
Accesses configuration settings from $GLOBALS.
Definition: GlobalVarConfig.php:28
GlobalVarConfigTest\testNewInstance
testNewInstance()
GlobalVarConfig::newInstance.
Definition: GlobalVarConfigTest.php:8
GlobalVarConfigTest\provideConstructor
static provideConstructor()
Definition: GlobalVarConfigTest.php:29
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:302
$value
$value
Definition: styleTest.css.php:49
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
GlobalVarConfig\newInstance
static newInstance()
Default builder function.
Definition: GlobalVarConfig.php:40
class
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:52
GlobalVarConfigTest\testConstructor
testConstructor( $prefix)
GlobalVarConfig::__construct provideConstructor.
Definition: GlobalVarConfigTest.php:20
GlobalVarConfigTest\testGet
testGet( $name, $prefix, $expected)
provideGet GlobalVarConfig::get GlobalVarConfig::getWithPrefix
Definition: GlobalVarConfigTest.php:79
$GLOBALS
$GLOBALS['IP']
Definition: ComposerHookHandler.php:6
wfRandomString
wfRandomString( $length=32)
Get a random string containing a number of pseudo-random hex characters.
Definition: GlobalFunctions.php:296