1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Yiisoft\Yii\Bootstrap4\Tests; |
6
|
|
|
|
7
|
|
|
use Yiisoft\Yii\Bootstrap4\Html; |
8
|
|
|
use Yiisoft\Yii\Bootstrap4\Modal; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Tests for Modal widget. |
12
|
|
|
* |
13
|
|
|
* ModalTest. |
14
|
|
|
*/ |
15
|
|
|
final class ModalTest extends TestCase |
16
|
|
|
{ |
17
|
|
|
public function testBodyOptions(): void |
18
|
|
|
{ |
19
|
|
|
Modal::counter(0); |
20
|
|
|
|
21
|
|
|
$html = Modal::begin() |
22
|
|
|
->bodyOptions(['class' => 'modal-body test', 'style' => 'text-align:center;']) |
23
|
|
|
->closeButtonEnabled(false) |
24
|
|
|
->toggleButtonEnabled(false) |
25
|
|
|
->start(); |
26
|
|
|
|
27
|
|
|
$html .= Modal::end(); |
28
|
|
|
|
29
|
|
|
$expected = <<<HTML |
30
|
|
|
|
31
|
|
|
<div id="w0-modal" class="fade modal" role="dialog" tabindex="-1" aria-hidden="true"> |
32
|
|
|
<div class="modal-dialog "> |
33
|
|
|
<div class="modal-content"> |
34
|
|
|
|
35
|
|
|
<div class="modal-body test" style="text-align:center;"> |
36
|
|
|
|
37
|
|
|
</div> |
38
|
|
|
|
39
|
|
|
</div> |
40
|
|
|
</div> |
41
|
|
|
</div> |
42
|
|
|
HTML; |
43
|
|
|
|
44
|
|
|
$this->assertEqualsWithoutLE($expected, $html); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function testContainerOptions(): void |
48
|
|
|
{ |
49
|
|
|
Modal::counter(0); |
50
|
|
|
|
51
|
|
|
$html = Modal::begin() |
52
|
|
|
->title('Modal title') |
53
|
|
|
->toggleButtonEnabled(false) |
54
|
|
|
->footer( |
55
|
|
|
Html::button('Close', [ |
56
|
|
|
'type' => 'button', |
57
|
|
|
'class' => ['btn', 'btn-secondary'], |
58
|
|
|
'data' => [ |
59
|
|
|
'dismiss' => 'modal' |
60
|
|
|
] |
61
|
|
|
]) . "\n" . |
62
|
|
|
Html::button('Save changes', [ |
63
|
|
|
'type' => 'button', |
64
|
|
|
'class' => ['btn', 'btn-primary'] |
65
|
|
|
]) |
66
|
|
|
) |
67
|
|
|
->start(); |
68
|
|
|
|
69
|
|
|
$html .= '<p>Woohoo, you\'re reading this text in a modal!</p>'; |
70
|
|
|
|
71
|
|
|
$html .= Modal::end(); |
72
|
|
|
|
73
|
|
|
$expected = <<<HTML |
74
|
|
|
|
75
|
|
|
<div id="w0-modal" class="fade modal" role="dialog" tabindex="-1" aria-hidden="true" aria-labelledby="w0-modal-label"> |
76
|
|
|
<div class="modal-dialog "> |
77
|
|
|
<div class="modal-content"> |
78
|
|
|
<div class="modal-header"> |
79
|
|
|
<h5 id="w0-modal-label" class="modal-title">Modal title</h5> |
80
|
|
|
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span></button> |
81
|
|
|
</div> |
82
|
|
|
<div class="modal-body"> |
83
|
|
|
<p>Woohoo, you're reading this text in a modal!</p> |
84
|
|
|
</div> |
85
|
|
|
<div class="modal-footer"> |
86
|
|
|
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button> |
87
|
|
|
<button type="button" class="btn btn-primary">Save changes</button> |
88
|
|
|
</div> |
89
|
|
|
</div> |
90
|
|
|
</div> |
91
|
|
|
</div> |
92
|
|
|
HTML; |
93
|
|
|
|
94
|
|
|
$this->assertEqualsWithoutLE($expected, $html); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
public function testTriggerButton(): void |
98
|
|
|
{ |
99
|
|
|
Modal::counter(0); |
100
|
|
|
|
101
|
|
|
$html = Modal::begin() |
102
|
|
|
->toggleButton([ |
103
|
|
|
'class' => ['btn', 'btn-primary'], |
104
|
|
|
'label' => 'Launch demo modal' |
105
|
|
|
]) |
106
|
|
|
->title('Modal title') |
107
|
|
|
->footer( |
108
|
|
|
Html::button('Close', [ |
109
|
|
|
'type' => 'button', |
110
|
|
|
'class' => ['btn', 'btn-secondary'] |
111
|
|
|
]) . "\n" . |
112
|
|
|
Html::button('Save changes', [ |
113
|
|
|
'type' => 'button', |
114
|
|
|
'class' => ['btn', 'btn-primary'] |
115
|
|
|
]) |
116
|
|
|
) |
117
|
|
|
->start(); |
118
|
|
|
|
119
|
|
|
$html .= '<p>Woohoo, you\'re reading this text in a modal!</p>'; |
120
|
|
|
|
121
|
|
|
$html .= Modal::end(); |
122
|
|
|
|
123
|
|
|
$this->assertStringContainsString( |
124
|
|
|
'<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#w0-modal">Launch demo modal</button>', |
125
|
|
|
$html |
126
|
|
|
); |
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
|