HTMLLegacySkinVersionFieldTest: Adjust tests to closer to real situation
The behavior of data loading can differ between submitting and display, so use FauxRequest to customize the method. Also fix the order of parameters passing to assertSame(), the first one should be the expected one. Change-Id: Icfa062eada75c50cd2c8bc5db2930602d80e9ae7
This commit is contained in:
parent
6ec87052e9
commit
1d67da02f8
|
@ -91,24 +91,32 @@ class HTMLLegacySkinVersionFieldTest extends \MediaWikiIntegrationTestCase {
|
|||
}
|
||||
|
||||
public function provideLoadDataFromRequest() {
|
||||
yield [ null, Constants::SKIN_VERSION_LEGACY ];
|
||||
yield [ true, Constants::SKIN_VERSION_LEGACY ];
|
||||
yield [ false, Constants::SKIN_VERSION_LATEST ];
|
||||
// User just load the form, fallback to default.
|
||||
yield [ null, false, Constants::SKIN_VERSION_LEGACY ];
|
||||
// User submit the form, load from request.
|
||||
yield [ null, true, Constants::SKIN_VERSION_LATEST ];
|
||||
yield [ true, true, Constants::SKIN_VERSION_LEGACY ];
|
||||
// In normal request you can't get the 'false' value though.
|
||||
yield [ false, true, Constants::SKIN_VERSION_LATEST ];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideLoadDataFromRequest
|
||||
* @covers ::loadDataFromRequest
|
||||
*/
|
||||
public function testLoadDataFromRequest( $wpVectorSkinVersion, $expectedResult ) {
|
||||
public function testLoadDataFromRequest( $wpVectorSkinVersion, $wasPosted, $expectedResult ) {
|
||||
$skinVerionField = new HTMLLegacySkinVersionField( [
|
||||
'fieldname' => 'VectorSkinVersion',
|
||||
'default' => true,
|
||||
] );
|
||||
|
||||
$request = new \WebRequest();
|
||||
$request->setVal( 'wpVectorSkinVersion', $wpVectorSkinVersion );
|
||||
$requestData = [ 'wpVectorSkinVersion' => $wpVectorSkinVersion ];
|
||||
if ( $wasPosted ) {
|
||||
// Check field would load data from requst if it pass the isSubmitAttempt() check.
|
||||
$requestData['wpEditToken'] = 'ABC123';
|
||||
}
|
||||
$request = new \FauxRequest( $requestData, $wasPosted );
|
||||
|
||||
$this->assertSame( $skinVerionField->loadDataFromRequest( $request ), $expectedResult );
|
||||
$this->assertSame( $expectedResult, $skinVerionField->loadDataFromRequest( $request ) );
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue