2017-07-12 15:12:40 +00:00
|
|
|
<?php
|
|
|
|
|
2017-07-14 23:56:16 +00:00
|
|
|
namespace Tests\MediaWiki\Minerva;
|
2017-07-12 15:12:40 +00:00
|
|
|
|
2019-11-18 22:12:11 +00:00
|
|
|
use HashConfig;
|
2019-04-10 21:43:50 +00:00
|
|
|
use MediaWiki\Minerva\SkinOptions;
|
2017-07-12 15:12:40 +00:00
|
|
|
use MediaWikiTestCase;
|
|
|
|
use OutputPage;
|
|
|
|
use RequestContext;
|
|
|
|
use SkinMinerva;
|
|
|
|
use Title;
|
|
|
|
use Wikimedia\TestingAccessWrapper;
|
|
|
|
|
|
|
|
/**
|
2017-07-17 20:34:47 +00:00
|
|
|
* @coversDefaultClass SkinMinerva
|
2017-07-14 23:56:16 +00:00
|
|
|
* @group MinervaNeue
|
2017-07-12 15:12:40 +00:00
|
|
|
*/
|
|
|
|
class SkinMinervaTest extends MediaWikiTestCase {
|
2020-05-19 22:43:34 +00:00
|
|
|
private const OPTIONS_MODULE = 'skins.minerva.options';
|
2017-07-12 15:12:40 +00:00
|
|
|
|
2019-04-10 21:43:50 +00:00
|
|
|
private function overrideSkinOptions( $options ) {
|
|
|
|
$mockOptions = new SkinOptions();
|
|
|
|
$mockOptions->setMultiple( $options );
|
|
|
|
$this->setService( 'Minerva.SkinOptions', $mockOptions );
|
2017-07-12 15:12:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers ::setContext
|
|
|
|
* @covers ::hasCategoryLinks
|
|
|
|
*/
|
|
|
|
public function testHasCategoryLinksWhenOptionIsOff() {
|
|
|
|
$outputPage = $this->getMockBuilder( OutputPage::class )
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
$outputPage->expects( $this->never() )
|
|
|
|
->method( 'getCategoryLinks' );
|
|
|
|
|
2019-08-01 16:18:18 +00:00
|
|
|
$this->overrideSkinOptions( [ SkinOptions::CATEGORIES => false ] );
|
2017-07-12 15:12:40 +00:00
|
|
|
$context = new RequestContext();
|
|
|
|
$context->setTitle( Title::newFromText( 'Test' ) );
|
|
|
|
$context->setOutput( $outputPage );
|
|
|
|
|
|
|
|
$skin = new SkinMinerva();
|
|
|
|
$skin->setContext( $context );
|
|
|
|
$skin = TestingAccessWrapper::newFromObject( $skin );
|
|
|
|
|
|
|
|
$this->assertEquals( $skin->hasCategoryLinks(), false );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider provideHasCategoryLinks
|
|
|
|
* @param array $categoryLinks
|
|
|
|
* @param bool $expected
|
|
|
|
* @covers ::setContext
|
2017-12-29 20:26:59 +00:00
|
|
|
* @covers ::hasCategoryLinks
|
2017-07-12 15:12:40 +00:00
|
|
|
*/
|
|
|
|
public function testHasCategoryLinks( array $categoryLinks, $expected ) {
|
|
|
|
$outputPage = $this->getMockBuilder( OutputPage::class )
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
$outputPage->expects( $this->once() )
|
|
|
|
->method( 'getCategoryLinks' )
|
|
|
|
->will( $this->returnValue( $categoryLinks ) );
|
|
|
|
|
2019-08-01 16:18:18 +00:00
|
|
|
$this->overrideSkinOptions( [ SkinOptions::CATEGORIES => true ] );
|
2019-04-10 21:43:50 +00:00
|
|
|
|
2017-07-12 15:12:40 +00:00
|
|
|
$context = new RequestContext();
|
|
|
|
$context->setTitle( Title::newFromText( 'Test' ) );
|
|
|
|
$context->setOutput( $outputPage );
|
|
|
|
|
|
|
|
$skin = new SkinMinerva();
|
|
|
|
$skin->setContext( $context );
|
|
|
|
|
|
|
|
$skin = TestingAccessWrapper::newFromObject( $skin );
|
|
|
|
|
|
|
|
$this->assertEquals( $skin->hasCategoryLinks(), $expected );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function provideHasCategoryLinks() {
|
|
|
|
return [
|
|
|
|
[ [], false ],
|
|
|
|
[
|
|
|
|
[
|
|
|
|
'normal' => '<ul><li><a href="/wiki/Category:1">1</a></li></ul>'
|
|
|
|
],
|
|
|
|
true
|
|
|
|
],
|
|
|
|
[
|
|
|
|
[
|
|
|
|
'hidden' => '<ul><li><a href="/wiki/Category:Hidden">Hidden</a></li></ul>'
|
|
|
|
],
|
|
|
|
true
|
|
|
|
],
|
|
|
|
[
|
|
|
|
[
|
|
|
|
'normal' => '<ul><li><a href="/wiki/Category:1">1</a></li></ul>',
|
|
|
|
'hidden' => '<ul><li><a href="/wiki/Category:Hidden">Hidden</a></li></ul>'
|
|
|
|
],
|
|
|
|
true
|
|
|
|
],
|
|
|
|
[
|
|
|
|
[
|
|
|
|
'unexpected' => '<ul><li><a href="/wiki/Category:1">1</a></li></ul>'
|
|
|
|
],
|
|
|
|
false
|
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-11-18 22:12:11 +00:00
|
|
|
* Test whether the font changer module is correctly added to the list context modules.
|
2017-07-12 15:12:40 +00:00
|
|
|
*
|
|
|
|
* @covers ::getContextSpecificModules
|
|
|
|
* @dataProvider provideGetContextSpecificModules
|
2019-11-08 06:28:52 +00:00
|
|
|
* @param mixed $categoryLinks whether category link feature is enabled
|
2017-07-12 15:12:40 +00:00
|
|
|
* @param string $moduleName Module name that is being tested
|
|
|
|
* @param bool $expected Whether the module is expected to be returned by the function being tested
|
|
|
|
*/
|
2019-11-08 06:28:52 +00:00
|
|
|
public function testGetContextSpecificModules( $categoryLinks, $moduleName, $expected ) {
|
2019-04-10 21:43:50 +00:00
|
|
|
$this->overrideSkinOptions( [
|
2019-07-30 00:24:23 +00:00
|
|
|
SkinOptions::TALK_AT_TOP => false,
|
|
|
|
SkinOptions::HISTORY_IN_PAGE_ACTIONS => false,
|
|
|
|
SkinOptions::TOOLBAR_SUBMENU => false,
|
2019-08-22 20:31:31 +00:00
|
|
|
SkinOptions::MAIN_MENU_EXPANDED => false,
|
|
|
|
SkinOptions::PERSONAL_MENU => false,
|
2019-11-08 06:28:52 +00:00
|
|
|
SkinOptions::CATEGORIES => $categoryLinks,
|
2019-03-29 21:31:09 +00:00
|
|
|
] );
|
2019-04-10 21:43:50 +00:00
|
|
|
|
|
|
|
$skin = new SkinMinerva();
|
2017-07-12 15:12:40 +00:00
|
|
|
$title = Title::newFromText( 'Test' );
|
2017-07-17 19:34:45 +00:00
|
|
|
$testContext = RequestContext::getMain();
|
|
|
|
$testContext->setTitle( $title );
|
2017-07-12 15:12:40 +00:00
|
|
|
|
2017-07-17 19:49:49 +00:00
|
|
|
$skin->setContext( $testContext );
|
2017-07-12 15:12:40 +00:00
|
|
|
|
|
|
|
if ( $expected ) {
|
|
|
|
$this->assertContains( $moduleName, $skin->getContextSpecificModules() );
|
|
|
|
} else {
|
|
|
|
$this->assertNotContains( $moduleName, $skin->getContextSpecificModules() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function provideGetContextSpecificModules() {
|
|
|
|
return [
|
2018-09-26 23:03:20 +00:00
|
|
|
[ true, self::OPTIONS_MODULE, true ],
|
|
|
|
[ false, self::OPTIONS_MODULE, false ],
|
2017-07-12 15:12:40 +00:00
|
|
|
];
|
|
|
|
}
|
2019-11-18 22:12:11 +00:00
|
|
|
|
|
|
|
public function provideGetSitename() {
|
|
|
|
return [
|
|
|
|
[
|
|
|
|
[
|
|
|
|
'Logos' => false,
|
|
|
|
'Logo' => '/logo.svg',
|
|
|
|
],
|
|
|
|
'(mobile-frontend-footer-sitename)',
|
2020-02-20 23:25:37 +00:00
|
|
|
'No wgLogos defined.'
|
2019-11-18 22:12:11 +00:00
|
|
|
],
|
|
|
|
[
|
|
|
|
[
|
|
|
|
'Logos' => [
|
|
|
|
'1x' => '/logo.svg',
|
|
|
|
'wordmark' => [
|
|
|
|
'src' => '/wordmark.svg',
|
|
|
|
'width' => '10',
|
|
|
|
'height' => '10',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
],
|
|
|
|
'<img src="/wordmark.svg" width="10" height="10" alt="(mobile-frontend-footer-sitename)"/>',
|
|
|
|
'wgLogos used.'
|
|
|
|
],
|
|
|
|
[
|
|
|
|
[
|
|
|
|
'Logos' => [
|
|
|
|
'1x' => '/logo.svg',
|
|
|
|
'wordmark' => [
|
|
|
|
'src' => '/wordmark.png',
|
|
|
|
'1x' => '/wordmark.svg',
|
|
|
|
'width' => '10',
|
|
|
|
'height' => '10',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
],
|
|
|
|
'<img src="/wordmark.png" width="10" height="10" '
|
|
|
|
. 'alt="(mobile-frontend-footer-sitename)" srcset="/wordmark.svg 1x"/>',
|
|
|
|
'wgLogos used with `png` and `svg`.'
|
|
|
|
]
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test whether the font changer module is correctly added to the list context modules
|
|
|
|
*
|
|
|
|
* @covers ::getSitename
|
|
|
|
* @dataProvider provideGetSitename
|
|
|
|
*/
|
|
|
|
public function testGetSitename( $configData, $expected, $msg ) {
|
|
|
|
$skin = new SkinMinerva();
|
|
|
|
$config = new HashConfig( $configData );
|
|
|
|
$context = new RequestContext();
|
|
|
|
$context->setLanguage( 'qqx' );
|
|
|
|
$context->setConfig( $config );
|
|
|
|
$skin->setContext( $context );
|
|
|
|
|
|
|
|
// See T236778
|
|
|
|
$this->setMwGlobals( [
|
|
|
|
'wgDevelopmentWarnings' => false
|
|
|
|
] );
|
|
|
|
|
|
|
|
$sitename = $skin->getSitename();
|
|
|
|
$this->assertEquals( $sitename, $expected, $msg );
|
|
|
|
}
|
2017-07-12 15:12:40 +00:00
|
|
|
}
|