mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/Vector.git
synced 2024-12-21 20:22:39 +00:00
5207a15b91
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
115 lines
3.4 KiB
PHP
115 lines
3.4 KiB
PHP
<?php
|
|
|
|
/**
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License along
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
*
|
|
* @file
|
|
*/
|
|
|
|
namespace MediaWiki\Skins\Vector\Tests\Integration;
|
|
|
|
use Vector\Constants;
|
|
use Vector\HTMLForm\Fields\HTMLLegacySkinVersionField;
|
|
|
|
/**
|
|
* @group Vector
|
|
* @coversDefaultClass \Vector\HTMLForm\Fields\HTMLLegacySkinVersionField
|
|
*/
|
|
class HTMLLegacySkinVersionFieldTest extends \MediaWikiIntegrationTestCase {
|
|
|
|
public function provideDefault() {
|
|
return [
|
|
[ false, '0' ],
|
|
[ false, false ],
|
|
[ true, '1' ],
|
|
[ true, true ],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @dataProvider provideDefault
|
|
* @covers ::__construct
|
|
*/
|
|
public function testConstructValidatesDefault( $expected, $default ) {
|
|
$field = new HTMLLegacySkinVersionField( [
|
|
'default' => $default,
|
|
'fieldname' => 'VectorSkinVersion',
|
|
] );
|
|
$this->assertSame(
|
|
$expected,
|
|
$field->getDefault()
|
|
);
|
|
}
|
|
|
|
public function provideGetInput() {
|
|
yield [ Constants::SKIN_VERSION_LEGACY, true ];
|
|
yield [ Constants::SKIN_VERSION_LATEST, false ];
|
|
}
|
|
|
|
/**
|
|
* @dataProvider provideGetInput
|
|
* @covers ::getInputHTML
|
|
* @covers ::getInputOOUI
|
|
*/
|
|
public function testGetInput( $skinVersionValue, $checkValue ) {
|
|
$params = [
|
|
'fieldname' => 'VectorSkinVersion',
|
|
'class' => HTMLLegacySkinVersionField::class,
|
|
'section' => 'rendering/skin/skin-prefs',
|
|
'label-message' => 'prefs-vector-enable-vector-1-label',
|
|
'help-message' => 'prefs-vector-enable-vector-1-help',
|
|
'default' => true,
|
|
'hide-if' => [ '!==', 'wpskin', Constants::SKIN_NAME ],
|
|
];
|
|
$skinVersionField = new HTMLLegacySkinVersionField( $params );
|
|
$checkField = new \HTMLCheckField( $params );
|
|
|
|
$this->assertSame(
|
|
$skinVersionField->getInputHTML( $skinVersionValue ),
|
|
$checkField->getInputHTML( $checkValue ),
|
|
'::getInputHTML matches HTMLCheckField::getInputHTML with mapped value'
|
|
);
|
|
|
|
$this->assertEquals(
|
|
$skinVersionField->getInputOOUI( $skinVersionValue ),
|
|
$checkField->getInputOOUI( $checkValue ),
|
|
'::getInputOOUI matches HTMLCheckField::getInputOOUI with mapped value'
|
|
);
|
|
}
|
|
|
|
public function provideLoadDataFromRequest() {
|
|
yield [ null, Constants::SKIN_VERSION_LEGACY ];
|
|
yield [ true, Constants::SKIN_VERSION_LEGACY ];
|
|
yield [ false, Constants::SKIN_VERSION_LATEST ];
|
|
}
|
|
|
|
/**
|
|
* @dataProvider provideLoadDataFromRequest
|
|
* @covers ::loadDataFromRequest
|
|
*/
|
|
public function testLoadDataFromRequest( $wpVectorSkinVersion, $expectedResult ) {
|
|
$skinVerionField = new HTMLLegacySkinVersionField( [
|
|
'fieldname' => 'VectorSkinVersion',
|
|
'default' => true,
|
|
] );
|
|
|
|
$request = new \WebRequest();
|
|
$request->setVal( 'wpVectorSkinVersion', $wpVectorSkinVersion );
|
|
|
|
$this->assertSame( $skinVerionField->loadDataFromRequest( $request ), $expectedResult );
|
|
}
|
|
}
|