|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Nip\Form\Tests\Renderer\Elements; |
|
4
|
|
|
|
|
5
|
|
|
use Nip\Form\Tests\AbstractTest; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Class RadioGroupTest |
|
9
|
|
|
* @package Nip\Form\Tests\Renderer\Elements |
|
10
|
|
|
*/ |
|
11
|
|
|
class RadioGroupTest extends AbstractTest |
|
12
|
|
|
{ |
|
13
|
|
|
public function testRenderEmptyElement() |
|
14
|
|
|
{ |
|
15
|
|
|
$renderer = $this->generateTestRenderer(); |
|
16
|
|
|
$html = $renderer->render(); |
|
17
|
|
|
|
|
18
|
|
|
self::assertSame('', $html); |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
View Code Duplication |
public function testRenderSimpleElement() |
|
|
|
|
|
|
22
|
|
|
{ |
|
23
|
|
|
$renderer = $this->generateTestRenderer(); |
|
24
|
|
|
$renderer->getElement()->addOption('123', 'Age'); |
|
25
|
|
|
$renderer->getElement()->addOption('789', 'Height'); |
|
26
|
|
|
$html = $renderer->render(); |
|
27
|
|
|
|
|
28
|
|
|
self::assertSame( |
|
29
|
|
|
'<div class="form-check">' |
|
30
|
|
|
.'<label class="form-check-label">' |
|
31
|
|
|
.'<input type="radio" name="" value="123" checked="checked" class="form-check-input " title="Age" />' |
|
32
|
|
|
.'Age' |
|
33
|
|
|
.'</label>' |
|
34
|
|
|
.'</div><br />' |
|
35
|
|
|
.'<div class="form-check">' |
|
36
|
|
|
.'<label class="form-check-label">' |
|
37
|
|
|
.'<input type="radio" name="" value="789" class="form-check-input " title="Height" />' |
|
38
|
|
|
.'Height' |
|
39
|
|
|
.'</label>' |
|
40
|
|
|
.'</div>', |
|
41
|
|
|
$html |
|
42
|
|
|
); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
View Code Duplication |
public function testRenderAutoSelectFirstFalse() |
|
|
|
|
|
|
46
|
|
|
{ |
|
47
|
|
|
$renderer = $this->generateTestRenderer(); |
|
48
|
|
|
$renderer->getElement()->autoSelectFirst(false); |
|
49
|
|
|
$renderer->getElement()->addOption('123', 'Age'); |
|
50
|
|
|
$renderer->getElement()->addOption('789', 'Height'); |
|
51
|
|
|
$html = $renderer->render(); |
|
52
|
|
|
|
|
53
|
|
|
self::assertSame( |
|
54
|
|
|
'<div class="form-check">' |
|
55
|
|
|
.'<label class="form-check-label">' |
|
56
|
|
|
.'<input type="radio" name="" value="123" class="form-check-input " title="Age" />' |
|
57
|
|
|
.'Age' |
|
58
|
|
|
.'</label>' |
|
59
|
|
|
.'</div><br />' |
|
60
|
|
|
.'<div class="form-check">' |
|
61
|
|
|
.'<label class="form-check-label">' |
|
62
|
|
|
.'<input type="radio" name="" value="789" class="form-check-input " title="Height" />' |
|
63
|
|
|
.'Height' |
|
64
|
|
|
.'</label>' |
|
65
|
|
|
.'</div>', |
|
66
|
|
|
$html |
|
67
|
|
|
); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @return \Nip_Form_Renderer_Elements_RadioGroup |
|
72
|
|
|
*/ |
|
73
|
|
|
protected function generateTestRenderer() |
|
74
|
|
|
{ |
|
75
|
|
|
$input = new \Nip_Form_Element_RadioGroup(new \Nip\Form\Form()); |
|
76
|
|
|
$render = new \Nip_Form_Renderer_Elements_RadioGroup(); |
|
77
|
|
|
$render->setElement($input); |
|
78
|
|
|
return $render; |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|
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.