Completed
Push — develop ( cca4ef...7bd965 )
by Mathieu
09:49
created

FormItemTest::testIsset()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 5
rs 10
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 testIsset()
32
    {
33
        $handler = new FormItem(['src' => 'http://']);
34
        $this->assertTrue(isset($handler->src));
0 ignored issues
show
Bug Best Practice introduced by
The property src does not exist on Suricate\FormItem. Since you implemented __get, consider adding a @property annotation.
Loading history...
35
        $this->assertFalse(isset($hander->value));
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $hander does not exist. Did you maybe mean $handler?
Loading history...
36
    }
37
38
    public function testInputText()
39
    {
40
        $res = FormItem::text('my-input-name', "accentué", 'Mon input');
41
        $this->assertEquals(
42
            '<label for="my-input-name">Mon input</label><input type="text" name="my-input-name" id="my-input-name" value="accentu&eacute;"/>',
43
            $res
44
        );
45
    }
46
47
    public function testInputPassword()
48
    {
49
        $res = FormItem::password('my-input-name', "accentué", 'Mon input');
50
        $this->assertEquals(
51
            '<label for="my-input-name">Mon input</label><input type="password" name="my-input-name" id="my-input-name" value="accentu&eacute;"/>',
52
            $res
53
        );
54
    }
55
56
    public function testInputNumber()
57
    {
58
        $res = FormItem::number('my-input-name', "accentué", 'Mon input');
59
        $this->assertEquals(
60
            '<label for="my-input-name">Mon input</label><input type="number" name="my-input-name" id="my-input-name" value="accentu&eacute;"/>',
61
            $res
62
        );
63
    }
64
65
    public function testInputButton()
66
    {
67
        $res = FormItem::button('my-input-name', "accentué", 'Mon input');
68
        $this->assertEquals(
69
            '<label for="my-input-name">Mon input</label><input type="button" name="my-input-name" id="my-input-name" value="accentu&eacute;"/>',
70
            $res
71
        );
72
    }
73
74
    public function testInputCheckbox()
75
    {
76
        $res = FormItem::checkbox('my-input-name', 2, true, 'Mon input');
77
        $this->assertEquals(
78
            '<label for="my-input-name">Mon input</label><input type="checkbox" name="my-input-name" id="my-input-name" value="2" checked="checked"/>',
79
            $res
80
        );
81
82
        $res = FormItem::checkbox('my-input-name', 2, false, 'Mon input');
83
        $this->assertEquals(
84
            '<label for="my-input-name">Mon input</label><input type="checkbox" name="my-input-name" id="my-input-name" value="2"/>',
85
            $res
86
        );
87
    }
88
89
    public function testInputRadio()
90
    {
91
        $res = FormItem::radio('my-input-name', [1, 2, 3], 2, 'Mon input');
92
        $this->assertEquals(
93
            '<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>',
94
            $res
95
        );
96
    }
97
98
    public function testInputReset()
99
    {
100
        $res = FormItem::reset('val');
101
        $this->assertEquals(
102
            '<input type="reset" value="val"/>',
103
            $res
104
        );
105
    }
106
107
    public function testInputSelect()
108
    {
109
        $res = FormItem::select('my-input-name', [1, 2, 3], 2, 'Mon input');
110
        $this->assertEquals(
111
            '<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>',
112
            $res
113
        );
114
115
        $res = FormItem::select('my-input-name', ["é\"" => ['a', 'b'], 2, 3 => ['c', 'd']], 2, 'Mon input');
116
        $this->assertEquals(
117
            '<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>',
118
            $res
119
        );
120
121
        $res = FormItem::select('my-input-name', ["é\"" => ['a', 'b'], 2, 3 => ['c', 'd']], 'c', 'Mon input');
122
        $this->assertEquals(
123
            '<label>Mon input</label><select name="my-input-name"><optgroup label="&eacute;&quot;"><option value="0" selected>a</option><option value="1">b</option></optgroup><option value="0" selected>2</option><optgroup label="3"><option value="0" selected>c</option><option value="1">d</option></optgroup></select>',
124
            $res
125
        );
126
127
        $res = FormItem::select('my-input-name', [1, 2, 3], [2, 1], 'Mon input');
128
        $this->assertEquals(
129
            '<label>Mon input</label><select name="my-input-name"><option value="0">1</option><option value="1" selected>2</option><option value="2" selected>3</option></select>',
130
            $res
131
        );
132
    }
