1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Helmut\Forms\Testing; |
4
|
|
|
|
5
|
|
|
class DropdownTest extends FormTestCase { |
6
|
|
|
|
7
|
|
|
/** @test */ |
8
|
|
View Code Duplication |
public function it_can_be_rendered() |
|
|
|
|
9
|
|
|
{ |
10
|
|
|
$form = $this->form(); |
11
|
|
|
$form->dropdown('foo')->options(['a'=>'A', 'b'=>'B', 'c'=>'C']); |
|
|
|
|
12
|
|
|
$this->assertContains('<select name="foo"', $form->render()); |
13
|
|
|
$this->assertContains('<option value="a">A</option>', $form->render()); |
14
|
|
|
$this->assertContains('<option value="b">B</option>', $form->render()); |
15
|
|
|
$this->assertContains('<option value="c">C</option>', $form->render()); |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
/** @test */ |
19
|
|
View Code Duplication |
public function it_renders_a_default_value() |
|
|
|
|
20
|
|
|
{ |
21
|
|
|
$form = $this->form(); |
22
|
|
|
$form->dropdown('foo')->options(['a'=>'A', 'b'=>'B', 'c'=>'C'])->default('b'); |
|
|
|
|
23
|
|
|
|
24
|
|
|
$this->assertContains('<option value="a">A</option>', $form->render()); |
25
|
|
|
$this->assertContains('<option value="b" selected="selected">B</option>', $form->render()); |
26
|
|
|
$this->assertContains('<option value="c">C</option>', $form->render()); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** @test */ |
30
|
|
View Code Duplication |
public function it_renders_model_values() |
|
|
|
|
31
|
|
|
{ |
32
|
|
|
$form = $this->form(); |
33
|
|
|
$form->defaults($this->model(['foo'=>'b'])); |
34
|
|
|
$form->dropdown('foo')->options(['a'=>'A', 'b'=>'B', 'c'=>'C']); |
|
|
|
|
35
|
|
|
|
36
|
|
|
$this->assertContains('<option value="a">A</option>', $form->render()); |
37
|
|
|
$this->assertContains('<option value="b" selected="selected">B</option>', $form->render()); |
38
|
|
|
$this->assertContains('<option value="c">C</option>', $form->render()); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** @test */ |
42
|
|
|
public function it_can_fill_model_values() |
43
|
|
|
{ |
44
|
|
|
$model = $this->model(['foo'=>'']); |
45
|
|
|
|
46
|
|
|
$form = $this->form(); |
47
|
|
|
$form->dropdown('foo')->options(['a'=>'A', 'b'=>'B', 'c'=>'C'])->default('b'); |
|
|
|
|
48
|
|
|
$form->fill($model); |
49
|
|
|
|
50
|
|
|
$form->assertEquals($model->foo, 'b'); |
|
|
|
|
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** @test */ |
54
|
|
View Code Duplication |
public function it_provides_expected_values() |
|
|
|
|
55
|
|
|
{ |
56
|
|
|
$form = $this->form(); |
57
|
|
|
$form->dropdown('foo')->options(['a'=>'A', 'b'=>'B', 'c'=>'C']); |
|
|
|
|
58
|
|
|
|
59
|
|
|
$this->assertSame($form->get('foo'), ''); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** @test */ |
63
|
|
View Code Duplication |
public function it_provides_expected_default_values() |
|
|
|
|
64
|
|
|
{ |
65
|
|
|
$form = $this->form(); |
66
|
|
|
$form->dropdown('foo')->options(['a'=>'A', 'b'=>'B', 'c'=>'C'])->default('c'); |
|
|
|
|
67
|
|
|
|
68
|
|
|
$this->assertSame($form->get('foo'), 'c'); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** @test */ |
72
|
|
|
public function it_validates_required() |
73
|
|
|
{ |
74
|
|
|
$this->assertValid(function($form) { $form->dropdown('foo')->options(['a'=>'A', 'b'=>'B', 'c'=>'C']); }); |
75
|
|
|
|
76
|
|
View Code Duplication |
$this->assertNotValid(function($form) { $form->dropdown('foo')->options(['a'=>'A', 'b'=>'B', 'c'=>'C'])->required(); }); |
|
|
|
|
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
} |
80
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.