create([ 'code' => 'attendance_absent', 'variant' => 'default', 'subject' => 'Default Subject', 'body_html' => '
Default
', 'is_active' => true, ]); AttendanceEmailTemplate::query()->create([ 'code' => 'attendance_absent', 'variant' => 'answered', 'subject' => 'Parent Subject', 'body_html' => 'Parent
', 'is_active' => true, ]); $result = (new AttendanceEmailTemplate)->getTemplate('attendance_absent', 'answered'); $this->assertIsArray($result); $this->assertSame('answered', $result['variant']); $this->assertSame('Parent Subject', $result['subject']); } public function test_get_template_falls_back_to_default_when_requested_variant_missing(): void { AttendanceEmailTemplate::query()->create([ 'code' => 'attendance_late', 'variant' => 'default', 'subject' => 'Late Default', 'body_html' => 'Late default
', 'is_active' => true, ]); $result = (new AttendanceEmailTemplate)->getTemplate('attendance_late', 'answered'); $this->assertIsArray($result); $this->assertSame('default', $result['variant']); $this->assertSame('Late Default', $result['subject']); } public function test_get_template_ignores_inactive_exact_variant_and_uses_active_default(): void { AttendanceEmailTemplate::query()->create([ 'code' => 'attendance_present', 'variant' => 'no_answer', 'subject' => 'Inactive SMS', 'body_html' => 'Inactive
', 'is_active' => false, ]); AttendanceEmailTemplate::query()->create([ 'code' => 'attendance_present', 'variant' => 'default', 'subject' => 'Active Default', 'body_html' => 'Active
', 'is_active' => true, ]); $result = (new AttendanceEmailTemplate)->getTemplate('attendance_present', 'no_answer'); $this->assertIsArray($result); $this->assertSame('default', $result['variant']); $this->assertSame('Active Default', $result['subject']); } public function test_get_template_returns_null_when_no_active_template_exists(): void { AttendanceEmailTemplate::query()->create([ 'code' => 'attendance_unknown', 'variant' => 'default', 'subject' => 'Inactive Default', 'body_html' => 'Inactive
', 'is_active' => false, ]); $result = (new AttendanceEmailTemplate)->getTemplate('attendance_unknown', 'anything'); $this->assertNull($result); } }