'unit_test_scenario', 'subject' => $subject, 'message' => $message, 'metadata' => ['variables' => $variables], ]); return $template; } public function test_it_replaces_known_placeholders_in_subject_and_html(): void { $template = $this->makeTemplate( 'Xin chào {{full_name}}', '
Chào mừng {{full_name}} đến với {{app_name}}
', [ ['key' => 'full_name', 'label' => 'Họ tên', 'type' => 'string'], ['key' => 'app_name', 'label' => 'Tên app', 'type' => 'string'], ], ); $result = (new EmailTemplateRenderer())->render($template, [ 'full_name' => 'Nguyễn Văn A', 'app_name' => 'Thế Giới Số', ]); $this->assertSame('Xin chào Nguyễn Văn A', $result['subject']); $this->assertSame('Chào mừng Nguyễn Văn A đến với Thế Giới Số
', $result['html']); } public function test_it_falls_back_to_example_value_when_data_missing(): void { $template = $this->makeTemplate( 'Mã: {{code}}', '{{code}}
', [['key' => 'code', 'label' => 'Mã', 'type' => 'string', 'example' => '000000']], ); $result = (new EmailTemplateRenderer())->render($template, []); $this->assertSame('Mã: 000000', $result['subject']); $this->assertSame('000000
', $result['html']); } public function test_it_html_escapes_string_type_by_default(): void { $template = $this->makeTemplate( 'subj', '{{name}}
', [['key' => 'name', 'label' => 'Tên', 'type' => 'string']], ); $result = (new EmailTemplateRenderer())->render($template, ['name' => '']); $this->assertStringNotContainsString('', 'client_name' => "A & B's ", 'admin_name' => 'A & B's <b> - <img src=x onerror=1> (<i>vps</i>)
', $result['html'], ); } }