fix: match directadmin vacation controls

This commit is contained in:
Marek Miklewicz
2026-06-03 09:21:51 +02:00
parent 0617798821
commit 9174d62706
12 changed files with 176 additions and 53 deletions
+1 -1
View File
@@ -49,7 +49,7 @@ test('backend mode derives schedule mode', function (): void {
test_write($path, "GLOBAL_AUTORESPONDER_BACKEND=da\n");
$settings = Settings::load($path);
assert_same('da', $settings->backendMode());
assert_same('directadmin_period', $settings->scheduleMode());
assert_same('exact_hour', $settings->scheduleMode());
test_write($path, "GLOBAL_AUTORESPONDER_BACKEND=exim\n");
$settings = Settings::load($path);
+20 -6
View File
@@ -13,22 +13,36 @@ test('directadmin vacation api builds scoped payload for one mailbox', function
$payload = $api->buildSavePayload('info@example.com', [
'subject_prefix' => 'Urlop',
'reply_every_message' => false,
'repeat_minutes' => 1440,
'repeat_minutes' => 1,
'body' => 'Body',
'start_value' => '2026-06-10|morning',
'end_value' => '2026-06-24|evening',
'start_value' => '2026-06-10T00:00',
'end_value' => '2026-06-24T23:59',
]);
assert_same('info', $payload['user']);
assert_same('example.com', $payload['domain']);
assert_same('Body', $payload['text']);
assert_same('Urlop', $payload['subject']);
assert_same('1d', $payload['reply_once_time']);
assert_same('1m', $payload['reply_once_time']);
assert_false(isset($payload['email']));
assert_false(isset($payload['subject_prefix']));
assert_false(isset($payload['reply_frequency']));
assert_same('morning', $payload['starttime']);
assert_same('evening', $payload['endtime']);
assert_same('00:00', $payload['starttime']);
assert_same('23:59', $payload['endtime']);
});
test('directadmin vacation api maps every-message legacy rules to one minute minimum', function (): void {
$api = new DirectAdminVacationApi('/usr/local/directadmin/directadmin');
$payload = $api->buildSavePayload('info@example.com', [
'subject_prefix' => 'Urlop',
'reply_every_message' => true,
'repeat_minutes' => 0,
'body' => 'Body',
'start_value' => '2026-06-10T00:00',
'end_value' => '2026-06-24T23:59',
]);
assert_same('1m', $payload['reply_once_time']);
});
test('directadmin vacation api reports http error response bodies', function (): void {
+18 -8
View File
@@ -59,11 +59,12 @@ test('rule form uses minute time input and no summary box in exim mode', functio
assert_contains(': pierwotny temat', $html);
assert_contains('Częstość odpowiedzi', $html);
assert_contains('Wysyłaj automatyczną odpowiedź dla każdej wiadomości', $html);
assert_contains('14 dni', $html);
assert_contains('1 dzień', $html);
assert_contains('Treść wiadomości', $html);
});
test('rule form uses native period selector in da mode', function (): void {
test('rule form uses exact hour selector and directadmin frequency range in da mode', function (): void {
$settingsPath = TEST_TMP . '/form-da.conf';
test_write($settingsPath, "DEFAULT_PLUGIN_LANGUAGE=pl\nGLOBAL_AUTORESPONDER_BACKEND=da\n");
$settings = Settings::load($settingsPath);
@@ -76,9 +77,18 @@ test('rule form uses native period selector in da mode', function (): void {
new AuditLog(TEST_TMP . '/audit.log')
);
$html = render_rule_form($ctx, 'create', null);
assert_contains('name="start_value_period"', $html);
assert_contains('Rano', $html);
assert_false(strpos($html, 'type="time"') !== false);
assert_contains('type="time"', $html);
assert_contains('step="60"', $html);
assert_contains('1 minuta', $html);
assert_contains('14 dni', $html);
assert_false(strpos($html, 'Wysyłaj automatyczną odpowiedź dla każdej wiadomości') !== false);
assert_false(strpos($html, 'name="start_value_period"') !== false);
});
test('autoresponder table does not expose mailbox scope column', function (): void {
$source = file_get_contents(PLUGIN_ROOT . '/exec/handlers/index.php') ?: '';
assert_false(strpos($source, "ctx->t('Scope')") !== false);
assert_false(strpos($source, "ctx->t(\$rule['dynamic_scope']") !== false);
});
test('mutating handlers synchronize active backend after storage changes', function (): void {
@@ -155,8 +165,8 @@ test('new rule form selects current date for start and end calendars by default'
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);
assert_contains('id="start_value" name="start_value" value="' . $today . 'T00:00"', $html);
assert_contains('id="end_value" name="end_value" value="' . $today . 'T23:59"', $html);
});
test('rule form localizes calendar and preview labels without translating user content globally', function (): void {
@@ -194,8 +204,8 @@ test('directadmin backend allows only one enabled global rule per account', func
'repeat_minutes' => 1440,
'body' => 'Body',
'enabled' => true,
'start_value' => '2026-06-10|morning',
'end_value' => '2026-06-24|evening',
'start_value' => '2026-06-10T00:00',
'end_value' => '2026-06-24T23:59',
]);
$ctx = new AppContext(
new DirectAdminUser('alice', 'enhanced', 'pl', TEST_TMP . '/config'),
+30 -9
View File
@@ -26,21 +26,42 @@ test('rule validator normalizes exact hour schedule', function (): void {
assert_true($rule['start_ts'] < $rule['end_ts']);
});
test('rule validator accepts da period schedule when backend is da', function (): void {
test('rule validator accepts da exact hour schedule when backend is da', function (): void {
$settingsPath = TEST_TMP . '/validator-da.conf';
test_write($settingsPath, "GLOBAL_AUTORESPONDER_BACKEND=da\n");
$settings = Settings::load($settingsPath);
$rule = RuleValidator::validate([
'subject_prefix' => 'Urlop',
'reply_frequency' => 'every',
'reply_frequency' => '1',
'body' => 'Body',
'start_value' => '2026-06-10|morning',
'end_value' => '2026-06-24|evening',
'start_value' => '2026-06-10T00:00',
'end_value' => '2026-06-24T23:59',
'enabled' => '1',
], $settings);
assert_same('directadmin_period', $rule['schedule_mode']);
assert_true($rule['reply_every_message']);
assert_same(0, $rule['repeat_minutes']);
assert_same('exact_hour', $rule['schedule_mode']);
assert_false($rule['reply_every_message']);
assert_same(1, $rule['repeat_minutes']);
assert_same('2026-06-10T00:00', $rule['start_value']);
assert_same('2026-06-24T23:59', $rule['end_value']);
});
test('rule validator rejects every message frequency for da backend', function (): void {
$settingsPath = TEST_TMP . '/validator-da-every.conf';
test_write($settingsPath, "GLOBAL_AUTORESPONDER_BACKEND=da\n");
$settings = Settings::load($settingsPath);
try {
RuleValidator::validate([
'subject_prefix' => 'Urlop',
'reply_frequency' => 'every',
'body' => 'Body',
'start_value' => '2026-06-10T00:00',
'end_value' => '2026-06-24T23:59',
], $settings);
} catch (InvalidArgumentException $e) {
assert_contains('Częstość odpowiedzi', $e->getMessage());
return;
}
throw new RuntimeException('Expected every-message frequency to fail for da backend');
});
test('rule validator rejects header injection and reversed dates', function (): void {
@@ -66,8 +87,8 @@ test('rule validator rejects unsupported response frequency', function (): void
'subject_prefix' => 'Urlop',
'reply_frequency' => '45',
'body' => 'Body',
'start_value' => '2026-06-10|morning',
'end_value' => '2026-06-24|evening',
'start_value' => '2026-06-10T00:00',
'end_value' => '2026-06-24T23:59',
], $settings);
} catch (InvalidArgumentException $e) {
assert_contains('Częstość odpowiedzi', $e->getMessage());