$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' => [ '!==', 'skin', Constants::SKIN_NAME_LEGACY ], ]; $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() { // 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, $wasPosted, $expectedResult ) { $skinVerionField = new HTMLLegacySkinVersionField( [ 'fieldname' => 'VectorSkinVersion', 'default' => true, ] ); $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( $expectedResult, $skinVerionField->loadDataFromRequest( $request ) ); } }