Completed
Push — develop ( eda620...cca4ef )
by Mathieu
01:38
created

FormItemTest::testInputSelect()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 8
nc 1
nop 0
dl 0
loc 12
rs 10
c 1
b 0
f 0
1
<?php
2
3
use \Suricate\FormItem;
4
5
/**
6
 * @SuppressWarnings("StaticAccess")
7
 */
8
class FormItemTest extends \PHPUnit\Framework\TestCase
9
{
10
    public function testInput()
11
    {
12
        $res = FormItem::input('text', 'myInput', "accentué", 'Mon input');
13
        $this->assertEquals(
14
            '<label for="myInput">Mon input</label><input type="text" name="myInput" id="myInput" value="accentu&eacute;"/>',
15
            $res
16
        );
17
18
        $res = FormItem::input('text', 'myInput', null, 'Mon input');
19
        $this->assertEquals(
20
            '<label for="myInput">Mon input</label><input type="text" name="myInput" id="myInput"/>',
21
            $res
22
        );
23
24
        $res = FormItem::input('text', 'myInput', "testval");
25
        $this->assertEquals(
26
            '<input type="text" name="myInput" value="testval"/>',
27
            $res
28
        );
29
    }
30
31
    public function testInputText()
32
    {
33
        $res = FormItem::text('my-input-name', "accentué", 'Mon input');
34
        $this->assertEquals(
35
            '<label for="my-input-name">Mon input</label><input type="text" name="my-input-name" id="my-input-name" value="accentu&eacute;"/>',
36
            $res
37
        );
38
    }
39
40
    public function testInputPassword()
41
    {
42
        $res = FormItem::password('my-input-name', "accentué", 'Mon input');
43
        $this->assertEquals(
44
            '<label for="my-input-name">Mon input</label><input type="password" name="my-input-name" id="my-input-name" value="accentu&eacute;"/>',
45
            $res
46
        );
47
    }
48
49
    public function testInputNumber()
50
    {
51
        $res = FormItem::number('my-input-name', "accentué", 'Mon input');
52
        $this->assertEquals(
53
            '<label for="my-input-name">Mon input</label><input type="number" name="my-input-name" id="my-input-name" value="accentu&eacute;"/>',
54
            $res
55
        );
56
    }
57
58
    public function testInputButton()
59
    {
60
        $res = FormItem::button('my-input-name', "accentué", 'Mon input');
61
        $this->assertEquals(
62
            '<label for="my-input-name">Mon input</label><input type="button" name="my-input-name" id="my-input-name" value="accentu&eacute;"/>',
63
            $res
64
        );
65
    }
66
67
    public function testInputCheckbox()
68
    {
69
        $res = FormItem::checkbox('my-input-name', 2, true, 'Mon input');
70
        $this->assertEquals(
71
            '<label for="my-input-name">Mon input</label><input type="checkbox" name="my-input-name" id="my-input-name" value="2" checked="checked"/>',
72
            $res
73
        );
74
75
        $res = FormItem::checkbox('my-input-name', 2, false, 'Mon input');
76
        $this->assertEquals(
77
            '<label for="my-input-name">Mon input</label><input type="checkbox" name="my-input-name" id="my-input-name" value="2"/>',
78
            $res
79
        );
80
    }
81
82
    public function testInputRadio()
83
    {
84
        $res = FormItem::radio('my-input-name', [1, 2, 3], 2, 'Mon input');
85
        $this->assertEquals(
86
            '<label>Mon input</label><div class="radio-list"><div class="radio-item"><label for="my-input-name-0">1</label><input type="radio" name="my-input-name" id="my-input-name-0" value="0"/></div><div class="radio-item"><label for="my-input-name-1">2</label><input type="radio" name="my-input-name" id="my-input-name-1" value="1"/></div><div class="radio-item"><label for="my-input-name-2">3</label><input type="radio" name="my-input-name" id="my-input-name-2" value="2" checked="checked"/></div></div>',
87
            $res
88
        );
89
    }
90
91
    public function testInputReset()
92
    {
93
        $res = FormItem::reset('val');
94
        $this->assertEquals(
95
            '<input type="reset" value="val"/>',
96
            $res
97
        );
98
    }
99
100
    public function testInputSelect()
101
    {
102
        $res = FormItem::select('my-input-name', [1, 2, 3], 2, 'Mon input');
103
        $this->assertEquals(
104
            '<label>Mon input</label><select name="my-input-name"><option value="0">1</option><option value="1">2</option><option value="2" selected>3</option></select>',
105
            $res
106
        );
107
108
        $res = FormItem::select('my-input-name', ["é\"" => ['a', 'b'], 2, 3 => ['c', 'd']], 2, 'Mon input');
109
        $this->assertEquals(
110
            '<label>Mon input</label><select name="my-input-name"><optgroup label="&eacute;&quot;"><option value="0">a</option><option value="1">b</option></optgroup><option value="0">2</option><optgroup label="3"><option value="0">c</option><option value="1">d</option></optgroup></select>',
111
            $res
112
        );
113
    }
114
115
    public function testInputFile()
116
    {
117
        $res = FormItem::file('my-input-name', "Mon input");
118
        $this->assertEquals(
119
            '<label for="my-input-name">Mon input</label><input type="file" name="my-input-name" id="my-input-name"/>',
120
            $res
121
        );
122
    }
123
124
    public function testInputHidden()
125
    {
126
        $res = FormItem::hidden('my-input-name', "accentué");
127
        $this->assertEquals(
128
            '<input type="hidden" name="my-input-name" value="accentu&eacute;"/>',
129
            $res
130
        );
131
    }
132
133
    public function testInputImage()
134
    {
135
        $res = FormItem::image('my-input-name', "https://gsuite.google.com/img/icons/product-lockup.png");
136
        $this->assertEquals(
137
            '<input type="image" name="my-input-name" src="https://gsuite.google.com/img/icons/product-lockup.png"/>',
138
            $res
139
        );
140
    }
141
142
    public function testInputSubmit()
143
    {
144
        $res = FormItem::submit('my-input-name', "accentué", 'Mon input');
145
        $this->assertEquals(
146
            '<label for="my-input-name">Mon input</label><input type="submit" name="my-input-name" id="my-input-name" value="accentu&eacute;"/>',
147
            $res
148
        );
149
    }
150
151
    public function testInputTextarea()
152
    {
153
        $res = FormItem::textarea('my-input-name', "accentué", 'Mon input');
154
        $this->assertEquals(
155
            '<label for="my-input-name">Mon input</label><textarea name="my-input-name" id="my-input-name">accentué</textarea>',
156
            $res
157
        );
158
    }
159
160
    public function testInputTel()
161
    {
162
        $res = FormItem::tel('my-input-name', "accentué", 'Mon input');
163
        $this->assertEquals(
164
            '<label for="my-input-name">Mon input</label><input type="tel" name="my-input-name" id="my-input-name" value="accentu&eacute;"/>',
165
            $res
166
        );
167
    }
168
169
    public function testInputUrl()
170
    {
171
        $res = FormItem::url('my-input-name', "accentué", 'Mon input');
172
        $this->assertEquals(
173
            '<label for="my-input-name">Mon input</label><input type="url" name="my-input-name" id="my-input-name" value="accentu&eacute;"/>',
174
            $res
175
        );
176
    }
177
178
    public function testInputEmail()
179
    {
180
        $res = FormItem::email('my-input-name', "accentué", 'Mon input');
181
        $this->assertEquals(
182
            '<label for="my-input-name">Mon input</label><input type="email" name="my-input-name" id="my-input-name" value="accentu&eacute;"/>',
183
            $res
184
        );
185
    }
186
187
    public function testInputSearch()
188
    {
189
        $res = FormItem::search('my-input-name', "accentué", 'Mon input');
190
        $this->assertEquals(
191
            '<label for="my-input-name">Mon input</label><input type="search" name="my-input-name" id="my-input-name" value="accentu&eacute;"/>',
192
            $res
193
        );
194
    }
195
196
    public function testInputDate()
197
    {
198
        $res = FormItem::date('my-input-name', "accentué", 'Mon input');
199
        $this->assertEquals(
200
            '<label for="my-input-name">Mon input</label><input type="date" name="my-input-name" id="my-input-name" value="accentu&eacute;"/>',
201
            $res
202
        );
203
    }
204
205
    public function testInputDateTime()
206
    {
207
        $res = FormItem::datetime('my-input-name', "accentué", 'Mon input');
208
        $this->assertEquals(
209
            '<label for="my-input-name">Mon input</label><input type="datetime" name="my-input-name" id="my-input-name" value="accentu&eacute;"/>',
210
            $res
211
        );
212
    }
213
214
    public function testInputTime()
215
    {
216
        $res = FormItem::time('my-input-name', "accentué", 'Mon input');
217
        $this->assertEquals(
218
            '<label for="my-input-name">Mon input</label><input type="time" name="my-input-name" id="my-input-name" value="accentu&eacute;"/>',
219
            $res
220
        );
221
    }
222
}
223