2014-02-04 07:21:45 +00:00
|
|
|
<?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 ) {
|
2018-01-13 00:02:09 +00:00
|
|
|
$template = $this->getMockForAbstractClass( BaseTemplate::class );
|
2014-02-04 07:21:45 +00:00
|
|
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
$expected,
|
|
|
|
|
$template->makeListItem( $key, $item, $options ),
|
|
|
|
|
$message
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function makeListItemProvider() {
|
2016-03-02 19:57:35 +00:00
|
|
|
return [
|
|
|
|
|
[
|
2014-02-04 07:21:45 +00:00
|
|
|
'<li class="class" title="itemtitle"><a href="url" title="title">text</a></li>',
|
|
|
|
|
'',
|
2016-03-02 19:57:35 +00:00
|
|
|
[
|
2014-04-24 12:35:05 +00:00
|
|
|
'class' => 'class',
|
|
|
|
|
'itemtitle' => 'itemtitle',
|
|
|
|
|
'href' => 'url',
|
|
|
|
|
'title' => 'title',
|
|
|
|
|
'text' => 'text'
|
2016-03-02 19:57:35 +00:00
|
|
|
],
|
|
|
|
|
[],
|
2016-08-11 20:54:05 +00:00
|
|
|
'Test makeListItem with normal values'
|
2016-03-02 19:57:35 +00:00
|
|
|
]
|
|
|
|
|
];
|
2014-02-04 07:21:45 +00:00
|
|
|
}
|
2017-01-20 14:00:28 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return PHPUnit_Framework_MockObject_MockObject|OutputPage
|
|
|
|
|
*/
|
|
|
|
|
private function getMockOutputPage( $isSyndicated, $html ) {
|
2017-02-07 18:20:28 +00:00
|
|
|
$mock = $this->getMockBuilder( OutputPage::class )
|
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
|
->getMock();
|
2017-01-20 14:00:28 +00:00
|
|
|
$mock->expects( $this->once() )
|
|
|
|
|
->method( 'isSyndicated' )
|
|
|
|
|
->will( $this->returnValue( $isSyndicated ) );
|
2018-04-24 23:22:00 +00:00
|
|
|
$mock->expects( $this->any() )
|
2017-01-20 14:00:28 +00:00
|
|
|
->method( 'getHTML' )
|
|
|
|
|
->will( $this->returnValue( $html ) );
|
|
|
|
|
return $mock;
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-24 23:22:00 +00:00
|
|
|
public function provideGetDefaultModules() {
|
2017-01-20 14:00:28 +00:00
|
|
|
$defaultStyles = [
|
|
|
|
|
'mediawiki.legacy.shared',
|
|
|
|
|
'mediawiki.legacy.commonPrint',
|
|
|
|
|
];
|
|
|
|
|
$buttonStyle = 'mediawiki.ui.button';
|
|
|
|
|
$feedStyle = 'mediawiki.feedlink';
|
|
|
|
|
return [
|
|
|
|
|
[
|
2018-04-24 23:22:00 +00:00
|
|
|
false,
|
|
|
|
|
'',
|
2017-01-20 14:00:28 +00:00
|
|
|
$defaultStyles
|
|
|
|
|
],
|
|
|
|
|
[
|
2018-04-24 23:22:00 +00:00
|
|
|
true,
|
|
|
|
|
'',
|
2017-01-20 14:00:28 +00:00
|
|
|
array_merge( $defaultStyles, [ $feedStyle ] )
|
|
|
|
|
],
|
|
|
|
|
[
|
2018-04-24 23:22:00 +00:00
|
|
|
false,
|
|
|
|
|
'FOO mw-ui-button BAR',
|
2017-01-20 14:00:28 +00:00
|
|
|
array_merge( $defaultStyles, [ $buttonStyle ] )
|
|
|
|
|
],
|
|
|
|
|
[
|
2018-04-24 23:22:00 +00:00
|
|
|
true,
|
|
|
|
|
'FOO mw-ui-button BAR',
|
|
|
|
|
array_merge( $defaultStyles, [ $buttonStyle, $feedStyle ] )
|
2017-01-20 14:00:28 +00:00
|
|
|
],
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2018-04-24 23:22:00 +00:00
|
|
|
* @covers Skin::getDefaultModules
|
|
|
|
|
* @dataProvider provideGetDefaultModules
|
2017-01-20 14:00:28 +00:00
|
|
|
*/
|
2018-04-24 23:22:00 +00:00
|
|
|
public function testgetDefaultModules( $isSyndicated, $html, $expectedModuleStyles ) {
|
|
|
|
|
$skin = new SkinTemplate();
|
2017-01-20 14:00:28 +00:00
|
|
|
|
2018-04-24 23:22:00 +00:00
|
|
|
$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'
|
|
|
|
|
);
|
2017-01-20 14:00:28 +00:00
|
|
|
}
|
2014-02-04 07:21:45 +00:00
|
|
|
}
|