Merge "Replace wfGetLB"
[lhc/web/wiklou.git] / tests / phpunit / includes / skins / SkinTemplateTest.php
1 <?php
2
3 /**
4 * @covers SkinTemplate
5 *
6 * @group Output
7 *
8 * @author Bene* < benestar.wikimedia@gmail.com >
9 */
10 class SkinTemplateTest extends MediaWikiTestCase {
11 /**
12 * @dataProvider makeListItemProvider
13 */
14 public function testMakeListItem( $expected, $key, $item, $options, $message ) {
15 $template = $this->getMockForAbstractClass( BaseTemplate::class );
16
17 $this->assertEquals(
18 $expected,
19 $template->makeListItem( $key, $item, $options ),
20 $message
21 );
22 }
23
24 public function makeListItemProvider() {
25 return [
26 [
27 '<li class="class" title="itemtitle"><a href="url" title="title">text</a></li>',
28 '',
29 [
30 'class' => 'class',
31 'itemtitle' => 'itemtitle',
32 'href' => 'url',
33 'title' => 'title',
34 'text' => 'text'
35 ],
36 [],
37 'Test makeListItem with normal values'
38 ]
39 ];
40 }
41
42 /**
43 * @return PHPUnit_Framework_MockObject_MockObject|OutputPage
44 */
45 private function getMockOutputPage( $isSyndicated, $html ) {
46 $mock = $this->getMockBuilder( OutputPage::class )
47 ->disableOriginalConstructor()
48 ->getMock();
49 $mock->expects( $this->once() )
50 ->method( 'isSyndicated' )
51 ->will( $this->returnValue( $isSyndicated ) );
52 $mock->expects( $this->once() )
53 ->method( 'getHTML' )
54 ->will( $this->returnValue( $html ) );
55 return $mock;
56 }
57
58 public function provideSetupSkinUserCss() {
59 $defaultStyles = [
60 'mediawiki.legacy.shared',
61 'mediawiki.legacy.commonPrint',
62 ];
63 $buttonStyle = 'mediawiki.ui.button';
64 $feedStyle = 'mediawiki.feedlink';
65 return [
66 [
67 $this->getMockOutputPage( false, '' ),
68 $defaultStyles
69 ],
70 [
71 $this->getMockOutputPage( true, '' ),
72 array_merge( $defaultStyles, [ $feedStyle ] )
73 ],
74 [
75 $this->getMockOutputPage( false, 'FOO mw-ui-button BAR' ),
76 array_merge( $defaultStyles, [ $buttonStyle ] )
77 ],
78 [
79 $this->getMockOutputPage( true, 'FOO mw-ui-button BAR' ),
80 array_merge( $defaultStyles, [ $feedStyle, $buttonStyle ] )
81 ],
82 ];
83 }
84
85 /**
86 * @param PHPUnit_Framework_MockObject_MockObject|OutputPage $outputPageMock
87 * @param string[] $expectedModuleStyles
88 *
89 * @covers SkinTemplate::setupSkinUserCss
90 * @dataProvider provideSetupSkinUserCss
91 */
92 public function testSetupSkinUserCss( $outputPageMock, $expectedModuleStyles ) {
93 $outputPageMock->expects( $this->once() )
94 ->method( 'addModuleStyles' )
95 ->with( $expectedModuleStyles );
96
97 $skinTemplate = new SkinTemplate();
98 $skinTemplate->setupSkinUserCss( $outputPageMock );
99 }
100 }