1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace FlexPHP\Inputs\Tests\Unit\Builder; |
4
|
|
|
|
5
|
|
|
use FlexPHP\Inputs\Builder\FormBuilder; |
6
|
|
|
use FlexPHP\Inputs\Tests\TestCase; |
7
|
|
|
|
8
|
|
|
class FormBuilderTest extends TestCase |
9
|
|
|
{ |
10
|
|
|
public function testItDefault(): void |
11
|
|
|
{ |
12
|
|
|
$render = (new FormBuilder('form', []))->render(); |
13
|
|
|
|
14
|
|
|
$this->assertEquals(<<<'T' |
15
|
|
|
<form name="form" method="post"> |
16
|
|
|
</form> |
17
|
|
|
T, $render); |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
public function testItWithInputRender(): void |
21
|
|
|
{ |
22
|
|
|
$render = (new FormBuilder('form', [ |
23
|
|
|
'foo' => '<div class="form-group"><label for="form_foo">Foo</label><input type="text" id="form_foo" name="form[foo]" class="form-control" /></div>', |
24
|
|
|
]))->render(); |
25
|
|
|
|
26
|
|
|
$this->assertEquals(<<<'T' |
27
|
|
|
<form name="form" method="post"> |
28
|
|
|
<div class="form-group"><label for="form_foo">Foo</label><input type="text" id="form_foo" name="form[foo]" class="form-control" /></div> |
29
|
|
|
</form> |
30
|
|
|
T, $render); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function testItWithInputOptions(): void |
34
|
|
|
{ |
35
|
|
|
$render = (new FormBuilder('form', [ |
36
|
|
|
'foo' => [ |
37
|
|
|
'type' => 'email', |
38
|
|
|
], |
39
|
|
|
]))->render(); |
40
|
|
|
|
41
|
|
|
$this->assertEquals(<<<'T' |
42
|
|
|
<form name="form" method="post"> |
43
|
|
|
<div class="form-group"><label for="form_foo">Foo</label><input type="email" id="form_foo" name="form[foo]" class="form-control" /></div> |
44
|
|
|
</form> |
45
|
|
|
T, $render); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function testItWithInputs(): void |
49
|
|
|
{ |
50
|
|
|
$render = (new FormBuilder('form', [ |
51
|
|
|
'foo' => [ |
52
|
|
|
'type' => 'email', |
53
|
|
|
], |
54
|
|
|
'bar' => [ |
55
|
|
|
'type' => 'textarea', |
56
|
|
|
], |
57
|
|
|
]))->render(); |
58
|
|
|
|
59
|
|
|
$this->assertEquals(<<<'T' |
60
|
|
|
<form name="form" method="post"> |
61
|
|
|
<div class="form-group"><label for="form_foo">Foo</label><input type="email" id="form_foo" name="form[foo]" class="form-control" /></div> |
62
|
|
|
<div class="form-group"><label for="form_bar">Bar</label><textarea id="form_bar" name="form[bar]" class="form-control"></textarea></div> |
63
|
|
|
</form> |
64
|
|
|
T, $render); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function testItWithStringTemplate(): void |
68
|
|
|
{ |
69
|
|
|
$render = (new FormBuilder('form', [], null, [], '{{ form(form) }}'))->render(); |
70
|
|
|
|
71
|
|
|
$this->assertEquals(<<<'T' |
72
|
|
|
<form name="form" method="post"><div id="form"></div></form> |
73
|
|
|
T, $render); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public function testItWithFileTemplate(): void |
77
|
|
|
{ |
78
|
|
|
$file = \sprintf('%1$s/../../Resources/Template.html.twig', __DIR__); |
79
|
|
|
|
80
|
|
|
$render = (new FormBuilder('form', [], null, [], $file))->render(); |
81
|
|
|
|
82
|
|
|
$this->assertEquals(<<<'T' |
83
|
|
|
File: <form name="form" method="post"><div id="form"></div></form> |
84
|
|
|
T, $render); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|