| 1 |
<?php |
| 2 |
|
| 3 |
use MediaWiki\MainConfigNames; |
| 4 |
use MediaWiki\Title\Title; |
| 5 |
use Wikimedia\TestingAccessWrapper; |
| 6 |
|
| 7 |
|
| 8 |
class SkinQuickTemplateTest extends QuickTemplate { |
| 9 |
public function execute() { |
| 10 |
} |
| 11 |
} |
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
class SkinTemplateTest extends MediaWikiIntegrationTestCase { |
| 21 |
|
| 22 |
|
| 23 |
|
| 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 |
] ) ); |
| 30 |
|
| 31 |
$this->assertEquals( |
| 32 |
$expected, |
| 33 |
$template->makeListItem( $key, $item, $options ), |
| 34 |
$message |
| 35 |
); |
| 36 |
} |
| 37 |
|
| 38 |
public static function makeListItemProvider() { |
| 39 |
return [ |
| 40 |
[ |
| 41 |
'<li class="class mw-list-item" title="itemtitle"><a href="url" title="title">text</a></li>', |
| 42 |
'', |
| 43 |
[ |
| 44 |
'class' => 'class', |
| 45 |
'itemtitle' => 'itemtitle', |
| 46 |
'href' => 'url', |
| 47 |
'title' => 'title', |
| 48 |
'text' => 'text' |
| 49 |
], |
| 50 |
[], |
| 51 |
'Test makeListItem with normal values' |
| 52 |
] |
| 53 |
]; |
| 54 |
} |
| 55 |
|
| 56 |
public static function provideGetFooterIcons() { |
| 57 |
return [ |
| 58 |
|
| 59 |
[ |
| 60 |
[ |
| 61 |
MainConfigNames::FooterIcons => [], |
| 62 |
], |
| 63 |
[], |
| 64 |
'Empty list' |
| 65 |
], |
| 66 |
|
| 67 |
[ |
| 68 |
[ |
| 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', |
| 77 |
] |
| 78 |
] |
| 79 |
], |
| 80 |
], |
| 81 |
[ |
| 82 |
'poweredby' => [ |
| 83 |
[ |
| 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, |
| 91 |
] |
| 92 |
] |
| 93 |
], |
| 94 |
'Width and height are hardcoded if not provided' |
| 95 |
], |
| 96 |
|
| 97 |
[ |
| 98 |
[ |
| 99 |
MainConfigNames::FooterIcons => [ |
| 100 |
'copyright' => [ |
| 101 |
'copyright' => [], |
| 102 |
], |
| 103 |
], |
| 104 |
], |
| 105 |
[], |
| 106 |
'Empty arrays are filtered out' |
| 107 |
], |
| 108 |
|
| 109 |
[ |
| 110 |
[ |
| 111 |
MainConfigNames::FooterIcons => [ |
| 112 |
'copyright' => [ |
| 113 |
'copyright' => [ |
| 114 |
'alt' => 'Wikimedia Foundation', |
| 115 |
'url' => 'https://wikimediafoundation.org' |
| 116 |
], |
| 117 |
], |
| 118 |
], |
| 119 |
], |
| 120 |
[], |
| 121 |
'Icons with no icon are filtered out' |
| 122 |
] |
| 123 |
]; |
| 124 |
} |
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
public function testGetFooterIcons( $globals, $expected, $msg ) { |
| 130 |
$this->overrideConfigValues( $globals ); |
| 131 |
$wrapper = TestingAccessWrapper::newFromObject( new SkinTemplate() ); |
| 132 |
$icons = $wrapper->getFooterIcons(); |
| 133 |
|
| 134 |
$this->assertEquals( $expected, $icons, $msg ); |
| 135 |
} |
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
public function testInjectLegacyMenusIntoPersonalTools( |
| 143 |
array $contentNavigation, |
| 144 |
array $expected |
| 145 |
) { |
| 146 |
$wrapper = TestingAccessWrapper::newFromObject( new SkinTemplate() ); |
| 147 |
|
| 148 |
$this->assertEquals( |
| 149 |
$expected, |
| 150 |
$wrapper->injectLegacyMenusIntoPersonalTools( $contentNavigation ) |
| 151 |
); |
| 152 |
} |
| 153 |
|
| 154 |
public static function provideContentNavigation(): array { |
| 155 |
return [ |
| 156 |
'No userpage set' => [ |
| 157 |
'contentNavigation' => [ |
| 158 |
'notifications' => [ |
| 159 |
'notification 1' => [] |
| 160 |
], |
| 161 |
'user-menu' => [ |
| 162 |
'item 1' => [], |
| 163 |
'item 2' => [], |
| 164 |
'item 3' => [] |
| 165 |
] |
| 166 |
], |
| 167 |
'expected' => [ |
| 168 |
'item 1' => [], |
| 169 |
'item 2' => [], |
| 170 |
'item 3' => [] |
| 171 |
] |
| 172 |
], |
| 173 |
'userpage set, no notifications' => [ |
| 174 |
'contentNavigation' => [ |
| 175 |
'notifications' => [], |
| 176 |
'user-menu' => [ |
| 177 |
'item 1' => [], |
| 178 |
'userpage' => [], |
| 179 |
'item 2' => [], |
| 180 |
'item 3' => [] |
| 181 |
] |
| 182 |
], |
| 183 |
'expected' => [ |
| 184 |
'item 1' => [], |
| 185 |
'userpage' => [], |
| 186 |
'item 2' => [], |
| 187 |
'item 3' => [] |
| 188 |
] |
| 189 |
], |
| 190 |
'userpage set, notification defined' => [ |
| 191 |
'contentNavigation' => [ |
| 192 |
'notifications' => [ |
| 193 |
'notification 1' => [] |
| 194 |
], |
| 195 |
'user-menu' => [ |
| 196 |
'item 1' => [], |
| 197 |
'userpage' => [], |
| 198 |
'item 2' => [], |
| 199 |
'item 3' => [] |
| 200 |
] |
| 201 |
], |
| 202 |
'expected' => [ |
| 203 |
'item 1' => [], |
| 204 |
'userpage' => [], |
| 205 |
'notification 1' => [], |
| 206 |
'item 2' => [], |
| 207 |
'item 3' => [] |
| 208 |
] |
| 209 |
], |
| 210 |
'userpage set, notification defined, user interface preferences set' => [ |
| 211 |
'contentNavigation' => [ |
| 212 |
'notifications' => [ |
| 213 |
'notification 1' => [] |
| 214 |
], |
| 215 |
'user-menu' => [ |
| 216 |
'item 1' => [], |
| 217 |
'userpage' => [], |
| 218 |
'item 2' => [], |
| 219 |
'item 3' => [] |
| 220 |
], |
| 221 |
'user-interface-preferences' => [ |
| 222 |
'uls' => [], |
| 223 |
], |
| 224 |
], |
| 225 |
'expected' => [ |
| 226 |
'uls' => [], |
| 227 |
'item 1' => [], |
| 228 |
'userpage' => [], |
| 229 |
'notification 1' => [], |
| 230 |
'item 2' => [], |
| 231 |
'item 3' => [] |
| 232 |
] |
| 233 |
], |
| 234 |
'no userpage, no notifications, no user-interface-preferences' => [ |
| 235 |
'contentNavigation' => [ |
| 236 |
'user-menu' => [ |
| 237 |
'item 1' => [], |
| 238 |
'item 2' => [], |
| 239 |
'item 3' => [] |
| 240 |
], |
| 241 |
], |
| 242 |
'expected' => [ |
| 243 |
'item 1' => [], |
| 244 |
'item 2' => [], |
| 245 |
'item 3' => [] |
| 246 |
] |
| 247 |
] |
| 248 |
]; |
| 249 |
} |
| 250 |
|
| 251 |
public function testGenerateHTML() { |
| 252 |
$wrapper = TestingAccessWrapper::newFromObject( |
| 253 |
new SkinTemplate( [ 'template' => 'SkinQuickTemplateTest', 'name' => 'test' ] ) |
| 254 |
); |
| 255 |
|
| 256 |
$wrapper->getContext()->setTitle( Title::makeTitle( NS_MAIN, 'PrepareQuickTemplateTest' ) ); |
| 257 |
$tpl = $wrapper->prepareQuickTemplate(); |
| 258 |
$contentNav = $tpl->get( 'content_navigation' ); |
| 259 |
|
| 260 |
$this->assertEquals( [ 'namespaces', 'views', 'actions', 'variants' ], array_keys( $contentNav ) ); |
| 261 |
} |
| 262 |
} |