2021-07-13 16:50:02 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace yiiunit\extensions\bootstrap5;
|
|
|
|
|
2021-08-04 08:09:56 +02:00
|
|
|
use PHPUnit\Framework\Constraint\IsType;
|
2021-07-27 11:23:42 +02:00
|
|
|
use Yii;
|
2021-07-13 16:50:02 +02:00
|
|
|
use yii\bootstrap5\Html;
|
|
|
|
use yii\bootstrap5\Popover;
|
2021-07-27 11:23:42 +02:00
|
|
|
use yii\web\View;
|
2021-07-13 16:50:02 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @group bootstrap5
|
|
|
|
*/
|
|
|
|
class PopoverTest extends TestCase
|
|
|
|
{
|
2021-07-27 11:23:42 +02:00
|
|
|
public function testButtonRender()
|
|
|
|
{
|
|
|
|
Popover::$counter = 0;
|
|
|
|
$out = Popover::widget(['toggleButton' => ['class' => ['btn', 'btn-primary']]]);
|
|
|
|
|
|
|
|
$expected = <<<HTML
|
|
|
|
<button type="button" id="w0" class="btn btn-primary">Show</button>
|
|
|
|
HTML;
|
|
|
|
|
|
|
|
$this->assertEqualsWithoutLE($expected, $out);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testClientOptions()
|
|
|
|
{
|
|
|
|
Popover::$counter = 0;
|
|
|
|
Popover::widget([
|
|
|
|
'headerOptions' => ['class' => ['test-header']],
|
|
|
|
'placement' => Popover::PLACEMENT_BOTTOM,
|
|
|
|
'title' => 'Test Popover'
|
|
|
|
]);
|
|
|
|
|
|
|
|
$js = Yii::$app->view->js[View::POS_READY];
|
|
|
|
|
2024-03-28 16:27:15 +08:00
|
|
|
// $this->assertInternalType(IsType::TYPE_ARRAY, $js);
|
|
|
|
$this->assertIsArray($js);
|
2021-07-27 11:23:42 +02:00
|
|
|
$options = array_shift($js);
|
|
|
|
|
2022-08-25 14:26:48 +03:00
|
|
|
$this->assertContainsWithoutLE("(new bootstrap.Popover('#w0', {", $options);
|
2021-07-27 11:23:42 +02:00
|
|
|
$this->assertContainsWithoutLE("id=\u0022w0-popover\u0022", $options);
|
|
|
|
$this->assertContainsWithoutLE("class=\u0022test-header popover-header\u0022", $options);
|
|
|
|
$this->assertContainsWithoutLE('"placement":"bottom"', $options);
|
|
|
|
$this->assertContainsWithoutLE('"title":"Test Popover"', $options);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testContent()
|
|
|
|
{
|
|
|
|
Popover::$counter = 0;
|
|
|
|
Popover::begin([]);
|
|
|
|
echo Html::tag('span', 'Test content', ['class' => ['test-content']]);
|
|
|
|
Popover::end();
|
|
|
|
|
|
|
|
$js = Yii::$app->view->js[View::POS_READY];
|
|
|
|
|
2024-03-28 16:27:15 +08:00
|
|
|
// $this->assertInternalType(IsType::TYPE_ARRAY, $js);
|
|
|
|
$this->assertIsArray($js);
|
2021-07-27 11:23:42 +02:00
|
|
|
$options = array_shift($js);
|
|
|
|
|
|
|
|
$this->assertContainsWithoutLE('"content":"\u003Cspan class=\u0022test-content\u0022\u003ETest content\u003C\/span\u003E"', $options);
|
|
|
|
}
|
2021-07-13 16:50:02 +02:00
|
|
|
}
|