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
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
{
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
31 protected function 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
);
40 /** Helpers for testGuessType() */
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 assertGuessString( $data ) {
49 $this->guess( FormOptions
::STRING, $data );
53 private function guess( $expected, $data ) {
56 FormOptions
::guessType( $data )
62 * Reuse helpers above assertGuessBoolean assertGuessInt assertGuessString
64 public function testGuessTypeDetection() {
65 $this->assertGuessBoolean( true );
66 $this->assertGuessBoolean( false );
68 $this->assertGuessInt( 0 );
69 $this->assertGuessInt( -5 );
70 $this->assertGuessInt( 5 );
71 $this->assertGuessInt( 0x0F );
73 $this->assertGuessString( 'true' );
74 $this->assertGuessString( 'false' );
75 $this->assertGuessString( '5' );
76 $this->assertGuessString( '0' );
80 * @expectedException MWException
82 public function testGuessTypeOnArrayThrowException() {
83 $this->object->guessType( array( 'foo' ) );
86 * @expectedException MWException
88 public function testGuessTypeOnNullThrowException() {
89 $this->object->guessType( null );