Merge "DatabaseMssql: Don't duplicate body of makeList()"
[mediawiki.git] / tests / phpunit / includes / FormOptionsTest.php
blob665fa390171d2f6ea3cc04d656c518ff59d66985
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.
13 * Generated by PHPUnit on 2011-02-28 at 20:46:27.
15 * Copyright © 2011, Antoine Musso
17 * @author Antoine Musso
19 class FormOptionsTest extends MediaWikiTestCase {
20 /**
21 * @var FormOptions
23 protected $object;
25 /**
26 * Instanciates a FormOptions object to play with.
27 * FormOptions::add() is tested by the class FormOptionsInitializationTest
28 * so we assume the function is well tested already an use it to create
29 * the fixture.
31 protected function setUp() {
32 parent::setUp();
33 $this->object = new FormOptions;
34 $this->object->add( 'string1', 'string one' );
35 $this->object->add( 'string2', 'string two' );
36 $this->object->add( 'integer', 0 );
37 $this->object->add( 'float', 0.0 );
38 $this->object->add( 'intnull', 0, FormOptions::INTNULL );
41 /** Helpers for testGuessType() */
42 /* @{ */
43 private function assertGuessBoolean( $data ) {
44 $this->guess( FormOptions::BOOL, $data );
46 private function assertGuessInt( $data ) {
47 $this->guess( FormOptions::INT, $data );
49 private function assertGuessFloat( $data ) {
50 $this->guess( FormOptions::FLOAT, $data );
52 private function assertGuessString( $data ) {
53 $this->guess( FormOptions::STRING, $data );
56 /** Generic helper */
57 private function guess( $expected, $data ) {
58 $this->assertEquals(
59 $expected,
60 FormOptions::guessType( $data )
63 /* @} */
65 /**
66 * Reuse helpers above assertGuessBoolean assertGuessInt assertGuessString
67 * @covers FormOptions::guessType
69 public function testGuessTypeDetection() {
70 $this->assertGuessBoolean( true );
71 $this->assertGuessBoolean( false );
73 $this->assertGuessInt( 0 );
74 $this->assertGuessInt( -5 );
75 $this->assertGuessInt( 5 );
76 $this->assertGuessInt( 0x0F );
78 $this->assertGuessFloat( 0.0 );
79 $this->assertGuessFloat( 1.5 );
80 $this->assertGuessFloat( 1e3 );
82 $this->assertGuessString( 'true' );
83 $this->assertGuessString( 'false' );
84 $this->assertGuessString( '5' );
85 $this->assertGuessString( '0' );
86 $this->assertGuessString( '1.5' );
89 /**
90 * @expectedException MWException
91 * @covers FormOptions::guessType
93 public function testGuessTypeOnArrayThrowException() {
94 $this->object->guessType( array( 'foo' ) );
96 /**
97 * @expectedException MWException
98 * @covers FormOptions::guessType
100 public function testGuessTypeOnNullThrowException() {
101 $this->object->guessType( null );