mediawiki-skins-MinervaNeue/tests/phpunit/unit/SkinOptionsTest.php

79 lines
2.1 KiB
PHP
Raw Normal View History

<?php
namespace MediaWiki\Minerva;
use MediaWiki\HookContainer\HookContainer;
use MediaWiki\Minerva\Skins\SkinUserPageHelper;
use MediaWikiUnitTestCase;
use OutOfBoundsException;
/**
* @package Tests\MediaWiki\Minerva
* @group MinervaNeue
* @coversDefaultClass \MediaWiki\Minerva\SkinOptions
*/
class SkinOptionsTest extends MediaWikiUnitTestCase {
private function newSkinOptions(): SkinOptions {
return new SkinOptions(
$this->createMock( HookContainer::class ),
$this->createMock( SkinUserPageHelper::class )
);
}
/**
* @covers ::get
* @covers ::getAll
* @covers ::setMultiple
*/
public function testSettersAndGetters() {
$options = $this->newSkinOptions();
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
$defaultValue = $options->get( SkinOptions::BETA_MODE );
$options->setMultiple( [ SkinOptions::BETA_MODE => !$defaultValue ] );
$allOptions = $options->getAll();
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
$this->assertEquals( !$defaultValue, $options->get( SkinOptions::BETA_MODE ) );
$this->assertArrayHasKey( SkinOptions::BETA_MODE, $allOptions );
$this->assertEquals( !$defaultValue, $allOptions[ SkinOptions::BETA_MODE ] );
}
/**
* @covers ::hasSkinOptions
*/
public function testHasSkinOptions() {
$options = $this->newSkinOptions();
$this->assertTrue( $options->hasSkinOptions() );
$options->setMultiple( [
SkinOptions::SHOW_DONATE => false,
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::TABS_ON_SPECIALS => false,
] );
$this->assertFalse( $options->hasSkinOptions() );
}
/**
* @covers ::get
*/
public function testGettingUnknownKeyShouldThrowException() {
$options = $this->newSkinOptions();
$this->expectException( OutOfBoundsException::class );
$options->get( 'non_existing_key' );
}
/**
* @covers ::get
*/
public function testSettingUnknownKeyShouldThrowException() {
$options = $this->newSkinOptions();
$this->expectException( OutOfBoundsException::class );
$options->setMultiple( [
'non_existing_key' => 1
] );
}
}