MediaWiki
REL1_24
|
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( 'float', 0.0 ); 00038 $this->object->add( 'intnull', 0, FormOptions::INTNULL ); 00039 } 00040 00042 /* @{ */ 00043 private function assertGuessBoolean( $data ) { 00044 $this->guess( FormOptions::BOOL, $data ); 00045 } 00046 private function assertGuessInt( $data ) { 00047 $this->guess( FormOptions::INT, $data ); 00048 } 00049 private function assertGuessFloat( $data ) { 00050 $this->guess( FormOptions::FLOAT, $data ); 00051 } 00052 private function assertGuessString( $data ) { 00053 $this->guess( FormOptions::STRING, $data ); 00054 } 00055 00057 private function guess( $expected, $data ) { 00058 $this->assertEquals( 00059 $expected, 00060 FormOptions::guessType( $data ) 00061 ); 00062 } 00063 /* @} */ 00064 00069 public function testGuessTypeDetection() { 00070 $this->assertGuessBoolean( true ); 00071 $this->assertGuessBoolean( false ); 00072 00073 $this->assertGuessInt( 0 ); 00074 $this->assertGuessInt( -5 ); 00075 $this->assertGuessInt( 5 ); 00076 $this->assertGuessInt( 0x0F ); 00077 00078 $this->assertGuessFloat( 0.0 ); 00079 $this->assertGuessFloat( 1.5 ); 00080 $this->assertGuessFloat( 1e3 ); 00081 00082 $this->assertGuessString( 'true' ); 00083 $this->assertGuessString( 'false' ); 00084 $this->assertGuessString( '5' ); 00085 $this->assertGuessString( '0' ); 00086 $this->assertGuessString( '1.5' ); 00087 } 00088 00093 public function testGuessTypeOnArrayThrowException() { 00094 $this->object->guessType( array( 'foo' ) ); 00095 } 00100 public function testGuessTypeOnNullThrowException() { 00101 $this->object->guessType( null ); 00102 } 00103 }