MediaWiki  REL1_19
FormOptionsTest.php
Go to the documentation of this file.
00001 <?php
00019 class FormOptionsTest extends MediaWikiTestCase {
00023         protected $object;
00024 
00031         protected function setUp() {
00032                 $this->object = new FormOptions;
00033                 $this->object->add( 'string1', 'string one' );
00034                 $this->object->add( 'string2', 'string two' );
00035                 $this->object->add( 'integer',  0 );
00036                 $this->object->add( 'intnull',  0, FormOptions::INTNULL );
00037         }
00038 
00040         /* @{ */
00041         private function assertGuessBoolean( $data ) {
00042                 $this->guess( FormOptions::BOOL, $data );
00043         }
00044         private function assertGuessInt( $data ) {
00045                 $this->guess( FormOptions::INT, $data );
00046         }
00047         private function assertGuessString( $data ) {
00048                 $this->guess( FormOptions::STRING, $data );
00049         }
00050 
00052         private function guess( $expected, $data ) {
00053                 $this->assertEquals(
00054                         $expected,
00055                         FormOptions::guessType( $data )
00056                 );
00057         }
00058         /* @} */
00059 
00063         public function testGuessTypeDetection() {
00064                 $this->assertGuessBoolean( true  );
00065                 $this->assertGuessBoolean( false );
00066 
00067                 $this->assertGuessInt(    0 );
00068                 $this->assertGuessInt(   -5 );
00069                 $this->assertGuessInt(    5 );
00070                 $this->assertGuessInt( 0x0F );
00071 
00072                 $this->assertGuessString( 'true'  );
00073                 $this->assertGuessString( 'false' ); 
00074                 $this->assertGuessString( '5'     ); 
00075                 $this->assertGuessString( '0'     ); 
00076         }
00077 
00081         public function testGuessTypeOnArrayThrowException() {
00082                 $this->object->guessType( array( 'foo' ) ); 
00083         }
00087         public function testGuessTypeOnNullThrowException() {
00088                 $this->object->guessType( null ); 
00089         }
00090 }