Added release notes for 'ContentHandler::runLegacyHooks' removal
[mediawiki.git] / tests / phpunit / includes / FormOptionsTest.php
blob2ee8b9833baffae31da5396d7b30c6ccf745aaa4
1 <?php
2 /**
3 * This file host two test case classes for the MediaWiki FormOptions class:
4 * - FormOptionsInitializationTest : tests initialization of the class.
5 * - FormOptionsTest : tests methods an on instance
7 * The split let us take advantage of setting up a fixture for the methods
8 * tests.
9 */
11 /**
12 * Test class for FormOptions methods.
14 * Copyright © 2011, Antoine Musso
16 * @author Antoine Musso
18 class FormOptionsTest extends MediaWikiTestCase {
19 /**
20 * @var FormOptions
22 protected $object;
24 /**
25 * Instanciates a FormOptions object to play with.
26 * FormOptions::add() is tested by the class FormOptionsInitializationTest
27 * so we assume the function is well tested already an use it to create
28 * the fixture.
30 protected function setUp() {
31 parent::setUp();
32 $this->object = new FormOptions;
33 $this->object->add( 'string1', 'string one' );
34 $this->object->add( 'string2', 'string two' );
35 $this->object->add( 'integer', 0 );
36 $this->object->add( 'float', 0.0 );
37 $this->object->add( 'intnull', 0, FormOptions::INTNULL );
40 /** Helpers for testGuessType() */
41 /* @{ */
42 private function assertGuessBoolean( $data ) {
43 $this->guess( FormOptions::BOOL, $data );
45 private function assertGuessInt( $data ) {
46 $this->guess( FormOptions::INT, $data );
48 private function assertGuessFloat( $data ) {
49 $this->guess( FormOptions::FLOAT, $data );
51 private function assertGuessString( $data ) {
52 $this->guess( FormOptions::STRING, $data );
54 private function assertGuessArray( $data ) {
55 $this->guess( FormOptions::ARR, $data );
58 /** Generic helper */
59 private function guess( $expected, $data ) {
60 $this->assertEquals(
61 $expected,
62 FormOptions::guessType( $data )
65 /* @} */
67 /**
68 * Reuse helpers above assertGuessBoolean assertGuessInt assertGuessString
69 * @covers FormOptions::guessType
71 public function testGuessTypeDetection() {
72 $this->assertGuessBoolean( true );
73 $this->assertGuessBoolean( false );
75 $this->assertGuessInt( 0 );
76 $this->assertGuessInt( -5 );
77 $this->assertGuessInt( 5 );
78 $this->assertGuessInt( 0x0F );
80 $this->assertGuessFloat( 0.0 );
81 $this->assertGuessFloat( 1.5 );
82 $this->assertGuessFloat( 1e3 );
84 $this->assertGuessString( 'true' );
85 $this->assertGuessString( 'false' );
86 $this->assertGuessString( '5' );
87 $this->assertGuessString( '0' );
88 $this->assertGuessString( '1.5' );
90 $this->assertGuessArray( [ 'foo' ] );
93 /**
94 * @expectedException MWException
95 * @covers FormOptions::guessType
97 public function testGuessTypeOnNullThrowException() {
98 $this->object->guessType( null );