MediaWiki REL1_31
FormOptionsTest.php
Go to the documentation of this file.
1<?php
22 protected $object;
23
30 protected function setUp() {
31 parent::setUp();
32 $this->object = new FormOptions;
33 $this->object->add( 'string1', 'string one' );
34 $this->object->add( 'string2', 'string two' );
35 $this->object->add( 'integer', 0 );
36 $this->object->add( 'float', 0.0 );
37 $this->object->add( 'intnull', 0, FormOptions::INTNULL );
38 }
39
41 /* @{ */
42 private function assertGuessBoolean( $data ) {
43 $this->guess( FormOptions::BOOL, $data );
44 }
45 private function assertGuessInt( $data ) {
46 $this->guess( FormOptions::INT, $data );
47 }
48 private function assertGuessFloat( $data ) {
49 $this->guess( FormOptions::FLOAT, $data );
50 }
51 private function assertGuessString( $data ) {
52 $this->guess( FormOptions::STRING, $data );
53 }
54 private function assertGuessArray( $data ) {
55 $this->guess( FormOptions::ARR, $data );
56 }
57
59 private function guess( $expected, $data ) {
60 $this->assertEquals(
61 $expected,
63 );
64 }
65 /* @} */
66
71 public function testGuessTypeDetection() {
72 $this->assertGuessBoolean( true );
73 $this->assertGuessBoolean( false );
74
75 $this->assertGuessInt( 0 );
76 $this->assertGuessInt( -5 );
77 $this->assertGuessInt( 5 );
78 $this->assertGuessInt( 0x0F );
79
80 $this->assertGuessFloat( 0.0 );
81 $this->assertGuessFloat( 1.5 );
82 $this->assertGuessFloat( 1e3 );
83
84 $this->assertGuessString( 'true' );
85 $this->assertGuessString( 'false' );
86 $this->assertGuessString( '5' );
87 $this->assertGuessString( '0' );
88 $this->assertGuessString( '1.5' );
89
90 $this->assertGuessArray( [ 'foo' ] );
91 }
92
98 $this->object->guessType( null );
99 }
100}
This file host two test case classes for the MediaWiki FormOptions class:
assertGuessBoolean( $data)
Helpers for testGuessType()
guess( $expected, $data)
Generic helper.
testGuessTypeDetection()
Reuse helpers above assertGuessBoolean assertGuessInt assertGuessString FormOptions::guessType.
FormOptions $object
setUp()
Instanciates a FormOptions object to play with.
testGuessTypeOnNullThrowException()
MWException FormOptions::guessType.
Helper class to keep track of options when mixing links and form elements.
add( $name, $default, $type=self::AUTO)
Add an option to be handled by this FormOptions instance.
const BOOL
Boolean type, maps guessType() to WebRequest::getBool()
const FLOAT
Float type, maps guessType() to WebRequest::getFloat()
const STRING
String type, maps guessType() to WebRequest::getText()
static guessType( $data)
Used to find out which type the data is.
const INTNULL
Integer type or null, maps to WebRequest::getIntOrNull() This is useful for the namespace selector.
const ARR
Array type, maps guessType() to WebRequest::getArray()
const INT
Integer type, maps guessType() to WebRequest::getInt()