2021-07-09 17:53:24 +08:00
|
|
|
<?php
|
2021-08-04 14:21:51 +08:00
|
|
|
|
2021-07-09 17:53:24 +08:00
|
|
|
namespace yiiunit\extensions\bootstrap5;
|
|
|
|
|
|
|
|
use yii\bootstrap5\Dropdown;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests for Dropdown widget
|
|
|
|
*
|
|
|
|
* @group bootstrap5
|
|
|
|
*/
|
|
|
|
class DropdownTest extends TestCase
|
|
|
|
{
|
|
|
|
public function testIds()
|
|
|
|
{
|
|
|
|
Dropdown::$counter = 0;
|
|
|
|
$out = Dropdown::widget(
|
|
|
|
[
|
|
|
|
'items' => [
|
|
|
|
[
|
|
|
|
'label' => 'Page1'
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'label' => 'Dropdown1',
|
|
|
|
'url' => '#test',
|
|
|
|
'items' => [
|
|
|
|
['label' => 'Page2'],
|
|
|
|
['label' => 'Page3'],
|
|
|
|
]
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'label' => 'Dropdown2',
|
|
|
|
'visible' => false,
|
|
|
|
'items' => [
|
|
|
|
['label' => 'Page4', 'content' => 'Page4'],
|
|
|
|
['label' => 'Page5', 'content' => 'Page5'],
|
|
|
|
]
|
|
|
|
]
|
|
|
|
]
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
|
|
|
$expected = <<<EXPECTED
|
|
|
|
<div id="w0" class="dropdown-menu"><h6 class="dropdown-header">Page1</h6>
|
|
|
|
<div class="dropdown" aria-expanded="false">
|
2021-07-12 23:22:29 +08:00
|
|
|
<a class="dropdown-item dropdown-toggle" href="#test" data-bs-toggle="dropdown" aria-expanded="false" role="button">Dropdown1</a>
|
2021-07-09 17:53:24 +08:00
|
|
|
<div id="w1" class="dropdown-submenu dropdown-menu"><h6 class="dropdown-header">Page2</h6>
|
|
|
|
<h6 class="dropdown-header">Page3</h6></div>
|
|
|
|
</div></div>
|
|
|
|
EXPECTED;
|
|
|
|
|
|
|
|
$this->assertEqualsWithoutLE($expected, $out);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testSubMenuOptions()
|
|
|
|
{
|
|
|
|
Dropdown::$counter = 0;
|
|
|
|
$out = Dropdown::widget(
|
|
|
|
[
|
|
|
|
'submenuOptions' => [
|
|
|
|
'class' => 'submenu-list',
|
|
|
|
],
|
|
|
|
'items' => [
|
|
|
|
[
|
|
|
|
'label' => 'Dropdown1',
|
|
|
|
'items' => [
|
|
|
|
['label' => 'Page1', 'content' => 'Page2'],
|
|
|
|
['label' => 'Page2', 'content' => 'Page3'],
|
|
|
|
]
|
|
|
|
],
|
|
|
|
'-',
|
|
|
|
[
|
|
|
|
'label' => 'Dropdown2',
|
|
|
|
'items' => [
|
|
|
|
['label' => 'Page3', 'content' => 'Page4'],
|
|
|
|
['label' => 'Page4', 'content' => 'Page5'],
|
|
|
|
],
|
|
|
|
'submenuOptions' => [
|
|
|
|
'class' => 'submenu-override',
|
|
|
|
],
|
|
|
|
]
|
|
|
|
]
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
|
|
|
$expected = <<<EXPECTED
|
|
|
|
<div id="w0" class="dropdown-menu"><div class="dropdown" aria-expanded="false">
|
2021-07-12 23:22:29 +08:00
|
|
|
<a class="dropdown-item dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false" role="button">Dropdown1</a>
|
2021-07-09 17:53:24 +08:00
|
|
|
<div id="w1" class="submenu-list dropdown-submenu dropdown-menu"><h6 class="dropdown-header">Page1</h6>
|
|
|
|
<h6 class="dropdown-header">Page2</h6></div>
|
|
|
|
</div>
|
2021-07-12 23:22:29 +08:00
|
|
|
<hr class="dropdown-divider">
|
2021-07-09 17:53:24 +08:00
|
|
|
<div class="dropdown" aria-expanded="false">
|
2021-07-12 23:22:29 +08:00
|
|
|
<a class="dropdown-item dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false" role="button">Dropdown2</a>
|
2021-07-09 17:53:24 +08:00
|
|
|
<div id="w2" class="submenu-override dropdown-submenu dropdown-menu"><h6 class="dropdown-header">Page3</h6>
|
|
|
|
<h6 class="dropdown-header">Page4</h6></div>
|
|
|
|
</div></div>
|
|
|
|
EXPECTED;
|
|
|
|
|
|
|
|
$this->assertEqualsWithoutLE($expected, $out);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testActive()
|
|
|
|
{
|
|
|
|
Dropdown::$counter = 0;
|
|
|
|
$out = Dropdown::widget(
|
|
|
|
[
|
|
|
|
'submenuOptions' => [
|
|
|
|
'class' => 'submenu-list',
|
|
|
|
],
|
|
|
|
'items' => [
|
|
|
|
[
|
|
|
|
'label' => 'Dropdown1',
|
|
|
|
'items' => [
|
|
|
|
['label' => 'Page1', 'content' => 'Page2'],
|
|
|
|
['label' => 'Page2', 'content' => 'Page3'],
|
|
|
|
]
|
|
|
|
],
|
|
|
|
'-',
|
|
|
|
[
|
|
|
|
'label' => 'Dropdown2',
|
|
|
|
'items' => [
|
|
|
|
['label' => 'Page3', 'content' => 'Page3', 'url' => '/', 'active' => true],
|
|
|
|
['label' => 'Page4', 'content' => 'Page4'],
|
|
|
|
],
|
|
|
|
]
|
|
|
|
]
|
|
|
|
]
|
|
|
|
);
|
|
|
|
$expected = <<<HTML
|
|
|
|
<div id="w0" class="dropdown-menu"><div class="dropdown" aria-expanded="false">
|
2021-07-12 23:22:29 +08:00
|
|
|
<a class="dropdown-item dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false" role="button">Dropdown1</a>
|
2021-07-09 17:53:24 +08:00
|
|
|
<div id="w1" class="submenu-list dropdown-submenu dropdown-menu"><h6 class="dropdown-header">Page1</h6>
|
|
|
|
<h6 class="dropdown-header">Page2</h6></div>
|
|
|
|
</div>
|
2021-07-12 23:22:29 +08:00
|
|
|
<hr class="dropdown-divider">
|
2021-07-09 17:53:24 +08:00
|
|
|
<div class="dropdown" aria-expanded="false">
|
2021-07-12 23:22:29 +08:00
|
|
|
<a class="dropdown-item dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false" role="button">Dropdown2</a>
|
|
|
|
<div id="w2" class="submenu-list dropdown-submenu dropdown-menu"><a class="dropdown-item active" href="/" aria-current="true">Page3</a>
|
2021-07-09 17:53:24 +08:00
|
|
|
<h6 class="dropdown-header">Page4</h6></div>
|
|
|
|
</div></div>
|
|
|
|
HTML;
|
|
|
|
$this->assertEqualsWithoutLE($expected, $out);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testDisabled()
|
|
|
|
{
|
|
|
|
Dropdown::$counter = 0;
|
|
|
|
$out = Dropdown::widget(
|
|
|
|
[
|
|
|
|
'submenuOptions' => [
|
|
|
|
'class' => 'submenu-list',
|
|
|
|
],
|
|
|
|
'items' => [
|
|
|
|
[
|
|
|
|
'label' => 'Dropdown1',
|
|
|
|
'items' => [
|
|
|
|
['label' => 'Page1', 'content' => 'Page2'],
|
|
|
|
['label' => 'Page2', 'content' => 'Page3'],
|
|
|
|
],
|
|
|
|
'disabled' => true
|
|
|
|
],
|
|
|
|
'-',
|
|
|
|
[
|
|
|
|
'label' => 'Dropdown2',
|
|
|
|
'items' => [
|
|
|
|
['label' => 'Page3', 'content' => 'Page3'],
|
|
|
|
['label' => 'Page4', 'content' => 'Page4'],
|
|
|
|
],
|
|
|
|
]
|
|
|
|
]
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
|
|
|
$expected = <<<HTML
|
|
|
|
<div id="w0" class="dropdown-menu"><div class="dropdown" aria-expanded="false">
|
2022-01-03 16:40:20 +08:00
|
|
|
<a class="dropdown-item disabled dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false" aria-disabled="true" role="button" tabindex="-1">Dropdown1</a>
|
2021-07-09 17:53:24 +08:00
|
|
|
<div id="w1" class="submenu-list dropdown-submenu dropdown-menu"><h6 class="dropdown-header">Page1</h6>
|
|
|
|
<h6 class="dropdown-header">Page2</h6></div>
|
|
|
|
</div>
|
2021-07-12 23:22:29 +08:00
|
|
|
<hr class="dropdown-divider">
|
2021-07-09 17:53:24 +08:00
|
|
|
<div class="dropdown" aria-expanded="false">
|
2021-07-12 23:22:29 +08:00
|
|
|
<a class="dropdown-item dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false" role="button">Dropdown2</a>
|
2021-07-09 17:53:24 +08:00
|
|
|
<div id="w2" class="submenu-list dropdown-submenu dropdown-menu"><h6 class="dropdown-header">Page3</h6>
|
|
|
|
<h6 class="dropdown-header">Page4</h6></div>
|
|
|
|
</div></div>
|
|
|
|
HTML;
|
|
|
|
|
|
|
|
$this->assertEqualsWithoutLE($expected, $out);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testForms()
|
|
|
|
{
|
|
|
|
Dropdown::$counter = 0;
|
|
|
|
$form = <<<HTML
|
|
|
|
<form class="px-4 py-3">
|
2021-07-12 23:22:29 +08:00
|
|
|
<div class="mb-3">
|
|
|
|
<label class="form-label" for="exampleDropdownFormEmail1">Email address</label>
|
2021-07-09 17:53:24 +08:00
|
|
|
<input type="email" class="form-control" id="exampleDropdownFormEmail1" placeholder="email@example.com">
|
|
|
|
</div>
|
2021-07-12 23:22:29 +08:00
|
|
|
<div class="mb-3">
|
|
|
|
<label class="form-label" for="exampleDropdownFormPassword1">Password</label>
|
2021-07-09 17:53:24 +08:00
|
|
|
<input type="password" class="form-control" id="exampleDropdownFormPassword1" placeholder="Password">
|
|
|
|
</div>
|
|
|
|
<div class="form-check">
|
|
|
|
<input type="checkbox" class="form-check-input" id="dropdownCheck">
|
|
|
|
<label class="form-check-label" for="dropdownCheck">
|
|
|
|
Remember me
|
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
<button type="submit" class="btn btn-primary">Sign in</button>
|
|
|
|
</form>
|
|
|
|
HTML;
|
|
|
|
|
|
|
|
$out = Dropdown::widget([
|
|
|
|
'items' => [
|
|
|
|
$form,
|
|
|
|
'-',
|
|
|
|
['label' => 'New around here? Sign up', 'url' => '#'],
|
|
|
|
['label' => 'Forgot password?', 'url' => '#']
|
|
|
|
]
|
|
|
|
]);
|
|
|
|
|
|
|
|
$expected = <<<HTML
|
|
|
|
<div id="w0" class="dropdown-menu"><form class="px-4 py-3">
|
2021-07-12 23:22:29 +08:00
|
|
|
<div class="mb-3">
|
|
|
|
<label class="form-label" for="exampleDropdownFormEmail1">Email address</label>
|
2021-07-09 17:53:24 +08:00
|
|
|
<input type="email" class="form-control" id="exampleDropdownFormEmail1" placeholder="email@example.com">
|
|
|
|
</div>
|
2021-07-12 23:22:29 +08:00
|
|
|
<div class="mb-3">
|
|
|
|
<label class="form-label" for="exampleDropdownFormPassword1">Password</label>
|
2021-07-09 17:53:24 +08:00
|
|
|
<input type="password" class="form-control" id="exampleDropdownFormPassword1" placeholder="Password">
|
|
|
|
</div>
|
|
|
|
<div class="form-check">
|
|
|
|
<input type="checkbox" class="form-check-input" id="dropdownCheck">
|
|
|
|
<label class="form-check-label" for="dropdownCheck">
|
|
|
|
Remember me
|
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
<button type="submit" class="btn btn-primary">Sign in</button>
|
|
|
|
</form>
|
2021-07-12 23:22:29 +08:00
|
|
|
<hr class="dropdown-divider">
|
2021-07-09 17:53:24 +08:00
|
|
|
<a class="dropdown-item" href="#">New around here? Sign up</a>
|
|
|
|
<a class="dropdown-item" href="#">Forgot password?</a></div>
|
|
|
|
HTML;
|
|
|
|
|
|
|
|
$this->assertEqualsWithoutLE($expected, $out);
|
|
|
|
}
|
|
|
|
}
|