mediawiki-skins-MinervaNeue/tests/phpunit/skins/SkinMinervaTest.php

149 lines
4 KiB
PHP
Raw Normal View History

<?php
namespace Tests\MediaWiki\Minerva;
use MediaWiki\Minerva\SkinOptions;
use MediaWikiTestCase;
use OutputPage;
use RequestContext;
use SkinMinerva;
use Title;
use Wikimedia\TestingAccessWrapper;
/**
* @coversDefaultClass SkinMinerva
* @group MinervaNeue
*/
class SkinMinervaTest extends MediaWikiTestCase {
const OPTIONS_MODULE = 'skins.minerva.options';
private function overrideSkinOptions( $options ) {
$mockOptions = new SkinOptions();
$mockOptions->setMultiple( $options );
$this->setService( 'Minerva.SkinOptions', $mockOptions );
}
/**
* @covers ::setContext
* @covers ::hasCategoryLinks
*/
public function testHasCategoryLinksWhenOptionIsOff() {
$outputPage = $this->getMockBuilder( OutputPage::class )
->disableOriginalConstructor()
->getMock();
$outputPage->expects( $this->never() )
->method( 'getCategoryLinks' );
$this->overrideSkinOptions( [ SkinOptions::CATEGORIES => false ] );
$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
* @covers ::hasCategoryLinks
*/
public function testHasCategoryLinks( array $categoryLinks, $expected ) {
$outputPage = $this->getMockBuilder( OutputPage::class )
->disableOriginalConstructor()
->getMock();
$outputPage->expects( $this->once() )
->method( 'getCategoryLinks' )
->will( $this->returnValue( $categoryLinks ) );
$this->overrideSkinOptions( [ SkinOptions::CATEGORIES => true ] );
$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
],
];
}
/**
* Test whether the font changer module is correctly added to the list context modules
*
* @covers ::getContextSpecificModules
* @dataProvider provideGetContextSpecificModules
* @param mixed $categoryLinks whether category link feature is enabled
* @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
*/
public function testGetContextSpecificModules( $categoryLinks, $moduleName, $expected ) {
$this->overrideSkinOptions( [
SkinOptions::TALK_AT_TOP => false,
SkinOptions::HISTORY_IN_PAGE_ACTIONS => false,
SkinOptions::TOOLBAR_SUBMENU => false,
Feature flag overhaul Two new feature flags: 1) MinervaPersonalMenu 2) MinervaAdvancedMainMenu Changes: * AMC defaults to false on desktop - desktop doesn't have AMC mode it just enables several skin options. * WHen inserting a link at the bottom of the page check whether the talk at top of the page (tabs) is enabled.. not AMC * Update ServiceWiring to construct menu based on MinervaAdvancedMainMenu and MinervaPersonalMenu - note when former is enabled but not latter there is no way to logout. Noted in README. * Use one entry point for skins.minerva.amc.styles/index.less * Document files inside skins.minerva.amc.styles to make it clear which features they are associated with * Drop history page styles when AMC is disabled - it's not possible to ever get to these as the history page redirects in non-AMC mode * Rename the class .minerva--amc-enabled to minerva--history-page-action-enabled to reflect its real purpose and move styles from skins.minerva.base.styles to skins.minerva.amc.styles No need to worry about cached HTML as AMC runs without cache... * Remove isAnyAMCOptionEnabled - it's an antipattern and should be discouraged as it discourages the art of feature flagging. Nothing is using it after these changes. * The AMC_MODE flag is disabled. There is no need for this - AMC is not a feature and therefore not a skin option. It is a mechanism for turning on other skin options. Tests are updated. Testing: It should now be possible to enable any feature in `beta` and see it in the beta of the site. Bug: T229295 Change-Id: I48959905f5c09721b14a27aa1a5ad82849ac6263
2019-08-22 20:31:31 +00:00
SkinOptions::MAIN_MENU_EXPANDED => false,
SkinOptions::PERSONAL_MENU => false,
SkinOptions::CATEGORIES => $categoryLinks,
] );
$skin = new SkinMinerva();
$title = Title::newFromText( 'Test' );
$testContext = RequestContext::getMain();
$testContext->setTitle( $title );
$skin->setContext( $testContext );
if ( $expected ) {
$this->assertContains( $moduleName, $skin->getContextSpecificModules() );
} else {
$this->assertNotContains( $moduleName, $skin->getContextSpecificModules() );
}
}
public function provideGetContextSpecificModules() {
return [
[ true, self::OPTIONS_MODULE, true ],
[ false, self::OPTIONS_MODULE, false ],
];
}
}