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

93 lines
2.4 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
namespace yiiunit\extensions\bootstrap5;
use yii\bootstrap5\Alert;
/**
* Tests for Alert widget
*
* @group bootstrap5
*/
class AlertTest extends TestCase
{
public function testNormalAlert()
{
Alert::$counter = 0;
$html = Alert::widget([
'body' => '<strong>Holy guacamole!</strong> You should check in on some of those fields below.',
'options' => [
2026-01-09 10:35:33 +00:00
'class' => ['alert-warning'],
],
2025-12-26 03:03:19 +00:00
]);
$expectedHtml = <<<HTML
<div id="w0" class="alert-warning alert alert-dismissible" role="alert">
<strong>Holy guacamole!</strong> You should check in on some of those fields below.
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
HTML;
$this->assertEqualsWithoutLE($expectedHtml, $html);
}
2026-01-09 10:35:33 +00:00
2025-12-26 03:03:19 +00:00
public function testDismissibleAlert()
{
Alert::$counter = 0;
$html = Alert::widget([
'body' => "Message1",
]);
$expectedHtml = <<<HTML
<div id="w0" class="alert alert-dismissible" role="alert">
Message1
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
HTML;
$this->assertEqualsWithoutLE($expectedHtml, $html);
}
/**
* @see https://github.com/yiisoft/yii2-bootstrap5/issues/11
*/
public function testDismissibleAlertCustomButton()
{
Alert::$counter = 0;
$html = Alert::widget([
'body' => "Low Blow: Bob Loblaw's Law Blog Lobs Law Bomb",
2026-01-09 10:35:33 +00:00
'options' => [
'class' => 'alert-warning',
],
2025-12-26 03:03:19 +00:00
'closeButton' => [
'label' => 'Dismiss',
'tag' => 'a',
2026-01-09 10:35:33 +00:00
'class' => [
'widget' => 'btn btn-outline-warning',
],
2025-12-26 03:03:19 +00:00
'style' => [
'position' => 'absolute',
'top' => '.5rem',
2026-01-09 10:35:33 +00:00
'right' => '.5rem',
2025-12-26 03:03:19 +00:00
],
2026-01-09 10:35:33 +00:00
],
2025-12-26 03:03:19 +00:00
]);
$expectedHtml = <<<HTML
<div id="w0" class="alert-warning alert alert-dismissible" role="alert">
Low Blow: Bob Loblaw's Law Blog Lobs Law Bomb
<a class="btn btn-outline-warning" data-bs-dismiss="alert" aria-label="Close" style="position: absolute; top: .5rem; right: .5rem;">Dismiss</a>
</div>
HTML;
$this->assertEqualsWithoutLE($expectedHtml, $html);
}
}