MediaWiki  1.28.0
FormOptionsInitializationTest.php
Go to the documentation of this file.
1 <?php
17  public function getOptions() {
18  return $this->options;
19  }
20 }
21 
36  protected $object;
37 
42  protected function setUp() {
43  parent::setUp();
44  $this->object = new FormOptionsExposed();
45  }
46 
50  public function testAddStringOption() {
51  $this->object->add( 'foo', 'string value' );
52  $this->assertEquals(
53  [
54  'foo' => [
55  'default' => 'string value',
56  'consumed' => false,
57  'type' => FormOptions::STRING,
58  'value' => null,
59  ]
60  ],
61  $this->object->getOptions()
62  );
63  }
64 
68  public function testAddIntegers() {
69  $this->object->add( 'one', 1 );
70  $this->object->add( 'negone', -1 );
71  $this->assertEquals(
72  [
73  'negone' => [
74  'default' => -1,
75  'value' => null,
76  'consumed' => false,
77  'type' => FormOptions::INT,
78  ],
79  'one' => [
80  'default' => 1,
81  'value' => null,
82  'consumed' => false,
83  'type' => FormOptions::INT,
84  ]
85  ],
86  $this->object->getOptions()
87  );
88  }
89 }
Helper class to keep track of options when mixing links and form elements.
Definition: FormOptions.php:35
testAddIntegers()
FormOptionsExposed::add.
globals will be eliminated from MediaWiki replaced by an application object which would be passed to constructors Whether that would be an convenient solution remains to be but certainly PHP makes such object oriented programming models easier than they were in previous versions For the time being MediaWiki programmers will have to work in an environment with some global context At the time of globals were initialised on startup by MediaWiki of these were configuration which are documented in DefaultSettings php There is no comprehensive documentation for the remaining however some of the most important ones are listed below They are typically initialised either in index php or in Setup php For a description of the see design txt $wgTitle Title object created from the request URL $wgOut OutputPage object for HTTP response $wgUser User object for the user associated with the current request $wgLang Language object selected by user preferences $wgContLang Language object associated with the wiki being viewed $wgParser Parser object Parser extensions register their hooks here $wgRequest WebRequest object
Definition: globals.txt:25
testAddStringOption()
FormOptionsExposed::add.
const INT
Integer type, maps guessType() to WebRequest::getInt()
Definition: FormOptions.php:45
setUp()
A new fresh and empty FormOptions object to test initialization with.
$options
Map of known option names to information about them.
Definition: FormOptions.php:67
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
Test class for FormOptions initialization Ensure the FormOptions::add() does what we want it to do...
const STRING
String type, maps guessType() to WebRequest::getText()
Definition: FormOptions.php:43
This file host two test case classes for the MediaWiki FormOptions class: