Add DROP INDEX support to DatabaseSqlite::replaceVars method
[lhc/web/wiklou.git] / tests / phpunit / includes / FormOptionsTest.php
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
6 *
7 * The split let us take advantage of setting up a fixture for the methods
8 * tests.
9 */
10
11 /**
12 * Test class for FormOptions methods.
13 * Generated by PHPUnit on 2011-02-28 at 20:46:27.
14 *
15 * Copyright © 2011, Antoine Musso
16 *
17 * @author Antoine Musso
18 */
19 class FormOptionsTest extends MediaWikiTestCase {
20 /**
21 * @var FormOptions
22 */
23 protected $object;
24
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.
30 */
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( 'intnull', 0, FormOptions::INTNULL );
38 }
39
40 /** Helpers for testGuessType() */
41 /* @{ */
42 private function assertGuessBoolean( $data ) {
43 $this->guess( FormOptions::BOOL, $data );
44 }
45 private function assertGuessInt( $data ) {
46 $this->guess( FormOptions::INT, $data );
47 }
48 private function assertGuessString( $data ) {
49 $this->guess( FormOptions::STRING, $data );
50 }
51
52 /** Generic helper */
53 private function guess( $expected, $data ) {
54 $this->assertEquals(
55 $expected,
56 FormOptions::guessType( $data )
57 );
58 }
59 /* @} */
60
61 /**
62 * Reuse helpers above assertGuessBoolean assertGuessInt assertGuessString
63 */
64 public function testGuessTypeDetection() {
65 $this->assertGuessBoolean( true );
66 $this->assertGuessBoolean( false );
67
68 $this->assertGuessInt( 0 );
69 $this->assertGuessInt( -5 );
70 $this->assertGuessInt( 5 );
71 $this->assertGuessInt( 0x0F );
72
73 $this->assertGuessString( 'true' );
74 $this->assertGuessString( 'false' );
75 $this->assertGuessString( '5' );
76 $this->assertGuessString( '0' );
77 }
78
79 /**
80 * @expectedException MWException
81 */
82 public function testGuessTypeOnArrayThrowException() {
83 $this->object->guessType( array( 'foo' ) );
84 }
85 /**
86 * @expectedException MWException
87 */
88 public function testGuessTypeOnNullThrowException() {
89 $this->object->guessType( null );
90 }
91 }