|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Yiisoft\Yii\Bootstrap4\Tests; |
|
6
|
|
|
|
|
7
|
|
|
use Yiisoft\Yii\Bootstrap4\ButtonDropdown; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Tests for ButtonDropdown widget |
|
11
|
|
|
* |
|
12
|
|
|
* ButtonDropdownTest |
|
13
|
|
|
*/ |
|
14
|
|
|
final class ButtonDropdownTest extends TestCase |
|
15
|
|
|
{ |
|
16
|
|
|
public function testContainerOptions(): void |
|
17
|
|
|
{ |
|
18
|
|
|
$containerClass = 'testClass'; |
|
19
|
|
|
|
|
20
|
|
|
ButtonDropdown::counter(0); |
|
21
|
|
|
|
|
22
|
|
|
$html = ButtonDropdown::widget() |
|
23
|
|
|
->direction(ButtonDropdown::DIRECTION_UP) |
|
24
|
|
|
->options([ |
|
25
|
|
|
'class' => $containerClass, |
|
26
|
|
|
]) |
|
27
|
|
|
->label('Action') |
|
28
|
|
|
->dropdown([ |
|
29
|
|
|
'items' => [ |
|
30
|
|
|
['label' => 'DropdownA', 'url' => '/'], |
|
31
|
|
|
['label' => 'DropdownB', 'url' => '#'], |
|
32
|
|
|
], |
|
33
|
|
|
]) |
|
34
|
|
|
->render(); |
|
35
|
|
|
|
|
36
|
|
|
$this->assertStringContainsString("$containerClass dropup btn-group", $html); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function testDirection(): void |
|
40
|
|
|
{ |
|
41
|
|
|
ButtonDropdown::counter(0); |
|
42
|
|
|
|
|
43
|
|
|
$html = ButtonDropdown::widget() |
|
44
|
|
|
->direction(ButtonDropdown::DIRECTION_LEFT) |
|
45
|
|
|
->label('Action') |
|
46
|
|
|
->dropdown([ |
|
47
|
|
|
'items' => [ |
|
48
|
|
|
['label' => 'ItemA', 'url' => '#'], |
|
49
|
|
|
['label' => 'ItemB', 'url' => '#'], |
|
50
|
|
|
], |
|
51
|
|
|
]) |
|
52
|
|
|
->render(); |
|
53
|
|
|
|
|
54
|
|
|
$expected = <<<EXPECTED |
|
55
|
|
|
<div id="w0-button-dropdown" class="dropleft btn-group"><button id="w0-button" class="btn dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Action</button> |
|
56
|
|
|
|
|
57
|
|
|
<div id="w1-dropdown" class="dropdown-menu"><a class="dropdown-item" href="#">ItemA</a> |
|
58
|
|
|
<a class="dropdown-item" href="#">ItemB</a></div></div> |
|
59
|
|
|
EXPECTED; |
|
60
|
|
|
|
|
61
|
|
|
$this->assertEqualsWithoutLE($expected, $html); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function testSplit(): void |
|
65
|
|
|
{ |
|
66
|
|
|
ButtonDropdown::counter(0); |
|
67
|
|
|
|
|
68
|
|
|
$html = ButtonDropdown::widget() |
|
69
|
|
|
->direction(ButtonDropdown::DIRECTION_DOWN) |
|
70
|
|
|
->label('Split dropdown') |
|
71
|
|
|
->split(true) |
|
72
|
|
|
->dropdown([ |
|
73
|
|
|
'items' => [ |
|
74
|
|
|
['label' => 'ItemA', 'url' => '#'], |
|
75
|
|
|
['label' => 'ItemB', 'url' => '#'] |
|
76
|
|
|
] |
|
77
|
|
|
]) |
|
78
|
|
|
->render(); |
|
79
|
|
|
|
|
80
|
|
|
$expected = <<<EXPECTED |
|
81
|
|
|
<div id="w0-button-dropdown" class="dropdown btn-group"><button id="w1-button" class="btn">Split dropdown</button> |
|
82
|
|
|
<button id="w0-button" class="btn dropdown-toggle dropdown-toggle-split" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><span class="sr-only">Toggle Dropdown</span></button> |
|
83
|
|
|
<div id="w2-dropdown" class="dropdown-menu"><a class="dropdown-item" href="#">ItemA</a> |
|
84
|
|
|
<a class="dropdown-item" href="#">ItemB</a></div></div> |
|
85
|
|
|
EXPECTED; |
|
86
|
|
|
|
|
87
|
|
|
$this->assertEqualsWithoutLE($expected, $html); |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|