mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/Vector.git
synced 2024-12-04 20:18:57 +00:00
7e0dd79d5a
Generalize LimitedWidthRequirement into a more reusable
UserPreferenceRequirement that can be used by both the limited width feature and
the persistent pinning feature (and possibly others in the future).
* Removes existing logic that checks whether the option is not null. Given that
skin.json sets the default [1], presumably this isn't needed.
* Adds unit test
[1] 65af26a258/skin.json (L163)
Bug: T322051
Change-Id: I7f228cf81a65b2eb22dbe94d2384b6c9f6da91f2
80 lines
1.7 KiB
PHP
80 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace MediaWiki\Skins\Vector\Tests\Unit\FeatureManagement\Requirements;
|
|
|
|
use MediaWiki\Skins\Vector\FeatureManagement\Requirements\UserPreferenceRequirement;
|
|
use MediaWiki\User\UserOptionsLookup;
|
|
use Title;
|
|
use User;
|
|
|
|
/**
|
|
* @group Vector
|
|
* @group FeatureManagement
|
|
* @coversDefaultClass \MediaWiki\Skins\Vector\FeatureManagement\Requirements\UserPreferenceRequirement
|
|
*/
|
|
final class UserPreferenceRequirementTest extends \MediaWikiUnitTestCase {
|
|
public function providerTestIsMetRequirement() {
|
|
return [
|
|
[
|
|
// Is option enabled?
|
|
true,
|
|
// Is title present?
|
|
true,
|
|
// Expected
|
|
true,
|
|
'If enabled, returns true'
|
|
],
|
|
[
|
|
// Is option enabled?
|
|
false,
|
|
// Is title present?
|
|
true,
|
|
// Expected
|
|
false,
|
|
'If disabled, returns false'
|
|
],
|
|
[
|
|
// Is option enabled?
|
|
true,
|
|
// Is title present?
|
|
false,
|
|
// Expected
|
|
false,
|
|
'If enabled but title null, returns false'
|
|
],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @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;
|
|
|
|
$userOptionsLookup = $this->createMock( UserOptionsLookup::class );
|
|
$userOptionsLookup->method( 'getOption' )->willReturn( $isEnabled );
|
|
$userOptionsLookup->method( 'getBoolOption' )->willReturn( $isEnabled );
|
|
|
|
$requirement = new UserPreferenceRequirement(
|
|
$user,
|
|
$userOptionsLookup,
|
|
'userOption',
|
|
'userRequirement',
|
|
$title
|
|
);
|
|
|
|
$this->assertSame( $expected, $requirement->isMet(), $msg );
|
|
}
|
|
}
|