The old way of providing a callable to SkinFactory::register is still supported. Those callables expected the skin name as their first argument. Coincidentally, so does the constructor of Skin. Some skins might not define any constructor parameters at all, which is acceptable to PHP, as it will just discard the argument. The registration using $wgValidSkinNames has not been changed, and skins that want to define services to be injected will still need to manually register their skin to the skin factory. CodeSearch did not indicate any extensions or skins manually constructing a SkinFactory in tests, but for posterity, the old way of creating a SkinFactory for testing can be replaced with new SkinFactory( new ObjectFactory( $this->createMock( ContainerInterface::class ) ) ); Note that the constructor for SkinFactory for internal use only, in accordance with the Stable interface policy. You should use MediaWikiServices::getInstance()->getSkinFactory instead. Bug: T244466 Change-Id: I8ba9d869bddd9b6124e47697b789d752c0620b02
64 lines
1.7 KiB
PHP
64 lines
1.7 KiB
PHP
<?php
|
|
|
|
use Psr\Container\ContainerInterface;
|
|
use Wikimedia\ObjectFactory;
|
|
|
|
class SkinTest extends MediaWikiTestCase {
|
|
|
|
/**
|
|
* @covers Skin::getDefaultModules
|
|
*/
|
|
public function testGetDefaultModules() {
|
|
$skin = $this->getMockBuilder( Skin::class )
|
|
->setMethods( [ 'outputPage', 'setupSkinUserCss' ] )
|
|
->getMock();
|
|
|
|
$modules = $skin->getDefaultModules();
|
|
$this->assertTrue( isset( $modules['core'] ), 'core key is set by default' );
|
|
$this->assertTrue( isset( $modules['styles'] ), 'style key is set by default' );
|
|
}
|
|
|
|
/**
|
|
* @covers Skin::getAllowedSkins
|
|
*/
|
|
public function testGetAllowedSkinsEmpty() {
|
|
$skin = $this->getMockBuilder( Skin::class )
|
|
->setMethods( [ 'outputPage' ] )
|
|
->getMock();
|
|
|
|
$this->setService( 'SkinFactory', new SkinFactory(
|
|
new ObjectFactory( $this->createMock( ContainerInterface::class ) )
|
|
) );
|
|
$this->setMwGlobals( 'wgSkipSkins', [] );
|
|
|
|
$this->assertEquals( [], $skin->getAllowedSkins() );
|
|
}
|
|
|
|
/**
|
|
* @covers Skin::getAllowedSkins
|
|
*/
|
|
public function testGetAllowedSkins() {
|
|
$skin = $this->getMockBuilder( Skin::class )
|
|
->setMethods( [ 'outputPage' ] )
|
|
->getMock();
|
|
$noop = function () {
|
|
};
|
|
|
|
$sf = new SkinFactory(
|
|
new ObjectFactory( $this->createMock( ContainerInterface::class ) )
|
|
);
|
|
$sf->register( 'foo', 'Foo', $noop );
|
|
$sf->register( 'apioutput', 'ApiOutput', $noop );
|
|
$sf->register( 'quux', 'Quux', $noop );
|
|
$sf->register( 'fallback', 'Fallback', $noop );
|
|
$sf->register( 'bar', 'Barbar', $noop );
|
|
|
|
$this->setService( 'SkinFactory', $sf );
|
|
$this->setMwGlobals( 'wgSkipSkins', [ 'quux' ] );
|
|
|
|
$this->assertEquals(
|
|
[ 'foo' => 'Foo', 'bar' => 'Barbar' ],
|
|
$skin->getAllowedSkins()
|
|
);
|
|
}
|
|
}
|