Debian Codegraph @

tests/phpunit/unit/includes/Html/FormOptionsTest.php

raw symbols SCIP
1 <?php
2
3 use MediaWiki\Html\FormOptions;
4
5 /**
6 * Copyright © 2011, Antoine Musso
7 *
8 * @author Antoine Musso
9 * @covers \MediaWiki\Html\FormOptions
10 */
11 class FormOptionsTest extends MediaWikiUnitTestCase {
12
13 /**
14 * @dataProvider provideTypeDetection
15 */
16 public function testGuessTypeDetection( $expectedType, $data ) {
17 $this->assertEquals(
18 $expectedType,
19 FormOptions::guessType( $data )
20 );
21 }
22
23 public static function provideTypeDetection() {
24 yield [ FormOptions::BOOL, true ];
25 yield [ FormOptions::BOOL, false ];
26 yield [ FormOptions::INT, 0 ];
27 yield [ FormOptions::INT, -5 ];
28 yield [ FormOptions::INT, 5 ];
29 yield [ FormOptions::INT, 0x0F ];
30 yield [ FormOptions::FLOAT, 0.0 ];
31 yield [ FormOptions::FLOAT, 1.5 ];
32 yield [ FormOptions::FLOAT, 1e3 ];
33 yield [ FormOptions::STRING, 'true' ];
34 yield [ FormOptions::STRING, 'false' ];
35 yield [ FormOptions::STRING, '5' ];
36 yield [ FormOptions::STRING, '0' ];
37 yield [ FormOptions::STRING, '1.5' ];
38 yield [ FormOptions::ARR, [ 'foo' ] ];
39 }
40
41 public function testGuessTypeOnNullThrowException() {
42 $this->expectException( InvalidArgumentException::class );
43 $this->expectExceptionMessage( 'Unsupported datatype' );
44 FormOptions::guessType( null );
45 }
46 }