MediaWiki REL1_31
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::class );
15 $factory->register( 'invalid', 'Invalid', 'Invalid callback' );
16 }
17
21 public function testMakeSkinWithNoBuilders() {
22 $factory = new SkinFactory();
23 $this->setExpectedException( SkinException::class );
24 $factory->makeSkin( 'nobuilderregistered' );
25 }
26
31 $factory = new SkinFactory();
32 $factory->register( 'unittest', 'Unittest', function () {
33 return true; // Not a Skin object
34 } );
35 $this->setExpectedException( UnexpectedValueException::class );
36 $factory->makeSkin( 'unittest' );
37 }
38
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::class, $skin );
50 $this->assertInstanceOf( SkinFallback::class, $skin );
51 $this->assertEquals( 'fallback', $skin->getSkinName() );
52 }
53
58 public function testGetSkinName() {
59 $skin = new SkinFallback();
60 $this->assertEquals( 'fallback', $skin->getSkinName(), 'Default' );
61 $skin = new SkinFallback( 'testname' );
62 $this->assertEquals( 'testname', $skin->getSkinName(), 'Constructor argument' );
63 }
64
68 public function testGetSkinNames() {
69 $factory = new SkinFactory();
70 // A fake callback we can use that will never be called
71 $callback = function () {
72 // NOP
73 };
74 $factory->register( 'skin1', 'Skin1', $callback );
75 $factory->register( 'skin2', 'Skin2', $callback );
76 $names = $factory->getSkinNames();
77 $this->assertArrayHasKey( 'skin1', $names );
78 $this->assertArrayHasKey( 'skin2', $names );
79 $this->assertEquals( 'Skin1', $names['skin1'] );
80 $this->assertEquals( 'Skin2', $names['skin2'] );
81 }
82}
testMakeSkinWithValidCallback()
SkinFactory::makeSkin.
testMakeSkinWithNoBuilders()
SkinFactory::makeSkin.
testGetSkinNames()
SkinFactory::getSkinNames.
testGetSkinName()
Skin::__construct Skin::getSkinName.
testMakeSkinWithInvalidCallback()
SkinFactory::makeSkin.
testRegister()
SkinFactory::register.
Factory class to create Skin objects.
SkinTemplate class for the fallback skin.