\Tests\UnitTemplateRendererTest

模板渲染内核

被测对象:TemplateRenderer(Handlebars 引擎) 守护约定:基础渲染与分模式转义(email 转义、sms 不转义)、strict 缺参抛错、 声明式校验(required/max_length)、配置注入与默认值填充。

Summary

Methods
Properties
Constants
test_basic_render()
test_html_escape_for_email()
test_no_escape_for_sms()
test_strict_missing_throws()
test_required_var_throws()
test_required_var_empty_value_throws()
test_max_length_throws()
test_config_injection()
test_config_missing_falls_back_to_default()
test_param_overrides_config_injection()
test_default_fill()
test_each_and_if()
test_render_text_no_escape()
test_untrusted_values_render_literally_without_reevaluation()
test_unknown_helper_does_not_execute()
No public properties found
No constants found
setUp()
No protected properties found
N/A
template()
$renderer
N/A

Properties

$renderer

$renderer : \App\Services\Admin\TemplateRenderer

Type

TemplateRenderer

Methods

test_basic_render()

test_basic_render() : void

验证基础变量渲染。

test_html_escape_for_email()

test_html_escape_for_email() : void

验证 email 类型对双花括号转义、三花括号原样输出。

test_no_escape_for_sms()

test_no_escape_for_sms() : void

验证 sms 类型不做 HTML 转义。

test_strict_missing_throws()

test_strict_missing_throws() : void

验证 strict 模式缺参抛异常。

test_required_var_throws()

test_required_var_throws() : void

验证 required 变量缺失抛「缺少必填变量」。

test_required_var_empty_value_throws()

test_required_var_empty_value_throws() : void

验证 required 变量空值同样抛缺参异常。

test_max_length_throws()

test_max_length_throws() : void

验证超长变量抛「超过最大长度」。

test_config_injection()

test_config_injection() : void

验证 config 来源变量注入。

test_config_missing_falls_back_to_default()

test_config_missing_falls_back_to_default() : void

验证 config 缺失时回落声明默认值。

test_param_overrides_config_injection()

test_param_overrides_config_injection() : void

验证调用方传参覆盖 config 注入。

test_default_fill()

test_default_fill() : void

验证变量默认值填充。

test_each_and_if()

test_each_and_if() : void

验证 each/if 循环条件语法渲染。

test_render_text_no_escape()

test_render_text_no_escape() : void

验证 renderText 不转义输出。

test_untrusted_values_render_literally_without_reevaluation()

test_untrusted_values_render_literally_without_reevaluation() : void

不可信值按字面量渲染:值内的模板语法不二次解析,email 模式 HTML 字符全转义。

test_unknown_helper_does_not_execute()

test_unknown_helper_does_not_execute() : void

未知 helper(模板源内)不产生执行面:引擎按值查找语义回落,渲染不崩溃、不执行代码。

setUp()

setUp() : void

template()

template(string  $type, string  $content, array  $vars = []) : \App\Models\SysTemplate

Parameters

string $type
string $content
array $vars

Returns

\App\Models\SysTemplate —