From 9da1d56b21e96994860181599c603ea08d9907bf Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Sun, 15 Oct 2023 23:03:27 +0900 Subject: [PATCH] Partial implementation of unit test for template parser v2 --- .../template/{sample.html => v1example.html} | 0 tests/_data/template/v2example.blade.php | 0 .../parsers/TemplateParserV1Test.php | 2 +- .../parsers/TemplateParserV2Test.php | 103 +++++++++++++++++- 4 files changed, 103 insertions(+), 2 deletions(-) rename tests/_data/template/{sample.html => v1example.html} (100%) create mode 100644 tests/_data/template/v2example.blade.php diff --git a/tests/_data/template/sample.html b/tests/_data/template/v1example.html similarity index 100% rename from tests/_data/template/sample.html rename to tests/_data/template/v1example.html diff --git a/tests/_data/template/v2example.blade.php b/tests/_data/template/v2example.blade.php new file mode 100644 index 000000000..e69de29bb diff --git a/tests/unit/framework/parsers/TemplateParserV1Test.php b/tests/unit/framework/parsers/TemplateParserV1Test.php index 4b3c4136d..eaeaab4d8 100644 --- a/tests/unit/framework/parsers/TemplateParserV1Test.php +++ b/tests/unit/framework/parsers/TemplateParserV1Test.php @@ -521,7 +521,7 @@ class TemplateParserV1Test extends \Codeception\TestCase\Test public function testCompileDirect() { $tmpl = new \Rhymix\Framework\Template(); - $result = $tmpl->compileDirect('./tests/_data/template', 'sample.html'); + $result = $tmpl->compileDirect('./tests/_data/template', 'v1example.html'); $result = trim($result); $this->assertEquals($this->prefix . ' if($__Context->has_blog ?? false){ ?>Taggon\'s blog'.PHP_EOL.'', $result); diff --git a/tests/unit/framework/parsers/TemplateParserV2Test.php b/tests/unit/framework/parsers/TemplateParserV2Test.php index 89c7a9837..e0108a320 100644 --- a/tests/unit/framework/parsers/TemplateParserV2Test.php +++ b/tests/unit/framework/parsers/TemplateParserV2Test.php @@ -2,6 +2,7 @@ class TemplateParserV2Test extends \Codeception\TestCase\Test { + private $prefix = 'config->version = 2; ?>'; private $baseurl; public function _before() @@ -9,8 +10,108 @@ class TemplateParserV2Test extends \Codeception\TestCase\Test $this->baseurl = '/' . basename(dirname(dirname(dirname(dirname(__DIR__))))) . '/'; } - public function testParse() + public function testVersion() + { + // Extension is .html and config is explicitly declared + $source = '' . "\n" . '
{{ RX_VERSION|noescape }}
'; + $target = '
'; + $this->assertEquals($this->prefix . "\n" . $target, $this->_parse($source), false); + + $source = '@version(2)' . "\n" . '
@php func_get_args(); @endphp
'; + $target = '
'; + $this->assertEquals($this->prefix . "\n" . $target, $this->_parse($source), false); + + // Extension is .blade.php and config is not declared + $source = ''; + $target = ' disabled="disabled">'; + $this->assertEquals($this->prefix . $target, $this->_parse($source)); + + // Extension is .blade.php but version is incorrectly declared: will be parsed as v1 + $source = '@version(1)' . "\n" . ''; + $target = ''; + $this->assertStringContainsString($target, $this->_parse($source)); + } + + public function testClassAliases() { } + + public function testInclude() + { + + } + + public function testAssetLoading() + { + + } + + public function testEchoStatements() + { + + } + + public function testOutputFilters() + { + + } + + public function testPathConversion() + { + + } + + public function testBlockConditions() + { + + } + + public function testInlineConditions() + { + + } + + public function testMiscDirectives() + { + + } + + public function testComments() + { + + } + + public function testVerbatim() + { + + } + + public function testRawPhpCode() + { + + } + + public function testAutoEscape() + { + + } + + public function testCurlyBracesAndVars() + { + + } + + public function testCompile() + { + + } + + public function _parse($source, $force_v2 = true) + { + $filename = $force_v2 ? 'v2example.blade.php' : 'no_file.html'; + $tmpl = new \Rhymix\Framework\Template('./tests/_data/template', $filename); + $result = $tmpl->parse($source); + return $result; + } }