diff --git a/composer.json b/composer.json index b71ce7e..87ab340 100644 --- a/composer.json +++ b/composer.json @@ -28,7 +28,7 @@ "php": ">=7.4.0", "ext-json": "*", "yiisoft/yii2": "^2.0.42", - "npm-asset/bootstrap": "^5.0.0" + "bower-asset/bootstrap": "^5.0.0" }, "require-dev": { "yiisoft/yii2-coding-standards": "~2.0", diff --git a/src/BootstrapAsset.php b/src/BootstrapAsset.php index 951ae11..a05e331 100644 --- a/src/BootstrapAsset.php +++ b/src/BootstrapAsset.php @@ -8,7 +8,7 @@ use yii\web\AssetBundle; class BootstrapAsset extends AssetBundle { - public $sourcePath = '@npm/bootstrap/dist'; + public $sourcePath = '@bower/bootstrap/dist'; public $css = [ 'css/bootstrap.css', diff --git a/src/BootstrapPluginAsset.php b/src/BootstrapPluginAsset.php index be85192..8d88845 100644 --- a/src/BootstrapPluginAsset.php +++ b/src/BootstrapPluginAsset.php @@ -13,7 +13,7 @@ use yii\web\AssetBundle; */ class BootstrapPluginAsset extends AssetBundle { - public $sourcePath = '@npm/bootstrap/dist'; + public $sourcePath = '@bower/bootstrap/dist'; public $js = [ 'js/bootstrap.bundle.js', ]; diff --git a/src/Popover.php b/src/Popover.php index afec04c..2344b1b 100644 --- a/src/Popover.php +++ b/src/Popover.php @@ -44,7 +44,7 @@ class Popover extends Widget /** * @var string|null the tile content in the popover. */ - public ?string $title; + public ?string $title = null; /** * @var array additional header options * @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered. diff --git a/tests/PopoverTest.php b/tests/PopoverTest.php index 2e97fe9..cba1fa7 100644 --- a/tests/PopoverTest.php +++ b/tests/PopoverTest.php @@ -2,13 +2,61 @@ namespace yiiunit\extensions\bootstrap5; +use Yii; use yii\bootstrap5\Html; use yii\bootstrap5\Popover; +use yii\web\View; /** * @group bootstrap5 */ class PopoverTest extends TestCase { - // TODO + public function testButtonRender() + { + Popover::$counter = 0; + $out = Popover::widget(['toggleButton' => ['class' => ['btn', 'btn-primary']]]); + + $expected = <<Show +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]; + + $this->assertIsArray($js); + $options = array_shift($js); + + $this->assertContainsWithoutLE("jQuery('#w0').popover({", $options); + $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]; + + $this->assertIsArray($js); + $options = array_shift($js); + + $this->assertContainsWithoutLE('"content":"\u003Cspan class=\u0022test-content\u0022\u003ETest content\u003C\/span\u003E"', $options); + } }