MediaWiki  REL1_22
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         parent::setUp();
00033         $this->object = new FormOptions;
00034         $this->object->add( 'string1', 'string one' );
00035         $this->object->add( 'string2', 'string two' );
00036         $this->object->add( 'integer', 0 );
00037         $this->object->add( 'intnull', 0, FormOptions::INTNULL );
00038     }
00039 
00041     /* @{ */
00042     private function assertGuessBoolean( $data ) {
00043         $this->guess( FormOptions::BOOL, $data );
00044     }
00045     private function assertGuessInt( $data ) {
00046         $this->guess( FormOptions::INT, $data );
00047     }
00048     private function assertGuessString( $data ) {
00049         $this->guess( FormOptions::STRING, $data );
00050     }
00051 
00053     private function guess( $expected, $data ) {
00054         $this->assertEquals(
00055             $expected,
00056             FormOptions::guessType( $data )
00057         );
00058     }
00059     /* @} */
00060 
00064     public function testGuessTypeDetection() {
00065         $this->assertGuessBoolean( true );
00066         $this->assertGuessBoolean( false );
00067 
00068         $this->assertGuessInt( 0 );
00069         $this->assertGuessInt( -5 );
00070         $this->assertGuessInt( 5 );
00071         $this->assertGuessInt( 0x0F );
00072 
00073         $this->assertGuessString( 'true' );
00074         $this->assertGuessString( 'false' );
00075         $this->assertGuessString( '5' );
00076         $this->assertGuessString( '0' );
00077     }
00078 
00082     public function testGuessTypeOnArrayThrowException() {
00083         $this->object->guessType( array( 'foo' ) );
00084     }
00088     public function testGuessTypeOnNullThrowException() {
00089         $this->object->guessType( null );
00090     }
00091 }