aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/TemplateFunctionsTest.php29
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/lib/TemplateFunctionsTest.php b/tests/lib/TemplateFunctionsTest.php
index caecdfc76ac..b2b25ab654c 100644
--- a/tests/lib/TemplateFunctionsTest.php
+++ b/tests/lib/TemplateFunctionsTest.php
@@ -57,6 +57,35 @@ class TemplateFunctionsTest extends \Test\TestCase {
print_unescaped($string);
}
+ public function testEmitScriptTagWithContent() {
+ $this->expectOutputRegex('/<script nonce="[^"]+">\nalert\(\)\n<\/script>\n?/');
+ emit_script_tag('', 'alert()');
+ }
+
+ public function testEmitScriptTagWithSource() {
+ $this->expectOutputRegex('/<script nonce=".*" defer src="some.js"><\/script>/');
+ emit_script_tag('some.js');
+ }
+
+ public function testEmitScriptTagWithModuleSource() {
+ $this->expectOutputRegex('/<script nonce=".*" defer src="some.mjs" type="module"><\/script>/');
+ emit_script_tag('some.mjs', '', 'module');
+ }
+
+ public function testEmitScriptLoadingTags() {
+ // Test mjs js and inline content
+ $pattern = '/src="some\.mjs"[^>]+type="module"[^>]*>.+\n'; // some.mjs with type = module
+ $pattern .= '<script[^>]+src="other\.js"[^>]*>.+\n'; // other.js as plain javascript
+ $pattern .= '<script[^>]*>\n?.*inline.*\n?<\/script>'; // inline content
+ $pattern .= '/'; // no flags
+
+ $this->expectOutputRegex($pattern);
+ emit_script_loading_tags([
+ 'jsfiles' => ['some.mjs', 'other.js'],
+ 'inline_ocjs' => '// inline'
+ ]);
+ }
+
// ---------------------------------------------------------------------------
// Test relative_modified_date with dates only
// ---------------------------------------------------------------------------