Move ResultWrapper subclasses to Rdbms
[mediawiki.git] / tests / phpunit / includes / skins / SkinFactoryTest.php
blobd3663c84ad5e9835d7f6c36b45074991c1fb8c15
1 <?php
3 class SkinFactoryTest extends MediaWikiTestCase {
5 /**
6 * @covers SkinFactory::register
7 */
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' );
18 /**
19 * @covers SkinFactory::makeSkin
21 public function testMakeSkinWithNoBuilders() {
22 $factory = new SkinFactory();
23 $this->setExpectedException( 'SkinException' );
24 $factory->makeSkin( 'nobuilderregistered' );
27 /**
28 * @covers SkinFactory::makeSkin
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' );
39 /**
40 * @covers SkinFactory::makeSkin
42 public function testMakeSkinWithValidCallback() {
43 $factory = new SkinFactory();
44 $factory->register( 'testfallback', 'TestFallback', function () {
45 return new SkinFallback();
46 } );
48 $skin = $factory->makeSkin( 'testfallback' );
49 $this->assertInstanceOf( 'Skin', $skin );
50 $this->assertInstanceOf( 'SkinFallback', $skin );
53 /**
54 * @covers SkinFactory::getSkinNames
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
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'] );