update
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit;
|
||||
|
||||
use App\Support\EmailScenarioRegistry;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class EmailScenarioRegistryTest extends TestCase
|
||||
{
|
||||
public function test_registered_scenario_is_locked_and_custom_template_is_marketing(): void
|
||||
{
|
||||
$system = EmailScenarioRegistry::describe(null, 'customer_password_reset_link');
|
||||
$this->assertTrue($system['registered']);
|
||||
$this->assertSame('TRANSACTIONAL', $system['category']);
|
||||
$this->assertSame(['edit_content' => true, 'delete' => false, 'change_key' => false, 'disable' => false], $system['permissions']);
|
||||
|
||||
$this->assertTrue(EmailScenarioRegistry::describe('order_created')['permissions']['disable']);
|
||||
|
||||
$custom = EmailScenarioRegistry::describe('promo_thang_10', 'promo');
|
||||
$this->assertFalse($custom['registered']);
|
||||
$this->assertSame('MARKETING', $custom['category']);
|
||||
$this->assertTrue($custom['permissions']['delete']);
|
||||
}
|
||||
|
||||
public function test_missing_variables_accepts_both_syntaxes_and_layout_slot(): void
|
||||
{
|
||||
$this->assertSame([], EmailScenarioRegistry::missingVariables(['reset_url'], 'x', '<a href="{{ $reset_url }}">'));
|
||||
$this->assertSame([], EmailScenarioRegistry::missingVariables(['reset_url'], 'Link {{reset_url}}', ''));
|
||||
$this->assertSame(['reset_url'], EmailScenarioRegistry::missingVariables(['reset_url'], 'x', '<p>Đặt lại mật khẩu</p>'));
|
||||
$this->assertSame([], EmailScenarioRegistry::missingVariables(['content'], null, '<table>{{$content}}</table>'));
|
||||
$this->assertSame(['content'], EmailScenarioRegistry::missingVariables(['content'], null, '<table></table>'));
|
||||
}
|
||||
}
|
||||
@@ -111,4 +111,28 @@ class EmailTemplateRendererTest extends TestCase
|
||||
$this->assertStringNotContainsString('49', $result['html']);
|
||||
$this->assertStringContainsString('<?php', $result['html']);
|
||||
}
|
||||
|
||||
public function test_dollar_placeholders_are_declared_on_sync_and_rendered_with_default(): void
|
||||
{
|
||||
$template = $this->makeTemplate(
|
||||
'Ưu đãi {{$promo_code}}',
|
||||
'<p>{{ $promo_code }} cho {{full_name}}</p>{{$content}}',
|
||||
[
|
||||
['key' => 'full_name', 'label' => 'Họ tên', 'type' => 'string'],
|
||||
['key' => 'old_custom', 'label' => 'Cũ', 'type' => 'string', 'custom' => true],
|
||||
],
|
||||
);
|
||||
|
||||
$template->syncVariables([['key' => 'promo_code', 'label' => 'Mã KM', 'example' => 'TGS10']]);
|
||||
$variables = $template->variables();
|
||||
|
||||
$this->assertSame(['full_name', 'promo_code'], array_keys($variables));
|
||||
$this->assertSame('Mã KM', $variables['promo_code']['label']);
|
||||
$this->assertTrue($variables['promo_code']['custom']);
|
||||
|
||||
$result = (new EmailTemplateRenderer())->render($template, ['full_name' => 'An']);
|
||||
|
||||
$this->assertSame('Ưu đãi TGS10', $result['subject']);
|
||||
$this->assertSame('<p>TGS10 cho An</p>{{$content}}', $result['html']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit;
|
||||
|
||||
use App\Models\Customer;
|
||||
use App\Support\MailPlaceholders;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class MailPlaceholdersTest extends TestCase
|
||||
{
|
||||
public function test_extracts_both_placeholder_styles_without_layout_slot(): void
|
||||
{
|
||||
$this->assertSame(
|
||||
['client_name', 'promo_code', 'due_date'],
|
||||
MailPlaceholders::extract('Xin chào {{ $client_name }}', '<p>{{promo_code}} {{$due_date}} {{$content}} {{client_name}}</p>'),
|
||||
);
|
||||
}
|
||||
|
||||
public function test_fill_escapes_html_and_keeps_layout_slot(): void
|
||||
{
|
||||
$html = MailPlaceholders::fill('<b>{{$name}}</b>{{$content}}{{missing}}', ['name' => "<script>\nx"]);
|
||||
|
||||
$this->assertSame("<b><script><br />\nx</b>{{\$content}}", $html);
|
||||
$this->assertSame('Hi <A&B>', MailPlaceholders::fill('Hi {{ name }}', ['name' => '<A&B>'], escapeHtml: false));
|
||||
}
|
||||
|
||||
public function test_recipient_values_fall_back_to_email_for_external_recipient(): void
|
||||
{
|
||||
$external = MailPlaceholders::recipientValues(null, 'a@b.vn');
|
||||
$this->assertSame('a@b.vn', $external['client_name']);
|
||||
$this->assertSame('', $external['phone']);
|
||||
|
||||
$customer = new Customer(['fullname' => 'Nguyễn An', 'phone' => '0909']);
|
||||
$values = MailPlaceholders::recipientValues($customer, 'an@x.vn');
|
||||
$this->assertSame('Nguyễn An', $values['customer_name']);
|
||||
$this->assertSame('an@x.vn', $values['customer_email']);
|
||||
$this->assertSame('0909', $values['customer_phone']);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user