2011-02-28 20:58:34 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test class for FormOptions methods.
|
|
|
|
|
*
|
2011-10-24 09:08:13 +00:00
|
|
|
* Copyright © 2011, Antoine Musso
|
2011-02-28 20:58:34 +00:00
|
|
|
*
|
2011-10-24 09:08:13 +00:00
|
|
|
* @author Antoine Musso
|
2011-02-28 20:58:34 +00:00
|
|
|
*/
|
2021-01-12 12:03:41 +00:00
|
|
|
class FormOptionsTest extends MediaWikiUnitTestCase {
|
2011-02-28 20:58:34 +00:00
|
|
|
|
|
|
|
|
/**
|
2020-12-23 10:03:34 +00:00
|
|
|
* @covers FormOptions::guessType
|
|
|
|
|
* @dataProvider provideTypeDetection
|
2011-02-28 20:58:34 +00:00
|
|
|
*/
|
2020-12-23 10:03:34 +00:00
|
|
|
public function testGuessTypeDetection( $expectedType, $data ) {
|
2011-02-28 20:58:34 +00:00
|
|
|
$this->assertEquals(
|
2020-12-23 10:03:34 +00:00
|
|
|
$expectedType,
|
2011-02-28 20:58:34 +00:00
|
|
|
FormOptions::guessType( $data )
|
|
|
|
|
);
|
|
|
|
|
}
|
2019-05-11 01:17:43 +00:00
|
|
|
|
2020-12-23 10:03:34 +00:00
|
|
|
public function provideTypeDetection() {
|
|
|
|
|
yield [ FormOptions::BOOL, true ];
|
|
|
|
|
yield [ FormOptions::BOOL, false ];
|
|
|
|
|
yield [ FormOptions::INT, 0 ];
|
|
|
|
|
yield [ FormOptions::INT, -5 ];
|
|
|
|
|
yield [ FormOptions::INT, 5 ];
|
|
|
|
|
yield [ FormOptions::INT, 0x0F ];
|
|
|
|
|
yield [ FormOptions::FLOAT, 0.0 ];
|
|
|
|
|
yield [ FormOptions::FLOAT, 1.5 ];
|
|
|
|
|
yield [ FormOptions::FLOAT, 1e3 ];
|
|
|
|
|
yield [ FormOptions::STRING, 'true' ];
|
|
|
|
|
yield [ FormOptions::STRING, 'false' ];
|
|
|
|
|
yield [ FormOptions::STRING, '5' ];
|
|
|
|
|
yield [ FormOptions::STRING, '0' ];
|
|
|
|
|
yield [ FormOptions::STRING, '1.5' ];
|
|
|
|
|
yield [ FormOptions::ARR, [ 'foo' ] ];
|
2011-02-28 20:58:34 +00:00
|
|
|
}
|
2016-05-11 13:42:12 +00:00
|
|
|
|
2011-02-28 20:58:34 +00:00
|
|
|
/**
|
2013-10-24 10:54:02 +00:00
|
|
|
* @covers FormOptions::guessType
|
2011-02-28 20:58:34 +00:00
|
|
|
*/
|
|
|
|
|
public function testGuessTypeOnNullThrowException() {
|
2019-10-05 05:21:11 +00:00
|
|
|
$this->expectException( MWException::class );
|
2020-12-23 10:03:34 +00:00
|
|
|
$this->expectExceptionMessage( 'Unsupported datatype' );
|
|
|
|
|
FormOptions::guessType( null );
|
2011-02-28 20:58:34 +00:00
|
|
|
}
|
|
|
|
|
}
|