1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Yiisoft\Yii\Bootstrap4\Tests; |
6
|
|
|
|
7
|
|
|
use Yiisoft\Yii\Bootstrap4\ButtonGroup; |
8
|
|
|
use Yiisoft\Yii\Bootstrap4\ButtonToolbar; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Tests for ButtonToolbar widget. |
12
|
|
|
* |
13
|
|
|
* ButtonToolbarTest |
14
|
|
|
*/ |
15
|
|
|
final class ButtonToolbarTest extends TestCase |
16
|
|
|
{ |
17
|
|
|
public function testContainerOptions(): void |
18
|
|
|
{ |
19
|
|
|
ButtonToolbar::counter(0); |
20
|
|
|
|
21
|
|
|
$html = ButtonToolbar::widget() |
22
|
|
|
->options([ |
23
|
|
|
'aria-label' => 'Toolbar with button groups' |
24
|
|
|
]) |
25
|
|
|
->buttonGroups([ |
26
|
|
|
ButtonGroup::widget() |
27
|
|
|
->options([ |
28
|
|
|
'aria-label' => 'First group', |
29
|
|
|
'class' => ['mr-2'] |
30
|
|
|
]) |
31
|
|
|
->buttons([ |
32
|
|
|
['label' => '1'], |
33
|
|
|
['label' => '2'], |
34
|
|
|
['label' => '3'], |
35
|
|
|
['label' => '4'] |
36
|
|
|
]) |
37
|
|
|
->render(), |
38
|
|
|
[ |
39
|
|
|
'options' => [ |
40
|
|
|
'aria-label' => 'Second group' |
41
|
|
|
], |
42
|
|
|
'buttons' => [ |
43
|
|
|
['label' => '5'], |
44
|
|
|
['label' => '6'], |
45
|
|
|
['label' => '7'] |
46
|
|
|
] |
47
|
|
|
] |
48
|
|
|
]) |
49
|
|
|
->render(); |
50
|
|
|
|
51
|
|
|
$expected = <<<HTML |
52
|
|
|
<div id="w5-button-toolbar" class="btn-toolbar" aria-label="Toolbar with button groups" role="toolbar"><div id="w0-button-group" class="mr-2 btn-group" aria-label="First group" role="group"><button type="button" id="w1-button" class="btn">1</button> |
53
|
|
|
<button type="button" id="w2-button" class="btn">2</button> |
54
|
|
|
<button type="button" id="w3-button" class="btn">3</button> |
55
|
|
|
<button type="button" id="w4-button" class="btn">4</button></div> |
56
|
|
|
<div id="w6-button-group" class="btn-group" aria-label="Second group" role="group"><button type="button" id="w7-button" class="btn">5</button> |
57
|
|
|
<button type="button" id="w8-button" class="btn">6</button> |
58
|
|
|
<button type="button" id="w9-button" class="btn">7</button></div></div> |
59
|
|
|
HTML; |
60
|
|
|
|
61
|
|
|
$this->assertEqualsWithoutLE($expected, $html); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function testAdditionalContent(): void |
65
|
|
|
{ |
66
|
|
|
$addHtml = <<<HTML |
67
|
|
|
<div class="input-group"> |
68
|
|
|
<div class="input-group-prepend"> |
69
|
|
|
<div class="input-group-text" id="btnGroupAddon">@</div> |
70
|
|
|
</div> |
71
|
|
|
<input type="text" class="form-control" placeholder="Input group example" aria-label="Input group example" aria-describedby="btnGroupAddon"> |
72
|
|
|
</div> |
73
|
|
|
HTML; |
74
|
|
|
|
75
|
|
|
ButtonToolbar::counter(0); |
76
|
|
|
|
77
|
|
|
$html = ButtonToolbar::widget() |
78
|
|
|
->options([ |
79
|
|
|
'aria-label' => 'Toolbar with button groups' |
80
|
|
|
]) |
81
|
|
|
->buttonGroups([ |
82
|
|
|
[ |
83
|
|
|
'options' => [ |
84
|
|
|
'aria-label' => 'First group', |
85
|
|
|
'class' => ['mr-2'] |
86
|
|
|
], |
87
|
|
|
'buttons' => [ |
88
|
|
|
['label' => '1'], |
89
|
|
|
['label' => '2'], |
90
|
|
|
['label' => '3'], |
91
|
|
|
['label' => '4'] |
92
|
|
|
] |
93
|
|
|
], |
94
|
|
|
$addHtml |
95
|
|
|
]) |
96
|
|
|
->render(); |
97
|
|
|
|
98
|
|
|
$expected = <<<HTML |
99
|
|
|
<div id="w0-button-toolbar" class="btn-toolbar" aria-label="Toolbar with button groups" role="toolbar"><div id="w1-button-group" class="mr-2 btn-group" aria-label="First group" role="group"><button type="button" id="w2-button" class="btn">1</button> |
100
|
|
|
<button type="button" id="w3-button" class="btn">2</button> |
101
|
|
|
<button type="button" id="w4-button" class="btn">3</button> |
102
|
|
|
<button type="button" id="w5-button" class="btn">4</button></div> |
103
|
|
|
<div class="input-group"> |
104
|
|
|
<div class="input-group-prepend"> |
105
|
|
|
<div class="input-group-text" id="btnGroupAddon">@</div> |
106
|
|
|
</div> |
107
|
|
|
<input type="text" class="form-control" placeholder="Input group example" aria-label="Input group example" aria-describedby="btnGroupAddon"> |
108
|
|
|
</div></div> |
109
|
|
|
HTML; |
110
|
|
|
|
111
|
|
|
$this->assertEqualsWithoutLE($expected, $html); |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
|