1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace FlexPHP\Inputs\Tests\Unit; |
4
|
|
|
|
5
|
|
|
use FlexPHP\Inputs\Input; |
6
|
|
|
use FlexPHP\Inputs\Tests\TestCase; |
7
|
|
|
use InvalidArgumentException; |
8
|
|
|
|
9
|
|
|
class InputTest extends TestCase |
10
|
|
|
{ |
11
|
|
|
public function testItCreateTypeNotValidThrownException(): void |
12
|
|
|
{ |
13
|
|
|
$this->expectException(InvalidArgumentException::class); |
14
|
|
|
$this->expectExceptionMessage('supported'); |
15
|
|
|
|
16
|
|
|
Input::create('unknow', 'foo'); |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
public function testItMethodTypeNotValidThrownException(): void |
20
|
|
|
{ |
21
|
|
|
$this->expectException(InvalidArgumentException::class); |
22
|
|
|
$this->expectExceptionMessage('supported'); |
23
|
|
|
|
24
|
|
|
Input::unknow('foo'); |
|
|
|
|
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @dataProvider getTypeNameOptions |
29
|
|
|
*/ |
30
|
|
|
public function testItRenderCreateText($type): void |
31
|
|
|
{ |
32
|
|
|
$render = Input::create($type, 'foo'); |
33
|
|
|
|
34
|
|
|
$this->assertEquals(<<<'T' |
35
|
|
|
<div class="form-group"><label for="form_foo">Foo</label><input type="text" id="form_foo" name="form[foo]" class="form-control" /></div> |
36
|
|
|
T, $render); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function testItRenderMethodType(): void |
40
|
|
|
{ |
41
|
|
|
$render = Input::text('foo'); |
42
|
|
|
|
43
|
|
|
$this->assertEquals(<<<'T' |
44
|
|
|
<div class="form-group"><label for="form_foo">Foo</label><input type="text" id="form_foo" name="form[foo]" class="form-control" /></div> |
45
|
|
|
T, $render); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function testItRenderMethodForm(): void |
49
|
|
|
{ |
50
|
|
|
$render = Input::form([]); |
51
|
|
|
|
52
|
|
|
$this->assertEquals(<<<'T' |
53
|
|
|
<form name="form" method="post"> |
54
|
|
|
</form> |
55
|
|
|
T, $render); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function getTypeNameOptions(): array |
59
|
|
|
{ |
60
|
|
|
return [ |
61
|
|
|
['text'], |
62
|
|
|
[' text '], |
63
|
|
|
[' text'], |
64
|
|
|
['text '], |
65
|
|
|
['TEXT '], |
66
|
|
|
['textType'], |
67
|
|
|
[' textType '], |
68
|
|
|
[' textType'], |
69
|
|
|
['textType '], |
70
|
|
|
['TextType '], |
71
|
|
|
['Texttype '], |
72
|
|
|
['texttype '], |
73
|
|
|
['TEXTTYPE '], |
74
|
|
|
]; |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|