MediaWiki  1.30.0
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,
62  FormOptions::guessType( $data )
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 }
FormOptionsTest\assertGuessInt
assertGuessInt( $data)
Definition: FormOptionsTest.php:45
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
FormOptions\ARR
const ARR
Array type, maps guessType() to WebRequest::getArray()
Definition: FormOptions.php:57
FormOptionsTest\assertGuessArray
assertGuessArray( $data)
Definition: FormOptionsTest.php:54
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
FormOptionsTest\assertGuessFloat
assertGuessFloat( $data)
Definition: FormOptionsTest.php:48
FormOptionsTest
This file host two test case classes for the MediaWiki FormOptions class:
Definition: FormOptionsTest.php:18
FormOptions\add
add( $name, $default, $type=self::AUTO)
Add an option to be handled by this FormOptions instance.
Definition: FormOptions.php:81
MediaWikiTestCase
Definition: MediaWikiTestCase.php:15
FormOptionsTest\setUp
setUp()
Instanciates a FormOptions object to play with.
Definition: FormOptionsTest.php:30
FormOptionsTest\testGuessTypeOnNullThrowException
testGuessTypeOnNullThrowException()
MWException FormOptions::guessType.
Definition: FormOptionsTest.php:97
FormOptions\guessType
static guessType( $data)
Used to find out which type the data is.
Definition: FormOptions.php:117
FormOptionsTest\testGuessTypeDetection
testGuessTypeDetection()
Reuse helpers above assertGuessBoolean assertGuessInt assertGuessString FormOptions::guessType.
Definition: FormOptionsTest.php:71
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:59
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