2021-07-09 11:53:24 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace yiiunit\extensions\bootstrap5;
|
|
|
|
|
|
|
|
use yii\bootstrap5\Html;
|
|
|
|
use yii\bootstrap5\Modal;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @group bootstrap5
|
|
|
|
*/
|
|
|
|
class ModalTest extends TestCase
|
|
|
|
{
|
|
|
|
public function testBodyOptions()
|
|
|
|
{
|
|
|
|
Modal::$counter = 0;
|
|
|
|
$out = Modal::widget([
|
|
|
|
'closeButton' => false,
|
|
|
|
'bodyOptions' => ['class' => 'modal-body test', 'style' => 'text-align:center;']
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
|
|
$expected = <<<HTML
|
|
|
|
|
2021-07-12 17:22:29 +02:00
|
|
|
<div id="w0" class="modal fade" tabindex="-1" aria-hidden="true">
|
|
|
|
<div class="modal-dialog">
|
2021-07-09 11:53:24 +02:00
|
|
|
<div class="modal-content">
|
|
|
|
|
|
|
|
<div class="modal-body test" style="text-align:center;">
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
HTML;
|
|
|
|
|
|
|
|
$this->assertEqualsWithoutLE($expected, $out);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*/
|
|
|
|
public function testContainerOptions()
|
|
|
|
{
|
|
|
|
Modal::$counter = 0;
|
|
|
|
|
|
|
|
ob_start();
|
|
|
|
Modal::begin([
|
|
|
|
'title' => 'Modal title',
|
|
|
|
'footer' => Html::button('Close', [
|
|
|
|
'type' => 'button',
|
|
|
|
'class' => ['btn', 'btn-secondary'],
|
|
|
|
'data' => [
|
2022-08-08 13:38:55 +01:00
|
|
|
'bs-dismiss' => 'modal'
|
2021-07-09 11:53:24 +02:00
|
|
|
]
|
|
|
|
]) . "\n" . Html::button('Save changes', [
|
|
|
|
'type' => 'button',
|
|
|
|
'class' => ['btn', 'btn-primary']
|
|
|
|
])
|
|
|
|
]);
|
|
|
|
echo '<p>Woohoo, you\'re reading this text in a modal!</p>';
|
|
|
|
Modal::end();
|
|
|
|
$out = ob_get_clean();
|
|
|
|
|
|
|
|
$expected = <<<HTML
|
|
|
|
|
2021-07-12 17:22:29 +02:00
|
|
|
<div id="w0" class="modal fade" tabindex="-1" aria-hidden="true" aria-labelledby="w0-label">
|
|
|
|
<div class="modal-dialog">
|
2021-07-09 11:53:24 +02:00
|
|
|
<div class="modal-content">
|
|
|
|
<div class="modal-header">
|
|
|
|
<h5 id="w0-label" class="modal-title">Modal title</h5>
|
2021-07-12 17:22:29 +02:00
|
|
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
2021-07-09 11:53:24 +02:00
|
|
|
</div>
|
|
|
|
<div class="modal-body">
|
|
|
|
<p>Woohoo, you're reading this text in a modal!</p>
|
|
|
|
</div>
|
|
|
|
<div class="modal-footer">
|
2022-08-08 13:38:55 +01:00
|
|
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
|
2021-07-09 11:53:24 +02:00
|
|
|
<button type="button" class="btn btn-primary">Save changes</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
HTML;
|
|
|
|
|
|
|
|
$this->assertEqualsWithoutLE($expected, $out);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testTriggerButton()
|
|
|
|
{
|
|
|
|
Modal::$counter = 0;
|
|
|
|
|
|
|
|
ob_start();
|
|
|
|
Modal::begin([
|
|
|
|
'toggleButton' => [
|
|
|
|
'class' => ['btn', 'btn-primary'],
|
|
|
|
'label' => 'Launch demo modal'
|
|
|
|
],
|
|
|
|
'title' => 'Modal title',
|
|
|
|
'footer' => Html::button('Close', [
|
|
|
|
'type' => 'button',
|
|
|
|
'class' => ['btn', 'btn-secondary']
|
|
|
|
]) . "\n" . Html::button('Save changes', [
|
|
|
|
'type' => 'button',
|
|
|
|
'class' => ['btn', 'btn-primary']
|
|
|
|
])
|
|
|
|
]);
|
|
|
|
echo '<p>Woohoo, you\'re reading this text in a modal!</p>';
|
|
|
|
Modal::end();
|
|
|
|
$out = ob_get_clean();
|
|
|
|
|
2024-03-28 16:27:15 +08:00
|
|
|
$this->assertStringContainsString(
|
2021-07-12 17:22:29 +02:00
|
|
|
'<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#w0">Launch demo modal</button>',
|
|
|
|
$out
|
|
|
|
);
|
2021-07-09 11:53:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testDialogOptions()
|
|
|
|
{
|
|
|
|
Modal::$counter = 0;
|
|
|
|
$out = Modal::widget([
|
|
|
|
'closeButton' => false,
|
|
|
|
'dialogOptions' => ['class' => 'test', 'style' => 'text-align:center;']
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
|
|
$expected = <<<HTML
|
|
|
|
|
2021-07-12 17:22:29 +02:00
|
|
|
<div id="w0" class="modal fade" tabindex="-1" aria-hidden="true">
|
|
|
|
<div class="test modal-dialog" style="text-align:center;">
|
2021-07-09 11:53:24 +02:00
|
|
|
<div class="modal-content">
|
|
|
|
|
|
|
|
<div class="modal-body">
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
HTML;
|
|
|
|
|
|
|
|
$this->assertEqualsWithoutLE($expected, $out);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testCenterVertical()
|
|
|
|
{
|
|
|
|
Modal::$counter = 0;
|
|
|
|
$out = Modal::widget([
|
|
|
|
'closeButton' => false,
|
2021-07-12 17:22:29 +02:00
|
|
|
'centerVertical' => true
|
2021-07-09 11:53:24 +02:00
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
|
|
$expected = <<<HTML
|
|
|
|
|
2021-07-12 17:22:29 +02:00
|
|
|
<div id="w0" class="modal fade" tabindex="-1" aria-hidden="true">
|
|
|
|
<div class="modal-dialog modal-dialog-centered">
|
2021-07-09 11:53:24 +02:00
|
|
|
<div class="modal-content">
|
|
|
|
|
|
|
|
<div class="modal-body">
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
HTML;
|
|
|
|
|
|
|
|
$this->assertEqualsWithoutLE($expected, $out);
|
|
|
|
}
|
2021-07-12 17:22:29 +02:00
|
|
|
|
2021-07-09 11:53:24 +02:00
|
|
|
public function testScrollable()
|
|
|
|
{
|
|
|
|
Modal::$counter = 0;
|
|
|
|
$out = Modal::widget([
|
|
|
|
'closeButton' => false,
|
2021-07-12 17:22:29 +02:00
|
|
|
'scrollable' => true
|
2021-07-09 11:53:24 +02:00
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
|
|
$expected = <<<HTML
|
|
|
|
|
2021-07-12 17:22:29 +02:00
|
|
|
<div id="w0" class="modal fade" tabindex="-1" aria-hidden="true">
|
|
|
|
<div class="modal-dialog modal-dialog-scrollable">
|
2021-07-09 11:53:24 +02:00
|
|
|
<div class="modal-content">
|
|
|
|
|
|
|
|
<div class="modal-body">
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
HTML;
|
|
|
|
|
|
|
|
$this->assertEqualsWithoutLE($expected, $out);
|
|
|
|
}
|
|
|
|
}
|