Merge "HTMLLegacySkinVersionField: accept string 'default' value"

This commit is contained in:
jenkins-bot 2021-11-23 11:27:41 +00:00 committed by Gerrit Code Review
commit ed4ec0079a
2 changed files with 21 additions and 12 deletions

View File

@ -3,7 +3,6 @@
namespace Vector\HTMLForm\Fields;
use Vector\Constants;
use Wikimedia\Assert\Assert;
/**
* The field on Special:Preferences (and Special:GlobalPreferences) that allows the user to
@ -34,10 +33,13 @@ final class HTMLLegacySkinVersionField extends \HTMLFormField {
* @inheritDoc
*/
public function __construct( $params ) {
Assert::precondition(
is_bool( $params['default'] ),
'The "default" param must be a boolean.'
);
/**
* HTMLCheckField must be given a boolean as the 'default' value.
* Since MW 1.38.0-wmf.9, we could be given a boolean or a string.
* @see T296068
*/
$params['default'] = $params['default'] === true ||
$params['default'] === Constants::SKIN_VERSION_LEGACY;
parent::__construct( $params );

View File

@ -31,20 +31,27 @@ use Vector\HTMLForm\Fields\HTMLLegacySkinVersionField;
class HTMLLegacySkinVersionFieldTest extends \MediaWikiIntegrationTestCase {
public function provideDefault() {
yield [ 'true' ];
yield [ 1 ];
return [
[ false, '0' ],
[ false, false ],
[ true, '1' ],
[ true, true ],
];
}
/**
* @dataProvider provideDefault
* @covers ::__construct
*/
public function testConstructValidatesDefault( $default ) {
$this->expectException( \Wikimedia\Assert\PreconditionException::class );
new HTMLLegacySkinVersionField( [
'default' => $default
public function testConstructValidatesDefault( $expected, $default ) {
$field = new HTMLLegacySkinVersionField( [
'default' => $default,
'fieldname' => 'VectorSkinVersion',
] );
$this->assertSame(
$expected,
$field->getDefault()
);
}
public function provideGetInput() {