2022-12-01 20:05:06 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace MediaWiki\Skins\Vector\Tests\Unit\FeatureManagement\Requirements;
|
|
|
|
|
2024-01-02 19:54:08 +00:00
|
|
|
use MediaWiki\Request\FauxRequest;
|
2022-12-01 20:05:06 +00:00
|
|
|
use MediaWiki\Skins\Vector\FeatureManagement\Requirements\UserPreferenceRequirement;
|
2023-08-19 18:19:12 +00:00
|
|
|
use MediaWiki\Title\Title;
|
2023-11-29 12:42:02 +00:00
|
|
|
use MediaWiki\User\Options\UserOptionsLookup;
|
2024-03-13 20:59:40 +00:00
|
|
|
use MediaWiki\User\UserIdentity;
|
2022-12-01 20:05:06 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @group Vector
|
|
|
|
* @group FeatureManagement
|
|
|
|
* @coversDefaultClass \MediaWiki\Skins\Vector\FeatureManagement\Requirements\UserPreferenceRequirement
|
|
|
|
*/
|
|
|
|
final class UserPreferenceRequirementTest extends \MediaWikiUnitTestCase {
|
2023-05-20 09:01:16 +00:00
|
|
|
public static function providerTestIsMetRequirement() {
|
2022-12-01 20:05:06 +00:00
|
|
|
return [
|
|
|
|
[
|
|
|
|
// Is option enabled?
|
2023-10-02 21:03:21 +00:00
|
|
|
1,
|
2022-12-01 20:05:06 +00:00
|
|
|
// Is title present?
|
|
|
|
true,
|
|
|
|
// Expected
|
|
|
|
true,
|
|
|
|
'If enabled, returns true'
|
|
|
|
],
|
|
|
|
[
|
|
|
|
// Is option enabled?
|
2023-10-02 21:03:21 +00:00
|
|
|
0,
|
2022-12-01 20:05:06 +00:00
|
|
|
// Is title present?
|
|
|
|
true,
|
|
|
|
// Expected
|
|
|
|
false,
|
|
|
|
'If disabled, returns false'
|
|
|
|
],
|
|
|
|
[
|
|
|
|
// Is option enabled?
|
2023-10-02 21:03:21 +00:00
|
|
|
'enabled',
|
2022-12-01 20:05:06 +00:00
|
|
|
// Is title present?
|
|
|
|
false,
|
|
|
|
// Expected
|
|
|
|
false,
|
|
|
|
'If enabled but title null, returns false'
|
|
|
|
],
|
2023-10-02 21:03:21 +00:00
|
|
|
[
|
|
|
|
'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'
|
|
|
|
],
|
2022-12-01 20:05:06 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers ::isMet
|
|
|
|
* @dataProvider providerTestIsMetRequirement
|
|
|
|
* @param bool $isEnabled
|
|
|
|
* @param bool $isTitlePresent
|
|
|
|
* @param bool $expected
|
|
|
|
* @param string $msg
|
|
|
|
*/
|
|
|
|
public function testIsMetRequirement(
|
|
|
|
$isEnabled,
|
|
|
|
$isTitlePresent,
|
|
|
|
$expected,
|
|
|
|
$msg
|
|
|
|
) {
|
2024-03-13 20:59:40 +00:00
|
|
|
$user = $this->createMock( UserIdentity::class );
|
2022-12-01 20:05:06 +00:00
|
|
|
$title = $isTitlePresent ? $this->createMock( Title::class ) : null;
|
2023-10-02 18:15:18 +00:00
|
|
|
$request = new FauxRequest();
|
2022-12-01 20:05:06 +00:00
|
|
|
|
|
|
|
$userOptionsLookup = $this->createMock( UserOptionsLookup::class );
|
|
|
|
$userOptionsLookup->method( 'getOption' )->willReturn( $isEnabled );
|
|
|
|
|
|
|
|
$requirement = new UserPreferenceRequirement(
|
|
|
|
$user,
|
|
|
|
$userOptionsLookup,
|
|
|
|
'userOption',
|
|
|
|
'userRequirement',
|
2023-10-02 18:15:18 +00:00
|
|
|
$request,
|
2022-12-01 20:05:06 +00:00
|
|
|
$title
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertSame( $expected, $requirement->isMet(), $msg );
|
|
|
|
}
|
|
|
|
}
|