Localisation updates from https://translatewiki.net.
[mediawiki.git] / tests / phpunit / includes / skins / SkinTemplateTest.php
blobacee7827ac75295629db58a11dc23d1a2f4856c6
1 <?php
3 use MediaWiki\MainConfigNames;
4 use MediaWiki\Title\Title;
5 use Wikimedia\TestingAccessWrapper;
7 // phpcs:ignore MediaWiki.Files.ClassMatchesFilename.NotMatch
8 class SkinQuickTemplateTest extends QuickTemplate {
9 public function execute() {
13 /**
14 * @covers \SkinTemplate
15 * @covers \Skin
16 * @group Skin
17 * @group Database
18 * @author Bene* < benestar.wikimedia@gmail.com >
20 class SkinTemplateTest extends MediaWikiIntegrationTestCase {
21 /**
22 * @dataProvider makeListItemProvider
24 public function testMakeListItem( $expected, $key, array $item, array $options, $message ) {
25 $template = $this->getMockForAbstractClass( BaseTemplate::class );
26 $template->set( 'skin', new SkinFallback( [
27 'name' => 'fallback',
28 'templateDirectory' => __DIR__,
29 ] ) );
31 $this->assertEquals(
32 $expected,
33 $template->makeListItem( $key, $item, $options ),
34 $message
38 public static function makeListItemProvider() {
39 return [
41 '<li class="class mw-list-item" title="itemtitle"><a href="url" title="title">text</a></li>',
42 '',
44 'class' => 'class',
45 'itemtitle' => 'itemtitle',
46 'href' => 'url',
47 'title' => 'title',
48 'text' => 'text'
50 [],
51 'Test makeListItem with normal values'
56 public static function provideGetFooterIcons() {
57 return [
58 // Test case 1
61 MainConfigNames::FooterIcons => [],
63 [],
64 'Empty list'
66 // Test case 2
69 MainConfigNames::FooterIcons => [
70 'poweredby' => [
71 'mediawiki' => [
72 'src' => '/w/resources/assets/poweredby_mediawiki_88x31.png',
73 'url' => 'https://www.mediawiki.org/',
74 'alt' => 'Powered by MediaWiki',
75 'srcset' => '/w/resources/assets/poweredby_mediawiki_132x47.png 1.5x,' .
76 ' /w/resources/assets/poweredby_mediawiki_176x62.png 2x',
82 'poweredby' => [
84 'src' => '/w/resources/assets/poweredby_mediawiki_88x31.png',
85 'url' => 'https://www.mediawiki.org/',
86 'alt' => 'Powered by MediaWiki',
87 'srcset' => '/w/resources/assets/poweredby_mediawiki_132x47.png 1.5x,' .
88 ' /w/resources/assets/poweredby_mediawiki_176x62.png 2x',
89 'width' => 88,
90 'height' => 31,
94 'Width and height are hardcoded if not provided'
96 // Test case 3
99 MainConfigNames::FooterIcons => [
100 'copyright' => [
101 'copyright' => [],
106 'Empty arrays are filtered out'
108 // Test case 4
111 MainConfigNames::FooterIcons => [
112 'copyright' => [
113 'copyright' => [
114 'alt' => 'Wikimedia Foundation',
115 'url' => 'https://wikimediafoundation.org'
121 'Icons with no icon are filtered out'
127 * @dataProvider provideGetFooterIcons
129 public function testGetFooterIcons( $globals, $expected, $msg ) {
130 $this->overrideConfigValues( $globals );
131 $wrapper = TestingAccessWrapper::newFromObject( new SkinTemplate() );
132 $icons = $wrapper->getFooterIcons();
134 $this->assertEquals( $expected, $icons, $msg );
138 * @dataProvider provideContentNavigation
139 * @param array $contentNavigation
140 * @param array $expected
142 public function testInjectLegacyMenusIntoPersonalTools(
143 array $contentNavigation,
144 array $expected
146 $wrapper = TestingAccessWrapper::newFromObject( new SkinTemplate() );
148 $this->assertEquals(
149 $expected,
150 $wrapper->injectLegacyMenusIntoPersonalTools( $contentNavigation )
154 public static function provideContentNavigation(): array {
155 return [
156 'No userpage set' => [
157 'contentNavigation' => [
158 'notifications' => [
159 'notification 1' => []
161 'user-menu' => [
162 'item 1' => [],
163 'item 2' => [],
164 'item 3' => []
167 'expected' => [
168 'item 1' => [],
169 'item 2' => [],
170 'item 3' => []
173 'userpage set, no notifications' => [
174 'contentNavigation' => [
175 'notifications' => [],
176 'user-menu' => [
177 'item 1' => [],
178 'userpage' => [],
179 'item 2' => [],
180 'item 3' => []
183 'expected' => [
184 'item 1' => [],
185 'userpage' => [],
186 'item 2' => [],
187 'item 3' => []
190 'userpage set, notification defined' => [
191 'contentNavigation' => [
192 'notifications' => [
193 'notification 1' => []
195 'user-menu' => [
196 'item 1' => [],
197 'userpage' => [],
198 'item 2' => [],
199 'item 3' => []
202 'expected' => [
203 'item 1' => [],
204 'userpage' => [],
205 'notification 1' => [],
206 'item 2' => [],
207 'item 3' => []
210 'userpage set, notification defined, user interface preferences set' => [
211 'contentNavigation' => [
212 'notifications' => [
213 'notification 1' => []
215 'user-menu' => [
216 'item 1' => [],
217 'userpage' => [],
218 'item 2' => [],
219 'item 3' => []
221 'user-interface-preferences' => [
222 'uls' => [],
225 'expected' => [
226 'uls' => [],
227 'item 1' => [],
228 'userpage' => [],
229 'notification 1' => [],
230 'item 2' => [],
231 'item 3' => []
234 'no userpage, no notifications, no user-interface-preferences' => [
235 'contentNavigation' => [
236 'user-menu' => [
237 'item 1' => [],
238 'item 2' => [],
239 'item 3' => []
242 'expected' => [
243 'item 1' => [],
244 'item 2' => [],
245 'item 3' => []
251 public function testGenerateHTML() {
252 $wrapper = TestingAccessWrapper::newFromObject(
253 new SkinTemplate( [ 'template' => 'SkinQuickTemplateTest', 'name' => 'test' ] )
256 $wrapper->getContext()->setTitle( Title::makeTitle( NS_MAIN, 'PrepareQuickTemplateTest' ) );
257 $tpl = $wrapper->prepareQuickTemplate();
258 $contentNav = $tpl->get( 'content_navigation' );
260 $this->assertEquals( [ 'namespaces', 'views', 'actions', 'variants' ], array_keys( $contentNav ) );