summaryrefslogtreecommitdiff
path: root/www/wiki/tests/phpunit/includes/skins
diff options
context:
space:
mode:
Diffstat (limited to 'www/wiki/tests/phpunit/includes/skins')
-rw-r--r--www/wiki/tests/phpunit/includes/skins/SkinFactoryTest.php82
-rw-r--r--www/wiki/tests/phpunit/includes/skins/SkinTemplateTest.php101
2 files changed, 183 insertions, 0 deletions
diff --git a/www/wiki/tests/phpunit/includes/skins/SkinFactoryTest.php b/www/wiki/tests/phpunit/includes/skins/SkinFactoryTest.php
new file mode 100644
index 00000000..4289fd91
--- /dev/null
+++ b/www/wiki/tests/phpunit/includes/skins/SkinFactoryTest.php
@@ -0,0 +1,82 @@
+<?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::class );
+ $factory->register( 'invalid', 'Invalid', 'Invalid callback' );
+ }
+
+ /**
+ * @covers SkinFactory::makeSkin
+ */
+ public function testMakeSkinWithNoBuilders() {
+ $factory = new SkinFactory();
+ $this->setExpectedException( SkinException::class );
+ $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::class );
+ $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::class, $skin );
+ $this->assertInstanceOf( SkinFallback::class, $skin );
+ $this->assertEquals( 'fallback', $skin->getSkinName() );
+ }
+
+ /**
+ * @covers Skin::__construct
+ * @covers Skin::getSkinName
+ */
+ public function testGetSkinName() {
+ $skin = new SkinFallback();
+ $this->assertEquals( 'fallback', $skin->getSkinName(), 'Default' );
+ $skin = new SkinFallback( 'testname' );
+ $this->assertEquals( 'testname', $skin->getSkinName(), 'Constructor argument' );
+ }
+
+ /**
+ * @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/www/wiki/tests/phpunit/includes/skins/SkinTemplateTest.php b/www/wiki/tests/phpunit/includes/skins/SkinTemplateTest.php
new file mode 100644
index 00000000..06b06677
--- /dev/null
+++ b/www/wiki/tests/phpunit/includes/skins/SkinTemplateTest.php
@@ -0,0 +1,101 @@
+<?php
+
+/**
+ * @covers SkinTemplate
+ *
+ * @group Output
+ *
+ * @author Bene* < benestar.wikimedia@gmail.com >
+ */
+class SkinTemplateTest extends MediaWikiTestCase {
+ /**
+ * @dataProvider makeListItemProvider
+ */
+ public function testMakeListItem( $expected, $key, $item, $options, $message ) {
+ $template = $this->getMockForAbstractClass( BaseTemplate::class );
+
+ $this->assertEquals(
+ $expected,
+ $template->makeListItem( $key, $item, $options ),
+ $message
+ );
+ }
+
+ public function makeListItemProvider() {
+ return [
+ [
+ '<li class="class" title="itemtitle"><a href="url" title="title">text</a></li>',
+ '',
+ [
+ 'class' => 'class',
+ 'itemtitle' => 'itemtitle',
+ 'href' => 'url',
+ 'title' => 'title',
+ 'text' => 'text'
+ ],
+ [],
+ 'Test makeListItem with normal values'
+ ]
+ ];
+ }
+
+ /**
+ * @return PHPUnit_Framework_MockObject_MockObject|OutputPage
+ */
+ private function getMockOutputPage( $isSyndicated, $html ) {
+ $mock = $this->getMockBuilder( OutputPage::class )
+ ->disableOriginalConstructor()
+ ->getMock();
+ $mock->expects( $this->once() )
+ ->method( 'isSyndicated' )
+ ->will( $this->returnValue( $isSyndicated ) );
+ $mock->expects( $this->once() )
+ ->method( 'getHTML' )
+ ->will( $this->returnValue( $html ) );
+ return $mock;
+ }
+
+ public function provideSetupSkinUserCss() {
+ $defaultStyles = [
+ 'mediawiki.legacy.shared',
+ 'mediawiki.legacy.commonPrint',
+ 'mediawiki.sectionAnchor',
+ ];
+ $buttonStyle = 'mediawiki.ui.button';
+ $feedStyle = 'mediawiki.feedlink';
+ return [
+ [
+ $this->getMockOutputPage( false, '' ),
+ $defaultStyles
+ ],
+ [
+ $this->getMockOutputPage( true, '' ),
+ array_merge( $defaultStyles, [ $feedStyle ] )
+ ],
+ [
+ $this->getMockOutputPage( false, 'FOO mw-ui-button BAR' ),
+ array_merge( $defaultStyles, [ $buttonStyle ] )
+ ],
+ [
+ $this->getMockOutputPage( true, 'FOO mw-ui-button BAR' ),
+ array_merge( $defaultStyles, [ $feedStyle, $buttonStyle ] )
+ ],
+ ];
+ }
+
+ /**
+ * @param PHPUnit_Framework_MockObject_MockObject|OutputPage $outputPageMock
+ * @param string[] $expectedModuleStyles
+ *
+ * @covers SkinTemplate::setupSkinUserCss
+ * @dataProvider provideSetupSkinUserCss
+ */
+ public function testSetupSkinUserCss( $outputPageMock, $expectedModuleStyles ) {
+ $outputPageMock->expects( $this->once() )
+ ->method( 'addModuleStyles' )
+ ->with( $expectedModuleStyles );
+
+ $skinTemplate = new SkinTemplate();
+ $skinTemplate->setupSkinUserCss( $outputPageMock );
+ }
+}