model = new ReminderMailConfigModel(); } public function testHasCustomTemplateRequiresBothSubjectAndBody() { $this->assertFalse($this->model->hasCustomTemplate(null)); $this->assertFalse($this->model->hasCustomTemplate([])); $this->assertFalse($this->model->hasCustomTemplate([ 'email_subject' => 'Reminder', 'email_body' => '', ])); $this->assertFalse($this->model->hasCustomTemplate([ 'email_subject' => ' ', 'email_body' => '
Body
', ])); $this->assertTrue($this->model->hasCustomTemplate([ 'email_subject' => 'Reminder', 'email_body' => 'Body
', ])); } public function testResolveNotificationTemplateUsesCustomTemplateWhenConfigured() { $config = [ 'email_subject' => 'Custom subject', 'email_body' => 'Custom body
', ]; $notification = [ 'id' => 5, 'enabled' => 0, 'subject' => 'Default subject', 'mail_content' => 'Default body
', ]; $resolved = $this->model->resolveNotificationTemplate($config, $notification); $this->assertSame('Custom subject', $resolved['subject']); $this->assertSame('Custom body
', $resolved['mail_content']); $this->assertSame(1, $resolved['enabled']); $this->assertSame(5, $resolved['id']); } public function testResolveNotificationTemplateReturnsDefaultWhenCustomTemplateMissing() { $notification = [ 'subject' => 'Default subject', 'mail_content' => 'Default body
', ]; $resolved = $this->model->resolveNotificationTemplate( ['email_subject' => 'Only subject'], $notification ); $this->assertSame($notification, $resolved); } public function testCanSendReminderMailAllowsCustomTemplateEvenWhenNotificationDisabled() { $config = [ 'email_subject' => 'Custom subject', 'email_body' => 'Custom body
', ]; $notification = [ 'enabled' => 0, 'mail_content' => '', ]; $this->assertTrue($this->model->canSendReminderMail($config, $notification)); } public function testCanSendReminderMailRequiresEnabledDefaultNotification() { $this->assertFalse($this->model->canSendReminderMail(null, null)); $this->assertFalse($this->model->canSendReminderMail(null, [ 'enabled' => 0, 'mail_content' => 'Body
', ])); $this->assertFalse($this->model->canSendReminderMail(null, [ 'enabled' => 1, 'mail_content' => '', ])); $this->assertTrue($this->model->canSendReminderMail(null, [ 'enabled' => 1, 'mail_content' => 'Body
', ])); } public function testValidateConfigRejectsInvalidFrequency() { $error = $this->model->validateConfig('hourly', '1'); $this->assertSame( 'Invalid frequency. Allowed values: daily, weekly, monthly, custom, working_days.', $error ); } public function testValidateConfigDailyDoesNotRequireReminderDays() { $this->assertNull($this->model->validateConfig( ReminderMailConfigModel::FREQUENCY_DAILY, null )); } public function testValidateConfigWorkingDaysAcceptsDayNames() { $this->assertNull($this->model->validateConfig( ReminderMailConfigModel::FREQUENCY_WORKING_DAYS, 'Mon,Wed,Fri' )); } public function testValidateConfigWeeklyRejectsInvalidDay() { $error = $this->model->validateConfig( ReminderMailConfigModel::FREQUENCY_WEEKLY, '0,8' ); $this->assertSame( 'Weekly reminder_days must be between 0 (Sunday) and 6 (Saturday).', $error ); } public function testEnrichConfigAddsCustomTemplateFlagAndWorkingDayLabels() { $config = $this->model->enrichConfig([ 'frequency' => ReminderMailConfigModel::FREQUENCY_WORKING_DAYS, 'reminder_days' => '1,3,5', 'email_subject' => 'Reminder', 'email_body' => 'Please enroll
', ]); $this->assertTrue($config['has_custom_template']); $this->assertSame(['Mon', 'Wed', 'Fri'], $config['working_day_labels']); } public function testNormalizeWorkingDaysSortsAndDeduplicates() { $this->assertSame('1,3,5', $this->model->normalizeWorkingDays('Fri,Mon,Wed,Mon')); } }