From a9779d96a4b34333a6c32e6b7547a496460381c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=98=D0=B3=D0=BE=D1=80=D1=8C=20=D0=A2=D0=B0=D1=80=D0=B0?= =?UTF-8?q?=D1=81=D0=BE=D0=B2?= Date: Fri, 13 Aug 2021 05:08:44 +0500 Subject: [PATCH 1/2] fix BootstrapWidgetTrait::registerPlugin --- src/BootstrapWidgetTrait.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/BootstrapWidgetTrait.php b/src/BootstrapWidgetTrait.php index 4706dd0..9ddef95 100644 --- a/src/BootstrapWidgetTrait.php +++ b/src/BootstrapWidgetTrait.php @@ -76,11 +76,9 @@ trait BootstrapWidgetTrait $id = $this->options['id']; - if ($this->clientOptions !== []) { - $options = empty($this->clientOptions) ? '' : Json::htmlEncode($this->clientOptions); - $js = "jQuery('#$id').$name($options);"; - $view->registerJs($js); - } + $options = empty($this->clientOptions) ? '' : Json::htmlEncode($this->clientOptions); + $js = "jQuery('#$id').$name($options);"; + $view->registerJs($js); $this->registerClientEvents(); } From 26ab72156b9c821fad96bbf018887f567d47c0d5 Mon Sep 17 00:00:00 2001 From: Simon Karlen Date: Mon, 16 Aug 2021 10:09:09 +0200 Subject: [PATCH 2/2] added test and CHANGELOG.md entry --- CHANGELOG.md | 2 +- tests/ToastTest.php | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f3fdf1..85fe33d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ Yii Framework 2 bootstrap5 extension Change Log 2.0.2 under development ----------------------- -- no changes in this release. +- Bug #5: BootstrapWidgetTrait::registerPlugin do nothing if no clientOptions is provided (dicrtarasov) 2.0.1 August 11, 2021 diff --git a/tests/ToastTest.php b/tests/ToastTest.php index bb160f9..18402ab 100644 --- a/tests/ToastTest.php +++ b/tests/ToastTest.php @@ -2,7 +2,10 @@ namespace yiiunit\extensions\bootstrap5; +use PHPUnit\Framework\Constraint\IsType; +use Yii; use yii\bootstrap5\Toast; +use yii\web\View; /** * @group bootstrap5 @@ -113,4 +116,30 @@ HTML; $this->assertEqualsWithoutLE($expected, $out); } + + /** + * @see https://github.com/yiisoft/yii2-bootstrap5/issues/5 + */ + public function testWidgetInitialization() + { + Toast::$counter = 0; + ob_start(); + $toast = Toast::begin([ + 'title' => 'Toast title', + 'titleOptions' => ['tag' => 'h5', 'style' => ['text-align' => 'left']] + ]); + echo 'test'; + Toast::end(); + $out = ob_get_clean(); + + $this->assertInternalType(IsType::TYPE_ARRAY, $toast->clientOptions); + $this->assertCount(0, $toast->clientOptions); + + $js = Yii::$app->view->js[View::POS_READY]; + + $this->assertInternalType(IsType::TYPE_ARRAY, $js); + $options = array_shift($js); + + $this->assertContainsWithoutLE("jQuery('#w0').toast();", $options); + } }