MediaWiki  1.23.1
FormOptionsTest.php
Go to the documentation of this file.
1 <?php
23  protected $object;
24 
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( 'float', 0.0 );
38  $this->object->add( 'intnull', 0, FormOptions::INTNULL );
39  }
40 
42  /* @{ */
43  private function assertGuessBoolean( $data ) {
44  $this->guess( FormOptions::BOOL, $data );
45  }
46  private function assertGuessInt( $data ) {
47  $this->guess( FormOptions::INT, $data );
48  }
49  private function assertGuessFloat( $data ) {
50  $this->guess( FormOptions::FLOAT, $data );
51  }
52  private function assertGuessString( $data ) {
53  $this->guess( FormOptions::STRING, $data );
54  }
55 
57  private function guess( $expected, $data ) {
58  $this->assertEquals(
59  $expected,
60  FormOptions::guessType( $data )
61  );
62  }
63  /* @} */
64 
69  public function testGuessTypeDetection() {
70  $this->assertGuessBoolean( true );
71  $this->assertGuessBoolean( false );
72 
73  $this->assertGuessInt( 0 );
74  $this->assertGuessInt( -5 );
75  $this->assertGuessInt( 5 );
76  $this->assertGuessInt( 0x0F );
77 
78  $this->assertGuessFloat( 0.0 );
79  $this->assertGuessFloat( 1.5 );
80  $this->assertGuessFloat( 1e3 );
81 
82  $this->assertGuessString( 'true' );
83  $this->assertGuessString( 'false' );
84  $this->assertGuessString( '5' );
85  $this->assertGuessString( '0' );
86  $this->assertGuessString( '1.5' );
87  }
88 
93  public function testGuessTypeOnArrayThrowException() {
94  $this->object->guessType( array( 'foo' ) );
95  }
100  public function testGuessTypeOnNullThrowException() {
101  $this->object->guessType( null );
102  }
103 }
FormOptionsTest\assertGuessInt
assertGuessInt( $data)
Definition: FormOptionsTest.php:45
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
FormOptions\FLOAT
const FLOAT
Float type, maps guessType() to WebRequest::getFloat()
Definition: FormOptions.php:48
FormOptionsTest\assertGuessBoolean
assertGuessBoolean( $data)
Helpers for testGuessType()
Definition: FormOptionsTest.php:42
FormOptions\INTNULL
const INTNULL
Integer type or null, maps to WebRequest::getIntOrNull() This is useful for the namespace selector.
Definition: FormOptions.php:54
FormOptionsTest\assertGuessString
assertGuessString( $data)
Definition: FormOptionsTest.php:51
FormOptionsTest\assertGuessFloat
assertGuessFloat( $data)
Definition: FormOptionsTest.php:48
FormOptionsTest
This file host two test case classes for the MediaWiki FormOptions class:
Definition: FormOptionsTest.php:19
FormOptions\add
add( $name, $default, $type=self::AUTO)
Add an option to be handled by this FormOptions instance.
Definition: FormOptions.php:78
MediaWikiTestCase
Definition: MediaWikiTestCase.php:6
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
FormOptionsTest\setUp
setUp()
Instanciates a FormOptions object to play with.
Definition: FormOptionsTest.php:30
FormOptionsTest\testGuessTypeOnNullThrowException
testGuessTypeOnNullThrowException()
@expectedException MWException @covers FormOptions::guessType
Definition: FormOptionsTest.php:99
FormOptions\guessType
static guessType( $data)
Used to find out which type the data is.
Definition: FormOptions.php:114
FormOptionsTest\testGuessTypeOnArrayThrowException
testGuessTypeOnArrayThrowException()
@expectedException MWException @covers FormOptions::guessType
Definition: FormOptionsTest.php:92
FormOptionsTest\testGuessTypeDetection
testGuessTypeDetection()
Reuse helpers above assertGuessBoolean assertGuessInt assertGuessString @covers FormOptions::guessTyp...
Definition: FormOptionsTest.php:68
FormOptionsTest\$object
FormOptions $object
Definition: FormOptionsTest.php:22
FormOptions\STRING
const STRING
String type, maps guessType() to WebRequest::getText()
Definition: FormOptions.php:43
FormOptions\INT
const INT
Integer type, maps guessType() to WebRequest::getInt()
Definition: FormOptions.php:45
FormOptionsTest\guess
guess( $expected, $data)
Generic helper.
Definition: FormOptionsTest.php:56
FormOptions
Helper class to keep track of options when mixing links and form elements.
Definition: FormOptions.php:35
FormOptions\BOOL
const BOOL
Boolean type, maps guessType() to WebRequest::getBool()
Definition: FormOptions.php:50