Add tests for ExtensionJsonValidator
[lhc/web/wiklou.git] / tests / phpunit / includes / FormOptionsInitializationTest.php
1 <?php
2 /**
3 * This file host two test case classes for the MediaWiki FormOptions class:
4 * - FormOptionsInitializationTest : tests initialization of the class.
5 * - FormOptionsTest : tests methods an on instance
6 *
7 * The split let us take advantage of setting up a fixture for the methods
8 * tests.
9 */
10
11 /**
12 * Dummy class to makes FormOptions::$options public.
13 * Used by FormOptionsInitializationTest which need to verify the $options
14 * array is correctly set through the FormOptions::add() function.
15 */
16 class FormOptionsExposed extends FormOptions {
17 public function getOptions() {
18 return $this->options;
19 }
20 }
21
22 /**
23 * Test class for FormOptions initialization
24 * Ensure the FormOptions::add() does what we want it to do.
25 *
26 * Copyright © 2011, Antoine Musso
27 *
28 * @author Antoine Musso
29 */
30 class FormOptionsInitializationTest extends MediaWikiTestCase {
31 /**
32 * @var FormOptions
33 */
34 protected $object;
35
36 /**
37 * A new fresh and empty FormOptions object to test initialization
38 * with.
39 */
40 protected function setUp() {
41 parent::setUp();
42 $this->object = new FormOptionsExposed();
43 }
44
45 /**
46 * @covers FormOptionsExposed::add
47 */
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 }
62
63 /**
64 * @covers FormOptionsExposed::add
65 */
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 }