fix: default autoresponder dates to today

This commit is contained in:
Marek Miklewicz
2026-06-02 22:01:32 +02:00
parent 767016c659
commit c0b007d25d
3 changed files with 25 additions and 4 deletions
+2 -3
View File
@@ -30,11 +30,10 @@ function render_rule_form(AppContext $ctx, string $mode, ?array $rule): string
function default_schedule_value(AppContext $ctx, bool $start): string function default_schedule_value(AppContext $ctx, bool $start): string
{ {
$today = new DateTimeImmutable('today', new DateTimeZone($ctx->settings->timezone())); $today = new DateTimeImmutable('today', new DateTimeZone($ctx->settings->timezone()));
$date = $start ? $today : $today->modify('+14 days');
if ($ctx->settings->scheduleMode() === 'directadmin_period') { if ($ctx->settings->scheduleMode() === 'directadmin_period') {
return $date->format('Y-m-d') . '|' . ($start ? 'morning' : 'evening'); return $today->format('Y-m-d') . '|' . ($start ? 'morning' : 'evening');
} }
return $date->format('Y-m-d') . 'T' . ($start ? '09:00' : '17:00'); return $today->format('Y-m-d') . 'T' . ($start ? '09:00' : '17:00');
} }
/** @param array<string,mixed>|null $rule */ /** @param array<string,mixed>|null $rule */
+1 -1
View File
@@ -2,7 +2,7 @@ name=global-autoresponder
id=global-autoresponder id=global-autoresponder
type=user type=user
author=HITME.PL author=HITME.PL
version=1.0.9 version=1.0.10
active=no active=no
installed=no installed=no
user_run_as=root user_run_as=root
+22
View File
@@ -137,6 +137,28 @@ test('calendar picker disables dates before today', function (): void {
assert_false(str_contains($html, 'data-date-value="2000-01-15"'), 'Past dates must not be clickable'); assert_false(str_contains($html, 'data-date-value="2000-01-15"'), 'Past dates must not be clickable');
}); });
test('new rule form selects current date for start and end calendars by default', function (): void {
$settingsPath = TEST_TMP . '/form-calendar-defaults.conf';
test_write($settingsPath, "DEFAULT_PLUGIN_LANGUAGE=pl\nGLOBAL_AUTORESPONDER_BACKEND=exim\nGLOBAL_AUTORESPONDER_TIMEZONE=Europe/Warsaw\n");
$settings = Settings::load($settingsPath);
$ctx = new AppContext(
new DirectAdminUser('alice', 'enhanced', 'pl', TEST_TMP . '/config'),
$settings,
new RuleRepository(TEST_TMP . '/data'),
new CsrfGuard('secret', 'alice', 'sid'),
Lang::load('pl', $settings),
new AuditLog(TEST_TMP . '/audit.log')
);
$today = (new DateTimeImmutable('today', new DateTimeZone($settings->timezone())))->format('Y-m-d');
$html = render_rule_form($ctx, 'create', null);
assert_contains('id="start_value_date" name="start_value_date" value="' . $today . '"', $html);
assert_contains('id="end_value_date" name="end_value_date" value="' . $today . '"', $html);
assert_contains('id="start_value" name="start_value" value="' . $today . 'T09:00"', $html);
assert_contains('id="end_value" name="end_value" value="' . $today . 'T17:00"', $html);
});
test('rule form localizes calendar and preview labels without translating user content globally', function (): void { test('rule form localizes calendar and preview labels without translating user content globally', function (): void {
$settingsPath = TEST_TMP . '/form-i18n.conf'; $settingsPath = TEST_TMP . '/form-i18n.conf';
test_write($settingsPath, "DEFAULT_PLUGIN_LANGUAGE=en\nGLOBAL_AUTORESPONDER_BACKEND=exim\n"); test_write($settingsPath, "DEFAULT_PLUGIN_LANGUAGE=en\nGLOBAL_AUTORESPONDER_BACKEND=exim\n");