RightsLogFormatter: Use DB key to generate foreign user link
[lhc/web/wiklou.git] / tests / phpunit / includes / config / ConfigFactoryTest.php
1 <?php
2
3 class ConfigFactoryTest extends MediaWikiTestCase {
4
5 public function tearDown() {
6 // Reset this since we mess with it a bit
7 ConfigFactory::destroyDefaultInstance();
8 parent::tearDown();
9 }
10
11 /**
12 * @covers ConfigFactory::register
13 */
14 public function testRegister() {
15 $factory = new ConfigFactory();
16 $factory->register( 'unittest', 'GlobalVarConfig::newInstance' );
17 $this->assertTrue( true ); // No exception thrown
18 $this->setExpectedException( 'InvalidArgumentException' );
19 $factory->register( 'invalid', 'Invalid callback' );
20 }
21
22 /**
23 * @covers ConfigFactory::makeConfig
24 */
25 public function testMakeConfig() {
26 $factory = new ConfigFactory();
27 $factory->register( 'unittest', 'GlobalVarConfig::newInstance' );
28 $conf = $factory->makeConfig( 'unittest' );
29 $this->assertInstanceOf( 'Config', $conf );
30 }
31
32 /**
33 * @covers ConfigFactory::makeConfig
34 */
35 public function testMakeConfigWithNoBuilders() {
36 $factory = new ConfigFactory();
37 $this->setExpectedException( 'ConfigException' );
38 $factory->makeConfig( 'nobuilderregistered' );
39 }
40
41 /**
42 * @covers ConfigFactory::makeConfig
43 */
44 public function testMakeConfigWithInvalidCallback() {
45 $factory = new ConfigFactory();
46 $factory->register( 'unittest', function () {
47 return true; // Not a Config object
48 } );
49 $this->setExpectedException( 'UnexpectedValueException' );
50 $factory->makeConfig( 'unittest' );
51 }
52
53 /**
54 * @covers ConfigFactory::getDefaultInstance
55 */
56 public function testGetDefaultInstance() {
57 // Set $wgConfigRegistry, and check the default
58 // instance read from it
59 $this->setMwGlobals( 'wgConfigRegistry', [
60 'conf1' => 'GlobalVarConfig::newInstance',
61 'conf2' => 'GlobalVarConfig::newInstance',
62 ] );
63 ConfigFactory::destroyDefaultInstance();
64 $factory = ConfigFactory::getDefaultInstance();
65 $this->assertInstanceOf( 'Config', $factory->makeConfig( 'conf1' ) );
66 $this->assertInstanceOf( 'Config', $factory->makeConfig( 'conf2' ) );
67 $this->setExpectedException( 'ConfigException' );
68 $factory->makeConfig( 'conf3' );
69 }
70 }