create([ 'code' => 'attendance_absent', 'variant' => 'default', 'subject' => 'Default Subject', 'body_html' => '

Default

', 'is_active' => true, 'updated_at' => now('UTC'), ]); EmailTemplate::query()->create([ 'code' => 'attendance_absent', 'variant' => 'answered', 'subject' => 'Parent Subject', 'body_html' => '

Parent

', 'is_active' => true, 'updated_at' => now('UTC'), ]); $tpl = EmailTemplate::getTemplate('attendance_absent', 'answered'); $this->assertNotNull($tpl); $this->assertSame('answered', $tpl->variant); $this->assertSame('Parent Subject', $tpl->subject); } public function test_get_template_falls_back_to_default_variant(): void { EmailTemplate::query()->create([ 'code' => 'attendance_late', 'variant' => 'default', 'subject' => 'Late Default', 'body_html' => '

Late default

', 'is_active' => true, 'updated_at' => now('UTC'), ]); $tpl = EmailTemplate::getTemplate('attendance_late', 'answered'); // missing $this->assertNotNull($tpl); $this->assertSame('default', $tpl->variant); $this->assertSame('Late Default', $tpl->subject); } public function test_get_template_ignores_inactive_templates_and_can_return_null(): void { EmailTemplate::query()->create([ 'code' => 'attendance_present', 'variant' => 'default', 'subject' => 'Present Default', 'body_html' => '

Present

', 'is_active' => false, // inactive 'updated_at' => now('UTC'), ]); $tpl = EmailTemplate::getTemplate('attendance_present', 'default'); $this->assertNull($tpl); } public function test_get_template_prefers_exact_variant_over_default(): void { EmailTemplate::query()->create([ 'code' => 'attendance_notice', 'variant' => 'default', 'subject' => 'Default Notice', 'body_html' => '

Default

', 'is_active' => true, 'updated_at' => now('UTC'), ]); EmailTemplate::query()->create([ 'code' => 'attendance_notice', 'variant' => 'no_answer', 'subject' => 'Short Notice', 'body_html' => '

Short

', 'is_active' => true, 'updated_at' => now('UTC'), ]); $tpl = EmailTemplate::getTemplate('attendance_notice', 'no_answer'); $this->assertNotNull($tpl); $this->assertSame('no_answer', $tpl->variant); $this->assertSame('Short Notice', $tpl->subject); } }