HTMLLegacySkinVersionField: accept string 'default' value
After I628435a4a, we were asserting a boolean was given because we're extending HTMLFormField which requires a boolean value. This was safe because GlobalPrefs would provide a boolean, but that changed with I594f6297. We could rework GlobalPrefs once again to ensure only a boolean is passed in, but since HTMLLegacySkinVersionField already has special handling around the data types, it seems to make sense to contain the type transformation in this class. Simply removing the Assertion is enough to prevent T296068, however depending on when the global preference was saved (such as since MW 1.38.0-wmf.9 but before wmf.10), it's possible either a bool or a string was saved, hence we check for both to ensure correct display. Bug: T296068 Change-Id: If10b948617d2bb8346475f207fe425fb768cb987
This commit is contained in:
parent
768a07ec6c
commit
5207a15b91
|
@ -3,7 +3,6 @@
|
||||||
namespace Vector\HTMLForm\Fields;
|
namespace Vector\HTMLForm\Fields;
|
||||||
|
|
||||||
use Vector\Constants;
|
use Vector\Constants;
|
||||||
use Wikimedia\Assert\Assert;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The field on Special:Preferences (and Special:GlobalPreferences) that allows the user to
|
* The field on Special:Preferences (and Special:GlobalPreferences) that allows the user to
|
||||||
|
@ -34,10 +33,13 @@ final class HTMLLegacySkinVersionField extends \HTMLFormField {
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
public function __construct( $params ) {
|
public function __construct( $params ) {
|
||||||
Assert::precondition(
|
/**
|
||||||
is_bool( $params['default'] ),
|
* HTMLCheckField must be given a boolean as the 'default' value.
|
||||||
'The "default" param must be a boolean.'
|
* 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 );
|
parent::__construct( $params );
|
||||||
|
|
||||||
|
|
|
@ -31,20 +31,27 @@ use Vector\HTMLForm\Fields\HTMLLegacySkinVersionField;
|
||||||
class HTMLLegacySkinVersionFieldTest extends \MediaWikiIntegrationTestCase {
|
class HTMLLegacySkinVersionFieldTest extends \MediaWikiIntegrationTestCase {
|
||||||
|
|
||||||
public function provideDefault() {
|
public function provideDefault() {
|
||||||
yield [ 'true' ];
|
return [
|
||||||
yield [ 1 ];
|
[ false, '0' ],
|
||||||
|
[ false, false ],
|
||||||
|
[ true, '1' ],
|
||||||
|
[ true, true ],
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider provideDefault
|
* @dataProvider provideDefault
|
||||||
* @covers ::__construct
|
* @covers ::__construct
|
||||||
*/
|
*/
|
||||||
public function testConstructValidatesDefault( $default ) {
|
public function testConstructValidatesDefault( $expected, $default ) {
|
||||||
$this->expectException( \Wikimedia\Assert\PreconditionException::class );
|
$field = new HTMLLegacySkinVersionField( [
|
||||||
|
'default' => $default,
|
||||||
new HTMLLegacySkinVersionField( [
|
'fieldname' => 'VectorSkinVersion',
|
||||||
'default' => $default
|
|
||||||
] );
|
] );
|
||||||
|
$this->assertSame(
|
||||||
|
$expected,
|
||||||
|
$field->getDefault()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function provideGetInput() {
|
public function provideGetInput() {
|
||||||
|
|
Loading…
Reference in New Issue