diff options
author | Luke Shumaker <lukeshu@sbcglobal.net> | 2016-05-01 15:17:42 -0400 |
---|---|---|
committer | Luke Shumaker <lukeshu@sbcglobal.net> | 2016-05-01 15:17:42 -0400 |
commit | f7d4cf9ed0ae68fec630d14e8f6aade38e49f036 (patch) | |
tree | a730c57badbe0e2f0f064ca2006c82d4b6ed54ea /tests/phpunit/includes/skins | |
parent | aee35e4a93d105024bcae947cd8b16c962191f5c (diff) | |
parent | 5d1e7dd0ccda0984ccf3e8e3d0f88ac888b05819 (diff) |
Merge commit '5d1e7'
Diffstat (limited to 'tests/phpunit/includes/skins')
-rw-r--r-- | tests/phpunit/includes/skins/SkinFactoryTest.php | 70 | ||||
-rw-r--r-- | tests/phpunit/includes/skins/SkinTemplateTest.php | 43 |
2 files changed, 113 insertions, 0 deletions
diff --git a/tests/phpunit/includes/skins/SkinFactoryTest.php b/tests/phpunit/includes/skins/SkinFactoryTest.php new file mode 100644 index 00000000..d3663c84 --- /dev/null +++ b/tests/phpunit/includes/skins/SkinFactoryTest.php @@ -0,0 +1,70 @@ +<?php + +class SkinFactoryTest extends MediaWikiTestCase { + + /** + * @covers SkinFactory::register + */ + public function testRegister() { + $factory = new SkinFactory(); + $factory->register( 'fallback', 'Fallback', function () { + return new SkinFallback(); + } ); + $this->assertTrue( true ); // No exception thrown + $this->setExpectedException( 'InvalidArgumentException' ); + $factory->register( 'invalid', 'Invalid', 'Invalid callback' ); + } + + /** + * @covers SkinFactory::makeSkin + */ + public function testMakeSkinWithNoBuilders() { + $factory = new SkinFactory(); + $this->setExpectedException( 'SkinException' ); + $factory->makeSkin( 'nobuilderregistered' ); + } + + /** + * @covers SkinFactory::makeSkin + */ + public function testMakeSkinWithInvalidCallback() { + $factory = new SkinFactory(); + $factory->register( 'unittest', 'Unittest', function () { + return true; // Not a Skin object + } ); + $this->setExpectedException( 'UnexpectedValueException' ); + $factory->makeSkin( 'unittest' ); + } + + /** + * @covers SkinFactory::makeSkin + */ + public function testMakeSkinWithValidCallback() { + $factory = new SkinFactory(); + $factory->register( 'testfallback', 'TestFallback', function () { + return new SkinFallback(); + } ); + + $skin = $factory->makeSkin( 'testfallback' ); + $this->assertInstanceOf( 'Skin', $skin ); + $this->assertInstanceOf( 'SkinFallback', $skin ); + } + + /** + * @covers SkinFactory::getSkinNames + */ + public function testGetSkinNames() { + $factory = new SkinFactory(); + // A fake callback we can use that will never be called + $callback = function () { + // NOP + }; + $factory->register( 'skin1', 'Skin1', $callback ); + $factory->register( 'skin2', 'Skin2', $callback ); + $names = $factory->getSkinNames(); + $this->assertArrayHasKey( 'skin1', $names ); + $this->assertArrayHasKey( 'skin2', $names ); + $this->assertEquals( 'Skin1', $names['skin1'] ); + $this->assertEquals( 'Skin2', $names['skin2'] ); + } +} diff --git a/tests/phpunit/includes/skins/SkinTemplateTest.php b/tests/phpunit/includes/skins/SkinTemplateTest.php new file mode 100644 index 00000000..baa995d4 --- /dev/null +++ b/tests/phpunit/includes/skins/SkinTemplateTest.php @@ -0,0 +1,43 @@ +<?php + +/** + * @covers SkinTemplate + * + * @group Output + * + * @licence GNU GPL v2+ + * @author Bene* < benestar.wikimedia@gmail.com > + */ + +class SkinTemplateTest extends MediaWikiTestCase { + /** + * @dataProvider makeListItemProvider + */ + public function testMakeListItem( $expected, $key, $item, $options, $message ) { + $template = $this->getMockForAbstractClass( 'BaseTemplate' ); + + $this->assertEquals( + $expected, + $template->makeListItem( $key, $item, $options ), + $message + ); + } + + public function makeListItemProvider() { + return array( + array( + '<li class="class" title="itemtitle"><a href="url" title="title">text</a></li>', + '', + array( + 'class' => 'class', + 'itemtitle' => 'itemtitle', + 'href' => 'url', + 'title' => 'title', + 'text' => 'text' + ), + array(), + 'Test makteListItem with normal values' + ) + ); + } +} |