demo-pathology/vendor/yiisoft/yii2-bootstrap5/tests/ButtonToolbarTest.php

131 lines
4.3 KiB
PHP
Raw Normal View History

2025-12-26 03:03:19 +00:00
<?php
2026-01-09 10:35:33 +00:00
declare(strict_types=1);
2025-12-26 03:03:19 +00:00
2026-01-09 10:35:33 +00:00
namespace yiiunit\extensions\bootstrap5;
2025-12-26 03:03:19 +00:00
use yii\bootstrap5\ButtonGroup;
use yii\bootstrap5\ButtonToolbar;
/**
* @group bootstrap5
*/
class ButtonToolbarTest extends TestCase
{
public function testContainerOptions()
{
ButtonToolbar::$counter = 0;
$out = ButtonToolbar::widget([
'options' => [
2026-01-09 10:35:33 +00:00
'aria-label' => 'Toolbar with button groups',
2025-12-26 03:03:19 +00:00
],
'buttonGroups' => [
ButtonGroup::widget([
'options' => [
'aria-label' => 'First group',
2026-01-09 10:35:33 +00:00
'class' => ['mr-2'],
2025-12-26 03:03:19 +00:00
],
'buttons' => [
2026-01-09 10:35:33 +00:00
[
'label' => '1',
],
[
'label' => '2',
],
[
'label' => '3',
],
[
'label' => '4',
],
],
2025-12-26 03:03:19 +00:00
]),
[
'options' => [
2026-01-09 10:35:33 +00:00
'aria-label' => 'Second group',
2025-12-26 03:03:19 +00:00
],
'buttons' => [
2026-01-09 10:35:33 +00:00
[
'label' => '5',
],
[
'label' => '6',
],
[
'label' => '7',
],
],
],
],
2025-12-26 03:03:19 +00:00
]);
$expected = <<<HTML
<div id="w5" class="btn-toolbar" aria-label="Toolbar with button groups" role="toolbar"><div id="w0" class="mr-2 btn-group" aria-label="First group" role="group"><button type="button" id="w1" class="btn">1</button>
<button type="button" id="w2" class="btn">2</button>
<button type="button" id="w3" class="btn">3</button>
<button type="button" id="w4" class="btn">4</button></div>
<div id="w6" class="btn-group" aria-label="Second group" role="group"><button type="button" id="w7" class="btn">5</button>
<button type="button" id="w8" class="btn">6</button>
<button type="button" id="w9" class="btn">7</button></div></div>
HTML;
$this->assertEqualsWithoutLE($expected, $out);
}
public function testAdditionalContent()
{
ButtonToolbar::$counter = 0;
$addHtml = <<<HTML
<div class="input-group">
<div class="input-group-prepend">
<div class="input-group-text" id="btnGroupAddon">@</div>
</div>
<input type="text" class="form-control" placeholder="Input group example" aria-label="Input group example" aria-describedby="btnGroupAddon">
</div>
HTML;
$out = ButtonToolbar::widget([
'options' => [
2026-01-09 10:35:33 +00:00
'aria-label' => 'Toolbar with button groups',
2025-12-26 03:03:19 +00:00
],
'buttonGroups' => [
[
'options' => [
'aria-label' => 'First group',
2026-01-09 10:35:33 +00:00
'class' => ['mr-2'],
2025-12-26 03:03:19 +00:00
],
'buttons' => [
2026-01-09 10:35:33 +00:00
[
'label' => '1',
],
[
'label' => '2',
],
[
'label' => '3',
],
[
'label' => '4',
],
],
2025-12-26 03:03:19 +00:00
],
2026-01-09 10:35:33 +00:00
$addHtml,
],
2025-12-26 03:03:19 +00:00
]);
$expected = <<<HTML
<div id="w0" class="btn-toolbar" aria-label="Toolbar with button groups" role="toolbar"><div id="w1" class="mr-2 btn-group" aria-label="First group" role="group"><button type="button" id="w2" class="btn">1</button>
<button type="button" id="w3" class="btn">2</button>
<button type="button" id="w4" class="btn">3</button>
<button type="button" id="w5" class="btn">4</button></div>
<div class="input-group">
<div class="input-group-prepend">
<div class="input-group-text" id="btnGroupAddon">@</div>
</div>
<input type="text" class="form-control" placeholder="Input group example" aria-label="Input group example" aria-describedby="btnGroupAddon">
</div></div>
HTML;
$this->assertEqualsWithoutLE($expected, $out);
}
}