mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-02 04:37:42 +08:00
Fix #20087: Add custom attributes to script tags
This commit is contained in:
@ -90,6 +90,21 @@ class HtmlTest extends TestCase
|
||||
$this->assertEquals("<script type=\"text/js\">{$content}</script>", Html::script($content, ['type' => 'text/js']));
|
||||
}
|
||||
|
||||
public function testScriptCustomAttribute()
|
||||
{
|
||||
$nonce = Yii::$app->security->generateRandomString();
|
||||
$this->mockApplication([
|
||||
'components' => [
|
||||
'view' => [
|
||||
'class' => 'yii\web\View',
|
||||
'scriptOptions' => ['nonce' => $nonce],
|
||||
],
|
||||
],
|
||||
]);
|
||||
$content = 'a <>';
|
||||
$this->assertEquals("<script nonce=\"{$nonce}\">{$content}</script>", Html::script($content));
|
||||
}
|
||||
|
||||
public function testCssFile()
|
||||
{
|
||||
$this->assertEquals('<link href="http://example.com" rel="stylesheet">', Html::cssFile('http://example.com'));
|
||||
|
||||
Reference in New Issue
Block a user