mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/Vector.git
synced 2024-12-13 16:38:44 +00:00
411f9ce69a
Currently only features that are associated with LocalSettings configuration can be overriden by query string. Going forward we'd like to expand this to apply to user preference too. A generic OverrideableRequirement is created. The existing OverridableConfigRequirement is refactored to extend OverrideableRequirement The /UserPreferenceRequirement now extends it This allows http://localhost:8888/wiki/Spain?vectortypographysurvey=1 to work Bug: T347900 Change-Id: I11efd6b07192d5d2333f4506e9d87a8c0638d657
106 lines
2.1 KiB
PHP
106 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace MediaWiki\Skins\Vector\Tests\Unit\FeatureManagement\Requirements;
|
|
|
|
use FauxRequest;
|
|
use MediaWiki\Skins\Vector\FeatureManagement\Requirements\UserPreferenceRequirement;
|
|
use MediaWiki\Title\Title;
|
|
use MediaWiki\User\UserOptionsLookup;
|
|
use User;
|
|
|
|
/**
|
|
* @group Vector
|
|
* @group FeatureManagement
|
|
* @coversDefaultClass \MediaWiki\Skins\Vector\FeatureManagement\Requirements\UserPreferenceRequirement
|
|
*/
|
|
final class UserPreferenceRequirementTest extends \MediaWikiUnitTestCase {
|
|
public static function providerTestIsMetRequirement() {
|
|
return [
|
|
[
|
|
// Is option enabled?
|
|
1,
|
|
// Is title present?
|
|
true,
|
|
// Expected
|
|
true,
|
|
'If enabled, returns true'
|
|
],
|
|
[
|
|
// Is option enabled?
|
|
0,
|
|
// Is title present?
|
|
true,
|
|
// Expected
|
|
false,
|
|
'If disabled, returns false'
|
|
],
|
|
[
|
|
// Is option enabled?
|
|
'enabled',
|
|
// Is title present?
|
|
false,
|
|
// Expected
|
|
false,
|
|
'If enabled but title null, returns false'
|
|
],
|
|
[
|
|
'disabled',
|
|
// Is title present?
|
|
true,
|
|
// Expected
|
|
false,
|
|
'If disabled, returns false'
|
|
],
|
|
[
|
|
'0',
|
|
// Is title present?
|
|
true,
|
|
// Expected
|
|
false,
|
|
'If disabled, returns false'
|
|
],
|
|
[
|
|
'medium',
|
|
// Is title present?
|
|
true,
|
|
// Expected
|
|
true,
|
|
'If unrecognized string returns true'
|
|
],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @covers ::isMet
|
|
* @dataProvider providerTestIsMetRequirement
|
|
* @param bool $isEnabled
|
|
* @param bool $isTitlePresent
|
|
* @param bool $expected
|
|
* @param string $msg
|
|
*/
|
|
public function testIsMetRequirement(
|
|
$isEnabled,
|
|
$isTitlePresent,
|
|
$expected,
|
|
$msg
|
|
) {
|
|
$user = $this->createMock( User::class );
|
|
$title = $isTitlePresent ? $this->createMock( Title::class ) : null;
|
|
$request = new FauxRequest();
|
|
|
|
$userOptionsLookup = $this->createMock( UserOptionsLookup::class );
|
|
$userOptionsLookup->method( 'getOption' )->willReturn( $isEnabled );
|
|
|
|
$requirement = new UserPreferenceRequirement(
|
|
$user,
|
|
$userOptionsLookup,
|
|
'userOption',
|
|
'userRequirement',
|
|
$request,
|
|
$title
|
|
);
|
|
|
|
$this->assertSame( $expected, $requirement->isMet(), $msg );
|
|
}
|
|
}
|