MediaWiki  1.29.1
Go to the documentation of this file.
1 <?php
17  public function getOptions() {
18  return $this->options;
19  }
20 }
34  protected $object;
40  protected function setUp() {
41  parent::setUp();
42  $this->object = new FormOptionsExposed();
43  }
48  public function testAddStringOption() {
49  $this->object->add( 'foo', 'string value' );
50  $this->assertEquals(
51  [
52  'foo' => [
53  'default' => 'string value',
54  'consumed' => false,
55  'type' => FormOptions::STRING,
56  'value' => null,
57  ]
58  ],
59  $this->object->getOptions()
60  );
61  }
66  public function testAddIntegers() {
67  $this->object->add( 'one', 1 );
68  $this->object->add( 'negone', -1 );
69  $this->assertEquals(
70  [
71  'negone' => [
72  'default' => -1,
73  'value' => null,
74  'consumed' => false,
75  'type' => FormOptions::INT,
76  ],
77  'one' => [
78  'default' => 1,
79  'value' => null,
80  'consumed' => false,
81  'type' => FormOptions::INT,
82  ]
83  ],
84  $this->object->getOptions()
85  );
86  }
87 }
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
A new fresh and empty FormOptions object to test initialization with.
Definition: FormOptionsInitializationTest.php:40
Definition: FormOptionsInitializationTest.php:66
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
Definition: FormOptionsInitializationTest.php:17
Test class for FormOptions initialization Ensure the FormOptions::add() does what we want it to do.
Definition: FormOptionsInitializationTest.php:30
Definition: MediaWikiTestCase.php:13
FormOptions $object
Definition: FormOptionsInitializationTest.php:34
Map of known option names to information about them.
Definition: FormOptions.php:70
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:
Definition: FormOptionsInitializationTest.php:16
const INT
Integer type, maps guessType() to WebRequest::getInt()
Definition: FormOptions.php:45
Definition: FormOptionsInitializationTest.php:48
Helper class to keep track of options when mixing links and form elements.
Definition: FormOptions.php:35