This advances T140664 as well, because it encourages module loading logic from the skin to be in this single method. Update the tests for setupSkinUserCss(), to now target getDefaultModules() instead, given setupSkinUserCss() no longer provides these behaviours. Had to move where the mock object was created so that it can be injected in the skin (previously it could be passed as parameter). Besides, its generally best- practice to create mocks and stubs within the test anyhow, not in the data provider. Bug: T140664 Depends-On: Ib2b19ba165a9d646a770702cdf1724509156b93e Change-Id: I3404c1c2a7e8eae0b803b31f333cb9b837f43d4a
109 lines
2.4 KiB
PHP
109 lines
2.4 KiB
PHP
<?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->any() )
|
|
->method( 'getHTML' )
|
|
->will( $this->returnValue( $html ) );
|
|
return $mock;
|
|
}
|
|
|
|
public function provideGetDefaultModules() {
|
|
$defaultStyles = [
|
|
'mediawiki.legacy.shared',
|
|
'mediawiki.legacy.commonPrint',
|
|
];
|
|
$buttonStyle = 'mediawiki.ui.button';
|
|
$feedStyle = 'mediawiki.feedlink';
|
|
return [
|
|
[
|
|
false,
|
|
'',
|
|
$defaultStyles
|
|
],
|
|
[
|
|
true,
|
|
'',
|
|
array_merge( $defaultStyles, [ $feedStyle ] )
|
|
],
|
|
[
|
|
false,
|
|
'FOO mw-ui-button BAR',
|
|
array_merge( $defaultStyles, [ $buttonStyle ] )
|
|
],
|
|
[
|
|
true,
|
|
'FOO mw-ui-button BAR',
|
|
array_merge( $defaultStyles, [ $buttonStyle, $feedStyle ] )
|
|
],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @covers Skin::getDefaultModules
|
|
* @dataProvider provideGetDefaultModules
|
|
*/
|
|
public function testgetDefaultModules( $isSyndicated, $html, $expectedModuleStyles ) {
|
|
$skin = new SkinTemplate();
|
|
|
|
$context = new DerivativeContext( $skin->getContext() );
|
|
$context->setOutput( $this->getMockOutputPage( $isSyndicated, $html ) );
|
|
$skin->setContext( $context );
|
|
|
|
$modules = $skin->getDefaultModules();
|
|
|
|
$actualStylesModule = call_user_func_array( 'array_merge', $modules['styles'] );
|
|
$this->assertArraySubset(
|
|
$expectedModuleStyles,
|
|
$actualStylesModule,
|
|
'style modules'
|
|
);
|
|
}
|
|
}
|