Sync global-autoresponder current state

This commit is contained in:
Marek Miklewicz
2026-07-04 15:16:50 +02:00
parent 196ee224fe
commit af775ce976
47 changed files with 1165 additions and 1037 deletions
+50 -13
View File
@@ -6,9 +6,10 @@ require_once PLUGIN_ROOT . '/exec/lib/RuleValidator.php';
test('rule validator normalizes exact hour schedule', function (): void {
$settingsPath = TEST_TMP . '/validator.conf';
test_write($settingsPath, "GLOBAL_AUTORESPONDER_TIMEZONE=Europe/Warsaw\nGLOBAL_AUTORESPONDER_BACKEND=exim\n");
test_write($settingsPath, "GLOBAL_AUTORESPONDER_TIMEZONE=Europe/Warsaw\n");
$settings = Settings::load($settingsPath);
$rule = RuleValidator::validate([
'name' => 'Urlop czerwcowy',
'subject_prefix' => 'Urlop',
'reply_frequency' => '120',
'body' => "Dzień dobry\r\nWracam jutro",
@@ -17,8 +18,8 @@ test('rule validator normalizes exact hour schedule', function (): void {
'enabled' => '1',
], $settings);
assert_same('Urlop czerwcowy', $rule['name']);
assert_same('Urlop', $rule['subject_prefix']);
assert_false($rule['reply_every_message']);
assert_same(120, $rule['repeat_minutes']);
assert_same("Dzień dobry\nWracam jutro", $rule['body']);
assert_same('exact_hour', $rule['schedule_mode']);
@@ -26,10 +27,8 @@ test('rule validator normalizes exact hour schedule', function (): void {
assert_true($rule['start_ts'] < $rule['end_ts']);
});
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);
test('rule validator accepts exact hour schedule', function (): void {
$settings = Settings::load(TEST_TMP . '/validator-da.conf');
$rule = RuleValidator::validate([
'subject_prefix' => 'Urlop',
'reply_frequency' => '1',
@@ -39,16 +38,13 @@ test('rule validator accepts da exact hour schedule when backend is da', functio
'enabled' => '1',
], $settings);
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);
test('rule validator rejects unsupported non-interval frequency', function (): void {
$settings = Settings::load(TEST_TMP . '/validator-da-every.conf');
try {
RuleValidator::validate([
'subject_prefix' => 'Urlop',
@@ -61,7 +57,7 @@ test('rule validator rejects every message frequency for da backend', function (
assert_contains('Częstość odpowiedzi', $e->getMessage());
return;
}
throw new RuntimeException('Expected every-message frequency to fail for da backend');
throw new RuntimeException('Expected every-message frequency to fail');
});
test('rule validator rejects header injection and reversed dates', function (): void {
@@ -99,7 +95,7 @@ test('rule validator rejects unsupported response frequency', function (): void
test('rule validator rejects start date before current date', function (): void {
$settingsPath = TEST_TMP . '/validator-past.conf';
test_write($settingsPath, "GLOBAL_AUTORESPONDER_TIMEZONE=Europe/Warsaw\nGLOBAL_AUTORESPONDER_BACKEND=exim\n");
test_write($settingsPath, "GLOBAL_AUTORESPONDER_TIMEZONE=Europe/Warsaw\n");
$settings = Settings::load($settingsPath);
$tz = new DateTimeZone($settings->timezone());
$yesterday = (new DateTimeImmutable('yesterday', $tz))->format('Y-m-d');
@@ -119,3 +115,44 @@ test('rule validator rejects start date before current date', function (): void
}
throw new RuntimeException('Expected past start date to fail');
});
test('rule validator rejects end date before current date when creating', function (): void {
$settingsPath = TEST_TMP . '/validator-past-end.conf';
test_write($settingsPath, "GLOBAL_AUTORESPONDER_TIMEZONE=Europe/Warsaw\n");
$settings = Settings::load($settingsPath);
$tz = new DateTimeZone($settings->timezone());
$yesterday = (new DateTimeImmutable('yesterday', $tz))->format('Y-m-d');
$today = (new DateTimeImmutable('today', $tz))->format('Y-m-d');
try {
RuleValidator::validate([
'subject_prefix' => 'Urlop',
'reply_frequency' => '1440',
'body' => 'Body',
'start_value' => $today . 'T09:00',
'end_value' => $yesterday . 'T17:00',
], $settings);
} catch (InvalidArgumentException $e) {
assert_contains('Data zakończenia nie może być wcześniejsza niż aktualna data.', $e->getMessage());
return;
}
throw new RuntimeException('Expected past end date to fail on create');
});
test('rule validator allows past schedule when editing', function (): void {
$settingsPath = TEST_TMP . '/validator-edit-past.conf';
test_write($settingsPath, "GLOBAL_AUTORESPONDER_TIMEZONE=Europe/Warsaw\n");
$settings = Settings::load($settingsPath);
$rule = RuleValidator::validate([
'subject_prefix' => 'Urlop',
'reply_frequency' => '1440',
'body' => 'Body',
'start_value' => '2000-01-10T09:00',
'end_value' => '2000-01-11T17:00',
], $settings, true);
assert_same('2000-01-10T09:00', $rule['start_value']);
assert_same('2000-01-11T17:00', $rule['end_value']);
assert_true($rule['start_ts'] < $rule['end_ts']);
});