133
134
    public function testInputFile()
135
    {
136
        $res = FormItem::file('my-input-name', "Mon input");
137
        $this->assertEquals(
138
            '<label for="my-input-name">Mon input</label><input type="file" name="my-input-name" id="my-input-name"/>',
139
            $res
140
        );
141
    }
142
143
    public function testInputHidden()
144
    {
145
        $res = FormItem::hidden('my-input-name', "accentué");
146
        $this->assertEquals(
147
            '<input type="hidden" name="my-input-name" value="accentu&eacute;"/>',
148
            $res
149
        );
150
    }
151
152
    public function testInputImage()
153
    {
154
        $res = FormItem::image('my-input-name', "https://gsuite.google.com/img/icons/product-lockup.png");
155
        $this->assertEquals(
156
            '<input type="image" name="my-input-name" src="https://gsuite.google.com/img/icons/product-lockup.png"/>',
157
            $res
158
        );
159
    }
160
161
    public function testInputSubmit()
162
    {
163
        $res = FormItem::submit('my-input-name', "accentué", 'Mon input');
164
        $this->assertEquals(
165
            '<label for="my-input-name">Mon input</label><input type="submit" name="my-input-name" id="my-input-name" value="accentu&eacute;"/>',
166
            $res
167
        );
168
    }
169
170
    public function testInputTextarea()
171
    {
172
        $res = FormItem::textarea('my-input-name', "accentué", 'Mon input');
173
        $this->assertEquals(
174
            '<label for="my-input-name">Mon input</label><textarea name="my-input-name" id="my-input-name">accentué</textarea>',
175
            $res
176
        );
177
    }
178
179
    public function testInputTel()
180
    {
181
        $res = FormItem::tel('my-input-name', "accentué", 'Mon input');
182
        $this->assertEquals(
183
            '<label for="my-input-name">Mon input</label><input type="tel" name="my-input-name" id="my-input-name" value="accentu&eacute;"/>',
184
            $res
185
        );
186
    }
187
188
    public function testInputUrl()
189
    {
190
        $res = FormItem::url('my-input-name', "accentué", 'Mon input');
191
        $this->assertEquals(
192
            '<label for="my-input-name">Mon input</label><input type="url" name="my-input-name" id="my-input-name" value="accentu&eacute;"/>',
193
            $res
194
        );
195
    }
196
197
    public function testInputEmail()
198
    {
199
        $res = FormItem::email('my-input-name', "accentué", 'Mon input');
200
        $this->assertEquals(
201
            '<label for="my-input-name">Mon input</label><input type="email" name="my-input-name" id="my-input-name" value="accentu&eacute;"/>',
202
            $res
203
        );
204
    }
205
206
    public function testInputSearch()
207
    {
208
        $res = FormItem::search('my-input-name', "accentué", 'Mon input');
209
        $this->assertEquals(
210
            '<label for="my-input-name">Mon input</label><input type="search" name="my-input-name" id="my-input-name" value="accentu&eacute;"/>',
211
            $res
212
        );
213
    }
214
215
    public function testInputDate()
216
    {
217
        $res = FormItem::date('my-input-name', "accentué", 'Mon input');
218
        $this->assertEquals(
219
            '<label for="my-input-name">Mon input</label><input type="date" name="my-input-name" id="my-input-name" value="accentu&eacute;"/>',
220
            $res
221
        );
222
    }
223
224
    public function testInputDateTime()
225
    {
226
        $res = FormItem::datetime('my-input-name', "accentué", 'Mon input');
227
        $this->assertEquals(
228
            '<label for="my-input-name">Mon input</label><input type="datetime" name="my-input-name" id="my-input-name" value="accentu&eacute;"/>',
229
            $res
230
        );
231
    }
232
233
    public function testInputTime()
234
    {
235
        $res = FormItem::time('my-input-name', "accentué", 'Mon input');
236
        $this->assertEquals(
237
            '<label for="my-input-name">Mon input</label><input type="time" name="my-input-name" id="my-input-name" value="accentu&eacute;"/>',
238
            $res
239
        );
240
    }
241
}
242