From 1b9e2f58b7006abd80dea857dce0275ff54f8872 Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Mon, 16 Oct 2023 00:50:20 +0900 Subject: [PATCH] Add unit tests for @load syntax of template v2 --- .../parsers/template/TemplateParser_v2.php | 2 +- .../parsers/TemplateParserV2Test.php | 76 +++++++++++++++++++ 2 files changed, 77 insertions(+), 1 deletion(-) diff --git a/common/framework/parsers/template/TemplateParser_v2.php b/common/framework/parsers/template/TemplateParser_v2.php index e74e796b3..39a64eb09 100644 --- a/common/framework/parsers/template/TemplateParser_v2.php +++ b/common/framework/parsers/template/TemplateParser_v2.php @@ -473,7 +473,7 @@ class TemplateParser_v2 { $info['type'] = $match[2]; } - elseif (preg_match('#^([\'"])(screen|print)\1$#', $value, $match)) + elseif (preg_match('#^([\'"])((?:screen|print)[^\'"]*)\1$#', $value, $match)) { $info['media'] = $match[2]; } diff --git a/tests/unit/framework/parsers/TemplateParserV2Test.php b/tests/unit/framework/parsers/TemplateParserV2Test.php index 4e63e948b..bf131f5d1 100644 --- a/tests/unit/framework/parsers/TemplateParserV2Test.php +++ b/tests/unit/framework/parsers/TemplateParserV2Test.php @@ -155,7 +155,83 @@ class TemplateParserV2Test extends \Codeception\Test\Unit public function testAssetLoading() { + // CSS, SCSS, LESS with media and variables + $source = ''; + $target = "foo]); ?>"; + $this->assertEquals($target, $this->_parse($source)); + $source = ''; + $target = ""; + $this->assertEquals($target, $this->_parse($source)); + + // JS with type and index + $source = ''; + $target = ""; + $this->assertEquals($target, $this->_parse($source)); + + $source = ''; + $target = ""; + $this->assertEquals($target, $this->_parse($source)); + + // Path relative to Rhymix installation directory + $source = ''; + $target = ""; + $this->assertEquals($target, $this->_parse($source)); + + // JS plugin + $source = ''; + $target = ""; + $this->assertEquals($target, $this->_parse($source)); + + // Lang file + $source = ''; + $target = ""; + $this->assertEquals($target, $this->_parse($source)); + + $source = ''; + $target = ""; + $this->assertEquals($target, $this->_parse($source)); + + // Blade-style SCSS with media and variables + $source = "@load('assets/hello.scss', 'print', \$vars)"; + $target = "vars]); ?>"; + $this->assertEquals($target, $this->_parse($source)); + + $source = "@load ('../hello.css', 'screen')"; + $target = ""; + $this->assertEquals($target, $this->_parse($source)); + + // Blade-style JS with type and index + $source = "@load('assets/hello.js', 'body', 10)"; + $target = ""; + $this->assertEquals($target, $this->_parse($source)); + + $source = "@load ('assets/hello.js', 'head')"; + $target = ""; + $this->assertEquals($target, $this->_parse($source)); + + $source = "@load ('assets/hello.js')"; + $target = ""; + $this->assertEquals($target, $this->_parse($source)); + + // Blade-style path relative to Rhymix installation directory + $source = '@load ("^/common/js/foobar.js")'; + $target = ""; + $this->assertEquals($target, $this->_parse($source)); + + // Blade-style JS plugin + $source = "@load('^/common/js/plugins/ckeditor/')"; + $target = ""; + $this->assertEquals($target, $this->_parse($source)); + + // Blade-style lang file + $source = "@load('^/modules/member/lang')"; + $target = ""; + $this->assertEquals($target, $this->_parse($source)); + + $source = '@load("^/modules/legacy_module/lang/lang.xml")'; + $target = ""; + $this->assertEquals($target, $this->_parse($source)); } public function testEchoStatements()