Merge pull request #12 from dicrtarasov/dicr-fix-register-plugin

Fix #5
This commit is contained in:
simialbi 2021-08-20 08:26:37 +02:00 committed by GitHub
commit 062ee99655
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 5 deletions

View File

@ -4,6 +4,7 @@ Yii Framework 2 bootstrap5 extension Change Log
2.0.2 under development
-----------------------
- Bug #5: BootstrapWidgetTrait::registerPlugin do nothing if no clientOptions is provided (dicrtarasov)
- Enh #11: Brought back close button api (simialbi)
- Bug #6: yii\bootstrap5\BaseHtml::staticControl(): Argument #1 ($value) must be of type string, int given (dicrtarasov)
- Bug #9: fixed default ActiveField::hintOptions (dicrtarasov)

View File

@ -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();
}

View File

@ -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);
}
}