update
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\Template;
|
||||
use App\Services\Email\EmailTemplateRenderer;
|
||||
use App\Services\Email\EmailTemplateService;
|
||||
use App\Support\EmailScenarioRegistry;
|
||||
use App\Support\MailPlaceholders;
|
||||
use Database\Seeders\EmailTemplates\TemplateVariables;
|
||||
use Database\Seeders\TemplateSeeder;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Tests\TestCase;
|
||||
|
||||
class TemplateSeederTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
public function test_seeder_covers_every_registered_scenario_with_required_variables(): void
|
||||
{
|
||||
$templates = collect(TemplateSeeder::templates())->keyBy('scenario');
|
||||
|
||||
$this->assertEqualsCanonicalizing(array_keys(EmailScenarioRegistry::SCENARIOS), $templates->keys()->all());
|
||||
|
||||
foreach (EmailScenarioRegistry::SCENARIOS as $scenario => $definition) {
|
||||
$item = $templates[$scenario];
|
||||
$this->assertSame([], EmailScenarioRegistry::missingVariables($definition['required_variables'], $item['subject'], $item['message']), $scenario);
|
||||
$this->assertStringContainsString('class="NoiDungKM"', $item['message'], $scenario);
|
||||
$this->assertStringContainsString('class="Footer"', $item['message'], $scenario);
|
||||
}
|
||||
}
|
||||
|
||||
public function test_every_placeholder_has_a_variable_definition(): void
|
||||
{
|
||||
foreach (TemplateSeeder::templates() as $item) {
|
||||
$unknown = array_diff(MailPlaceholders::extract($item['subject'], $item['message']), array_keys(TemplateVariables::DEFINITIONS));
|
||||
$this->assertSame([], array_values($unknown), $item['scenario']);
|
||||
}
|
||||
}
|
||||
|
||||
public function test_seeded_templates_render_and_rerun_updates_in_place(): void
|
||||
{
|
||||
$this->seed(TemplateSeeder::class);
|
||||
$countAfterFirstRun = Template::count();
|
||||
$this->seed(TemplateSeeder::class);
|
||||
$this->assertSame($countAfterFirstRun, Template::count());
|
||||
|
||||
$service = app(EmailTemplateService::class);
|
||||
$renderer = app(EmailTemplateRenderer::class);
|
||||
|
||||
foreach (array_keys(EmailScenarioRegistry::SCENARIOS) as $scenario) {
|
||||
if ($scenario === 'layout') {
|
||||
continue;
|
||||
}
|
||||
$template = $service->loadTemplate($scenario);
|
||||
$rendered = $renderer->render($template, []);
|
||||
|
||||
$this->assertDoesNotMatchRegularExpression(MailPlaceholders::PATTERN, $rendered['subject'] . $rendered['html'], $scenario);
|
||||
}
|
||||
|
||||
$this->assertSame('html', $service->loadTemplate('invoice_notification')->variables()['pay_button']['type']);
|
||||
$this->assertSame('string', $service->loadTemplate('manual_deposit_status')->variables()['status_label']['type']);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user