MediaWiki  1.30.0
SkinFactoryTest.php
Go to the documentation of this file.
1 <?php
2 
4 
8  public function testRegister() {
9  $factory = new SkinFactory();
10  $factory->register( 'fallback', 'Fallback', function () {
11  return new SkinFallback();
12  } );
13  $this->assertTrue( true ); // No exception thrown
14  $this->setExpectedException( 'InvalidArgumentException' );
15  $factory->register( 'invalid', 'Invalid', 'Invalid callback' );
16  }
17 
21  public function testMakeSkinWithNoBuilders() {
22  $factory = new SkinFactory();
23  $this->setExpectedException( 'SkinException' );
24  $factory->makeSkin( 'nobuilderregistered' );
25  }
26 
30  public function testMakeSkinWithInvalidCallback() {
31  $factory = new SkinFactory();
32  $factory->register( 'unittest', 'Unittest', function () {
33  return true; // Not a Skin object
34  } );
35  $this->setExpectedException( 'UnexpectedValueException' );
36  $factory->makeSkin( 'unittest' );
37  }
38 
42  public function testMakeSkinWithValidCallback() {
43  $factory = new SkinFactory();
44  $factory->register( 'testfallback', 'TestFallback', function () {
45  return new SkinFallback();
46  } );
47 
48  $skin = $factory->makeSkin( 'testfallback' );
49  $this->assertInstanceOf( 'Skin', $skin );
50  $this->assertInstanceOf( 'SkinFallback', $skin );
51  }
52 
56  public function testGetSkinNames() {
57  $factory = new SkinFactory();
58  // A fake callback we can use that will never be called
59  $callback = function () {
60  // NOP
61  };
62  $factory->register( 'skin1', 'Skin1', $callback );
63  $factory->register( 'skin2', 'Skin2', $callback );
64  $names = $factory->getSkinNames();
65  $this->assertArrayHasKey( 'skin1', $names );
66  $this->assertArrayHasKey( 'skin2', $names );
67  $this->assertEquals( 'Skin1', $names['skin1'] );
68  $this->assertEquals( 'Skin2', $names['skin2'] );
69  }
70 }
SkinFactoryTest\testMakeSkinWithInvalidCallback
testMakeSkinWithInvalidCallback()
SkinFactory::makeSkin.
Definition: SkinFactoryTest.php:30
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
SkinFactoryTest
Definition: SkinFactoryTest.php:3
SkinFactoryTest\testGetSkinNames
testGetSkinNames()
SkinFactory::getSkinNames.
Definition: SkinFactoryTest.php:56
MediaWikiTestCase
Definition: MediaWikiTestCase.php:15
SkinFallback
SkinTemplate class for the fallback skin.
Definition: SkinFallback.php:14
SkinFactoryTest\testRegister
testRegister()
SkinFactory::register.
Definition: SkinFactoryTest.php:8
SkinFactory
Factory class to create Skin objects.
Definition: SkinFactory.php:31
SkinFactoryTest\testMakeSkinWithNoBuilders
testMakeSkinWithNoBuilders()
SkinFactory::makeSkin.
Definition: SkinFactoryTest.php:21
$skin
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned $skin
Definition: hooks.txt:1965
SkinFactoryTest\testMakeSkinWithValidCallback
testMakeSkinWithValidCallback()
SkinFactory::makeSkin.
Definition: SkinFactoryTest.php:42