2024-03-26 22:02:43 +00:00
|
|
|
<?php
|
|
|
|
|
2024-05-07 07:01:55 +00:00
|
|
|
use MediaWiki\Context\RequestContext;
|
2024-03-26 22:02:43 +00:00
|
|
|
use MediaWiki\Skins\Vector\Constants;
|
|
|
|
use MediaWiki\Skins\Vector\FeatureManagement\FeatureManager;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @coversDefaultClass \MediaWiki\Skins\Vector\FeatureManagement\FeatureManager
|
|
|
|
*/
|
|
|
|
class FeatureManagerTest extends \MediaWikiIntegrationTestCase {
|
2024-05-06 19:59:33 +00:00
|
|
|
private function newFeatureManager(): FeatureManager {
|
|
|
|
return new FeatureManager(
|
2024-05-07 07:01:55 +00:00
|
|
|
$this->getServiceContainer()->getUserOptionsLookup(),
|
|
|
|
RequestContext::getMain()
|
2024-05-06 19:59:33 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-03-26 22:02:43 +00:00
|
|
|
public static function provideGetFeatureBodyClass() {
|
|
|
|
return [
|
|
|
|
[ CONSTANTS::FEATURE_LIMITED_WIDTH, false, 'vector-feature-limited-width-clientpref-0' ],
|
|
|
|
[ CONSTANTS::FEATURE_LIMITED_WIDTH, true, 'vector-feature-limited-width-clientpref-1' ],
|
|
|
|
[ CONSTANTS::FEATURE_TOC_PINNED, false, 'vector-feature-toc-pinned-clientpref-0' ],
|
|
|
|
[ CONSTANTS::FEATURE_TOC_PINNED, true, 'vector-feature-toc-pinned-clientpref-1' ],
|
|
|
|
[ 'default', false, 'vector-feature-default-disabled' ],
|
|
|
|
[ 'default', true, 'vector-feature-default-enabled' ],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider provideGetFeatureBodyClass
|
|
|
|
* @covers ::getFeatureBodyClass basic usage
|
|
|
|
*/
|
|
|
|
public function testGetFeatureBodyClass( $feature, $enabled, $expected ) {
|
2024-05-06 19:59:33 +00:00
|
|
|
$featureManager = $this->newFeatureManager();
|
2024-03-26 22:02:43 +00:00
|
|
|
$featureManager->registerSimpleRequirement( 'requirement', $enabled );
|
|
|
|
$featureManager->registerFeature( $feature, [ 'requirement' ] );
|
2024-05-06 16:13:00 +00:00
|
|
|
// Title is required for checking whether or not the feature is excluded
|
|
|
|
// based on page title.
|
|
|
|
$context = RequestContext::getMain();
|
2024-05-10 19:25:42 +00:00
|
|
|
$context->setTitle( Title::makeTitle( NS_MAIN, 'test' ) );
|
2024-03-26 22:02:43 +00:00
|
|
|
$this->assertSame( [ $expected ], $featureManager->getFeatureBodyClass() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers ::getFeatureBodyClass returning multiple feature classes
|
|
|
|
*/
|
|
|
|
public function testGetFeatureBodyClassMultiple() {
|
2024-05-06 19:59:33 +00:00
|
|
|
$featureManager = $this->newFeatureManager();
|
2024-03-26 22:02:43 +00:00
|
|
|
$featureManager->registerSimpleRequirement( 'requirement', true );
|
|
|
|
$featureManager->registerSimpleRequirement( 'disabled', false );
|
|
|
|
$featureManager->registerFeature( 'sticky-header', [ 'requirement' ] );
|
|
|
|
$featureManager->registerFeature( 'TableOfContents', [ 'requirement' ] );
|
|
|
|
$featureManager->registerFeature( 'Test', [ 'disabled' ] );
|
|
|
|
$this->assertEquals(
|
|
|
|
[
|
|
|
|
'vector-feature-sticky-header-enabled',
|
|
|
|
'vector-feature-table-of-contents-enabled',
|
|
|
|
'vector-feature-test-disabled'
|
|
|
|
],
|
|
|
|
$featureManager->getFeatureBodyClass()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function provideGetFeatureBodyClassNightModeQueryParam() {
|
|
|
|
return [
|
|
|
|
[ 0, 'skin-theme-clientpref-day' ],
|
|
|
|
[ 1, 'skin-theme-clientpref-night' ],
|
|
|
|
[ 2, 'skin-theme-clientpref-os' ],
|
|
|
|
[ 'day', 'skin-theme-clientpref-day' ],
|
|
|
|
[ 'night', 'skin-theme-clientpref-night' ],
|
|
|
|
[ 'os', 'skin-theme-clientpref-os' ],
|
|
|
|
[ 'invalid', 'skin-theme-clientpref-day' ]
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider provideGetFeatureBodyClassNightModeQueryParam
|
|
|
|
* @covers ::getFeatureBodyClass pref night mode specifics - disabled pages
|
|
|
|
*/
|
|
|
|
public function testGetFeatureBodyClassNightModeQueryParam( $value, $expected ) {
|
2024-05-06 19:59:33 +00:00
|
|
|
$featureManager = $this->newFeatureManager();
|
2024-03-26 22:02:43 +00:00
|
|
|
$featureManager->registerFeature( CONSTANTS::PREF_NIGHT_MODE, [] );
|
|
|
|
|
|
|
|
$context = RequestContext::getMain();
|
|
|
|
$context->setTitle( Title::makeTitle( NS_MAIN, 'test' ) );
|
|
|
|
|
|
|
|
$request = $context->getRequest();
|
|
|
|
$request->setVal( 'vectornightmode', $value );
|
|
|
|
|
|
|
|
$this->assertEquals( [ $expected ], $featureManager->getFeatureBodyClass() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/** ensure the class is present when disabled and absent when not */
|
2024-05-22 16:58:32 +00:00
|
|
|
public static function provideGetFeatureBodyClassNightModeDisabled() {
|
2024-03-26 22:02:43 +00:00
|
|
|
return [
|
|
|
|
[ true ], [ false ]
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2024-05-22 16:58:32 +00:00
|
|
|
* @dataProvider provideGetFeatureBodyClassNightModeDisabled
|
2024-03-26 22:02:43 +00:00
|
|
|
* @covers ::getFeatureBodyClass pref night mode specifics - disabled pages
|
|
|
|
*/
|
2024-05-22 16:58:32 +00:00
|
|
|
public function testGetFeatureBodyClassNightModeDisabled( $disabled ) {
|
2024-05-06 19:59:33 +00:00
|
|
|
$featureManager = $this->newFeatureManager();
|
2024-03-26 22:02:43 +00:00
|
|
|
$featureManager->registerFeature( CONSTANTS::PREF_NIGHT_MODE, [] );
|
|
|
|
|
|
|
|
$context = RequestContext::getMain();
|
|
|
|
$context->setTitle( Title::makeTitle( NS_MAIN, 'Main Page' ) );
|
|
|
|
|
|
|
|
$this->overrideConfigValues( [ 'VectorNightModeOptions' => [ 'exclude' => [ 'mainpage' => $disabled ] ] ] );
|
|
|
|
$this->assertEquals(
|
2024-05-22 16:58:32 +00:00
|
|
|
in_array( 'skin-theme-clientpref--excluded', $featureManager->getFeatureBodyClass() ),
|
2024-03-26 22:02:43 +00:00
|
|
|
$disabled
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|