dcaf1f7957d86382791e0a148bfa8138616f61f8
[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 * Generated by PHPUnit on 2011-02-28 at 20:46:27.
27 *
28 * Copyright © 2011, Antoine Musso
29 *
30 * @author Antoine Musso
31 */
32 class FormOptionsInitializationTest extends MediaWikiTestCase {
33 /**
34 * @var FormOptions
35 */
36 protected $object;
37
38 /**
39 * A new fresh and empty FormOptions object to test initialization
40 * with.
41 */
42 protected function setUp() {
43 parent::setUp();
44 $this->object = new FormOptionsExposed();
45 }
46
47 /**
48 * @covers FormOptionsExposed::add
49 */
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
65 /**
66 * @covers FormOptionsExposed::add
67 */
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 }