2011-02-28 20:58:34 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* This file host two test case classes for the MediaWiki FormOptions class:
|
|
|
|
|
* - FormOptionsInitializationTest : tests initialization of the class.
|
|
|
|
|
* - FormOptionsTest : tests methods an on instance
|
|
|
|
|
*
|
|
|
|
|
* The split let us take advantage of setting up a fixture for the methods
|
|
|
|
|
* tests.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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
|
|
|
*/
|
2019-06-30 13:23:53 +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
|
|
|
}
|
|
|
|
|
}
|