Sync global-autoresponder current state
This commit is contained in:
@@ -1,21 +0,0 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
require_once PLUGIN_ROOT . '/exec/lib/Settings.php';
|
||||
require_once PLUGIN_ROOT . '/exec/lib/BackendRuntimeConfig.php';
|
||||
|
||||
test('backend runtime sync invokes backend script when setting changes', function (): void {
|
||||
$settingsPath = TEST_TMP . '/backend-runtime.conf';
|
||||
test_write($settingsPath, "GLOBAL_AUTORESPONDER_BACKEND=exim\n");
|
||||
$settings = Settings::load($settingsPath);
|
||||
|
||||
$script = TEST_TMP . '/backend.sh';
|
||||
test_write($script, "#!/bin/sh\necho \"$1\" >> " . escapeshellarg(TEST_TMP . '/called.log') . "\nmkdir -p " . escapeshellarg(TEST_TMP . '/config') . "\nprintf '{\"active_backend\":\"%s\"}\\n' \"$1\" > " . escapeshellarg(TEST_TMP . '/config/backend-state.json') . "\n");
|
||||
chmod($script, 0700);
|
||||
|
||||
BackendRuntimeConfig::sync($settings, $script, TEST_TMP . '/config/backend-state.json');
|
||||
assert_same("exim\n", file_get_contents(TEST_TMP . '/called.log'));
|
||||
|
||||
BackendRuntimeConfig::sync($settings, $script, TEST_TMP . '/config/backend-state.json');
|
||||
assert_same("exim\n", file_get_contents(TEST_TMP . '/called.log'), 'Script should not run again when backend is already active');
|
||||
});
|
||||
+19
-13
@@ -10,7 +10,6 @@ test('settings validate defaults and external paths', function (): void {
|
||||
'DEFAULT_PLUGIN_LANGUAGE=pl',
|
||||
'DEFAULT_ENABLE=false',
|
||||
'GLOBAL_AUTORESPONDER_TIMEZONE=Europe/Warsaw',
|
||||
'GLOBAL_AUTORESPONDER_BACKEND=exim',
|
||||
'GLOBAL_AUTORESPONDER_DYNAMIC_MAILBOX_SCOPE=true',
|
||||
'GLOBAL_AUTORESPONDER_MAX_SUBJECT_BYTES=255',
|
||||
'GLOBAL_AUTORESPONDER_MAX_BODY_BYTES=20000',
|
||||
@@ -21,7 +20,6 @@ test('settings validate defaults and external paths', function (): void {
|
||||
assert_false($settings->defaultEnable());
|
||||
assert_same('Europe/Warsaw', $settings->timezone());
|
||||
assert_same('exact_hour', $settings->scheduleMode());
|
||||
assert_same('exim', $settings->backendMode());
|
||||
assert_same('/usr/local/hitme_plugins/global-autoresponders/config', Settings::CONFIG_DIR);
|
||||
assert_same('/usr/local/hitme_plugins/global-autoresponders/data', Settings::DATA_DIR);
|
||||
});
|
||||
@@ -34,7 +32,7 @@ test('settings template does not contain global repeat policy settings', functio
|
||||
|
||||
test('settings reject invalid timezone and schedule mode', function (): void {
|
||||
$path = TEST_TMP . '/bad-settings.conf';
|
||||
test_write($path, "GLOBAL_AUTORESPONDER_TIMEZONE=Not/AZone\nGLOBAL_AUTORESPONDER_BACKEND=bad\n");
|
||||
test_write($path, "GLOBAL_AUTORESPONDER_TIMEZONE=Not/AZone\n");
|
||||
try {
|
||||
Settings::load($path);
|
||||
} catch (InvalidArgumentException $e) {
|
||||
@@ -44,16 +42,8 @@ test('settings reject invalid timezone and schedule mode', function (): void {
|
||||
throw new RuntimeException('Expected invalid settings to fail');
|
||||
});
|
||||
|
||||
test('backend mode derives schedule mode', function (): void {
|
||||
$path = TEST_TMP . '/backend.conf';
|
||||
test_write($path, "GLOBAL_AUTORESPONDER_BACKEND=da\n");
|
||||
$settings = Settings::load($path);
|
||||
assert_same('da', $settings->backendMode());
|
||||
assert_same('exact_hour', $settings->scheduleMode());
|
||||
|
||||
test_write($path, "GLOBAL_AUTORESPONDER_BACKEND=exim\n");
|
||||
$settings = Settings::load($path);
|
||||
assert_same('exim', $settings->backendMode());
|
||||
test('settings keep exact schedule mode', function (): void {
|
||||
$settings = Settings::load(TEST_TMP . '/schedule.conf');
|
||||
assert_same('exact_hour', $settings->scheduleMode());
|
||||
});
|
||||
|
||||
@@ -67,3 +57,19 @@ test('directadmin user access follows DEFAULT_ENABLE and per-user overrides', fu
|
||||
test_write(TEST_TMP . '/config/users/marek.conf', "enabled=true\n");
|
||||
assert_true($user->hasPluginAccess($settings));
|
||||
});
|
||||
|
||||
test('directadmin user normalizes evolution skin variants', function (): void {
|
||||
assert_same('evolution', (new DirectAdminUser('marek', 'Evolution', 'en', TEST_TMP . '/config'))->skin());
|
||||
assert_same('evolution', (new DirectAdminUser('marek', 'evolution-ui', 'en', TEST_TMP . '/config'))->skin());
|
||||
assert_same('enhanced', (new DirectAdminUser('marek', '', 'en', TEST_TMP . '/config'))->skin());
|
||||
});
|
||||
|
||||
test('directadmin user checks common skin environment variables', function (): void {
|
||||
$source = file_get_contents(PLUGIN_ROOT . '/exec/lib/DirectAdminUser.php') ?: '';
|
||||
|
||||
assert_contains('SESSION_SKIN', $source);
|
||||
assert_contains('SESSION_SELECTED_SKIN', $source);
|
||||
assert_contains('DA_SKIN', $source);
|
||||
assert_contains("['skin']", $source);
|
||||
assert_contains('readUserConf', $source);
|
||||
});
|
||||
|
||||
@@ -12,7 +12,6 @@ test('directadmin vacation api builds scoped payload for one mailbox', function
|
||||
$api = new DirectAdminVacationApi('/usr/local/directadmin/directadmin');
|
||||
$payload = $api->buildSavePayload('info@example.com', [
|
||||
'subject_prefix' => 'Urlop',
|
||||
'reply_every_message' => false,
|
||||
'repeat_minutes' => 1,
|
||||
'body' => 'Body',
|
||||
'start_value' => '2026-06-10T00:00',
|
||||
@@ -31,20 +30,6 @@ test('directadmin vacation api builds scoped payload for one mailbox', function
|
||||
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 {
|
||||
$runner = static function (array $args, string $stdin): string {
|
||||
if ($args[0] === '/bin/echo') {
|
||||
@@ -58,7 +43,6 @@ test('directadmin vacation api reports http error response bodies', function ():
|
||||
try {
|
||||
$api->saveVacation('alice', 'info@example.com', [
|
||||
'subject_prefix' => 'Urlop',
|
||||
'reply_every_message' => false,
|
||||
'repeat_minutes' => 1440,
|
||||
'body' => 'Body',
|
||||
'start_value' => '2026-06-10|morning',
|
||||
@@ -85,7 +69,6 @@ test('directadmin vacation api reports legacy api error payloads', function ():
|
||||
try {
|
||||
$api->saveVacation('alice', 'info@example.com', [
|
||||
'subject_prefix' => 'Urlop',
|
||||
'reply_every_message' => false,
|
||||
'repeat_minutes' => 1440,
|
||||
'body' => 'Body',
|
||||
'start_value' => '2026-06-10|morning',
|
||||
|
||||
@@ -16,7 +16,6 @@ test('directadmin vacation sync creates tracked entries for enabled rule mailbox
|
||||
$repo = new RuleRepository(TEST_TMP . '/da-sync-data');
|
||||
$rule = $repo->create('alice', [
|
||||
'subject_prefix' => 'Urlop',
|
||||
'reply_every_message' => false,
|
||||
'repeat_minutes' => 1440,
|
||||
'body' => 'Body',
|
||||
'start_value' => '2026-06-10|morning',
|
||||
@@ -71,7 +70,6 @@ test('directadmin vacation sync deletes stale tracked entries after rule removal
|
||||
$syncRepo = new DirectAdminSyncRepository($dataDir);
|
||||
$rule = $repo->create('alice', [
|
||||
'subject_prefix' => 'Urlop',
|
||||
'reply_every_message' => false,
|
||||
'repeat_minutes' => 1440,
|
||||
'body' => 'Body',
|
||||
'start_value' => '2026-06-10|morning',
|
||||
@@ -112,7 +110,6 @@ test('directadmin vacation sync refuses to overwrite untracked native vacation',
|
||||
$repo = new RuleRepository($dataDir);
|
||||
$repo->create('alice', [
|
||||
'subject_prefix' => 'Urlop',
|
||||
'reply_every_message' => false,
|
||||
'repeat_minutes' => 1440,
|
||||
'body' => 'Body',
|
||||
'start_value' => '2026-06-10|morning',
|
||||
@@ -153,3 +150,98 @@ test('directadmin vacation sync refuses to overwrite untracked native vacation',
|
||||
assert_true($thrown);
|
||||
assert_same([], $calls);
|
||||
});
|
||||
|
||||
test('directadmin vacation sync preflights all target mailboxes before saving', function (): void {
|
||||
$virtualRoot = TEST_TMP . '/da-sync-preflight-virtual';
|
||||
test_write($virtualRoot . '/domainowners', "example.com: alice\n");
|
||||
test_write($virtualRoot . '/example.com/passwd', "info:x:1000:12::/home/alice/imap/example.com/info:/bin/false\nsales:x:1000:12::/home/alice/imap/example.com/sales:/bin/false\n");
|
||||
|
||||
$dataDir = TEST_TMP . '/da-sync-preflight-data';
|
||||
$repo = new RuleRepository($dataDir);
|
||||
$repo->create('alice', [
|
||||
'subject_prefix' => 'Urlop',
|
||||
'repeat_minutes' => 1440,
|
||||
'body' => 'Body',
|
||||
'start_value' => '2026-06-10|morning',
|
||||
'end_value' => '2026-06-24|evening',
|
||||
'start_ts' => 1,
|
||||
'end_ts' => 2,
|
||||
'enabled' => true,
|
||||
'dynamic_scope' => true,
|
||||
]);
|
||||
|
||||
$calls = [];
|
||||
$api = new class($calls) extends DirectAdminVacationApi {
|
||||
public function __construct(private array &$calls) {}
|
||||
public function vacationExists(string $owner, string $email): bool
|
||||
{
|
||||
return $email === 'sales@example.com';
|
||||
}
|
||||
public function saveVacation(string $owner, string $email, array $rule, bool $exists): void
|
||||
{
|
||||
$this->calls[] = ['save', $owner, $email];
|
||||
}
|
||||
};
|
||||
|
||||
$sync = new DirectAdminVacationSyncService(
|
||||
$repo,
|
||||
new DirectAdminSyncRepository($dataDir),
|
||||
new MailboxDirectory($virtualRoot),
|
||||
$api
|
||||
);
|
||||
|
||||
$thrown = false;
|
||||
try {
|
||||
$sync->syncUser('alice');
|
||||
} catch (RuntimeException $e) {
|
||||
$thrown = true;
|
||||
assert_contains('sales@example.com', $e->getMessage());
|
||||
}
|
||||
assert_true($thrown);
|
||||
assert_same([], $calls, 'No vacation should be saved before all conflicts are known');
|
||||
});
|
||||
|
||||
test('directadmin vacation sync lists and disables untracked native vacations for user domains', function (): void {
|
||||
$virtualRoot = TEST_TMP . '/da-native-list-virtual';
|
||||
test_write($virtualRoot . '/domainowners', "example.com: alice\nother.com: bob\n");
|
||||
test_write($virtualRoot . '/example.com/passwd', "info:x:1000:12::/home/alice/imap/example.com/info:/bin/false\n");
|
||||
|
||||
$dataDir = TEST_TMP . '/da-native-list-data';
|
||||
$repo = new RuleRepository($dataDir);
|
||||
$syncRepo = new DirectAdminSyncRepository($dataDir);
|
||||
$rule = $repo->create('alice', [
|
||||
'subject_prefix' => 'Urlop',
|
||||
'body' => 'Body',
|
||||
'start_ts' => 1,
|
||||
'end_ts' => 2,
|
||||
'enabled' => true,
|
||||
]);
|
||||
$syncRepo->replaceRuleEntries('alice', (string)$rule['id'], [
|
||||
['email' => 'tracked@example.com', 'domain' => 'example.com', 'mailbox' => 'tracked', 'api_key' => 'tracked@example.com'],
|
||||
]);
|
||||
|
||||
$calls = [];
|
||||
$api = new class($calls) extends DirectAdminVacationApi {
|
||||
public function __construct(private array &$calls) {}
|
||||
public function listVacations(string $owner, string $domain): array
|
||||
{
|
||||
return $domain === 'example.com' ? ['manual', 'tracked'] : ['foreign'];
|
||||
}
|
||||
public function deleteVacation(string $owner, string $email): void
|
||||
{
|
||||
$this->calls[] = ['delete', $owner, $email];
|
||||
}
|
||||
};
|
||||
|
||||
$sync = new DirectAdminVacationSyncService($repo, $syncRepo, new MailboxDirectory($virtualRoot), $api);
|
||||
$native = $sync->untrackedNativeVacations('alice');
|
||||
|
||||
assert_same([[
|
||||
'domain' => 'example.com',
|
||||
'mailbox' => 'manual',
|
||||
'email' => 'manual@example.com',
|
||||
]], $native);
|
||||
|
||||
$sync->deleteNativeVacations('alice', $native);
|
||||
assert_same([['delete', 'alice', 'manual@example.com']], $calls);
|
||||
});
|
||||
|
||||
@@ -1,151 +0,0 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
require_once PLUGIN_ROOT . '/scripts/global_autoresponder_worker.php';
|
||||
|
||||
test('exim worker sends active rule for resolved mailbox only', function (): void {
|
||||
$settingsPath = TEST_TMP . '/worker-settings.conf';
|
||||
test_write($settingsPath, "GLOBAL_AUTORESPONDER_BACKEND=exim\n");
|
||||
$settings = Settings::load($settingsPath);
|
||||
|
||||
$virtualRoot = TEST_TMP . '/worker-virtual';
|
||||
test_write($virtualRoot . '/domainowners', "example.com: alice\n");
|
||||
test_write($virtualRoot . '/example.com/passwd', "info:x:1000:12::/home/alice/imap/example.com/info:/bin/false\n");
|
||||
|
||||
$repo = new RuleRepository(TEST_TMP . '/worker-data');
|
||||
$created = $repo->create('alice', [
|
||||
'subject' => 'Urlop',
|
||||
'subject_prefix' => 'Urlop',
|
||||
'reply_every_message' => false,
|
||||
'repeat_minutes' => 60,
|
||||
'body' => 'Odpowiem później',
|
||||
'start_ts' => 900,
|
||||
'end_ts' => 1100,
|
||||
'enabled' => true,
|
||||
]);
|
||||
|
||||
$sent = [];
|
||||
$worker = new GlobalAutoresponderWorker(
|
||||
$settings,
|
||||
$repo,
|
||||
new MailboxDirectory($virtualRoot),
|
||||
new RepeatState(TEST_TMP . '/worker-state', 1000),
|
||||
static function (string $from, string $to, string $subject, string $body) use (&$sent): bool {
|
||||
$sent[] = compact('from', 'to', 'subject', 'body');
|
||||
return true;
|
||||
},
|
||||
1000
|
||||
);
|
||||
|
||||
$count = $worker->handle(
|
||||
['SENDER_ADDRESS' => 'person@example.net', 'LOCAL_PART' => 'info', 'DOMAIN' => 'example.com'],
|
||||
"Auto-Submitted: no\nSubject: hello\n\nBody"
|
||||
);
|
||||
|
||||
assert_same(1, $count);
|
||||
assert_same('info@example.com', $sent[0]['from']);
|
||||
assert_same('person@example.net', $sent[0]['to']);
|
||||
assert_same('Urlop: hello', $sent[0]['subject']);
|
||||
assert_same('Odpowiem później', $sent[0]['body']);
|
||||
|
||||
$count = $worker->handle(
|
||||
['SENDER_ADDRESS' => 'person@example.net', 'RECIPIENT' => 'info@example.com'],
|
||||
"Auto-Submitted: no\nSubject: hello\n\nBody"
|
||||
);
|
||||
assert_same(0, $count, 'repeat policy should block immediate second response');
|
||||
|
||||
assert_true(isset($created['id']));
|
||||
});
|
||||
|
||||
test('exim worker suppresses automated messages and ignores unresolved recipients', function (): void {
|
||||
$settingsPath = TEST_TMP . '/worker-suppress-settings.conf';
|
||||
test_write($settingsPath, "GLOBAL_AUTORESPONDER_BACKEND=exim\n");
|
||||
$settings = Settings::load($settingsPath);
|
||||
|
||||
$virtualRoot = TEST_TMP . '/worker-suppress-virtual';
|
||||
test_write($virtualRoot . '/domainowners', "example.com: alice\n");
|
||||
test_write($virtualRoot . '/example.com/passwd', "info:x:1000:12::/home/alice/imap/example.com/info:/bin/false\n");
|
||||
test_write($virtualRoot . '/example.com/aliases', "alias: info\n");
|
||||
|
||||
$repo = new RuleRepository(TEST_TMP . '/worker-suppress-data');
|
||||
$repo->create('alice', [
|
||||
'subject_prefix' => 'Urlop',
|
||||
'reply_every_message' => true,
|
||||
'repeat_minutes' => 0,
|
||||
'body' => 'Body',
|
||||
'start_ts' => 1,
|
||||
'end_ts' => 2000,
|
||||
'enabled' => true,
|
||||
]);
|
||||
|
||||
$sent = 0;
|
||||
$worker = new GlobalAutoresponderWorker(
|
||||
$settings,
|
||||
$repo,
|
||||
new MailboxDirectory($virtualRoot),
|
||||
new RepeatState(TEST_TMP . '/worker-suppress-state', 1000),
|
||||
static function () use (&$sent): bool {
|
||||
$sent++;
|
||||
return true;
|
||||
},
|
||||
1000
|
||||
);
|
||||
|
||||
assert_same(0, $worker->handle(
|
||||
['SENDER_ADDRESS' => 'person@example.net', 'RECIPIENT' => 'info@example.com'],
|
||||
"Precedence: bulk\n\nBody"
|
||||
));
|
||||
assert_same(0, $worker->handle(
|
||||
['SENDER_ADDRESS' => 'person@example.net', 'RECIPIENT' => 'alias@example.com'],
|
||||
"Auto-Submitted: no\n\nBody"
|
||||
));
|
||||
assert_same(0, $sent);
|
||||
});
|
||||
|
||||
test('exim worker respects static mailbox snapshot scope', function (): void {
|
||||
$settingsPath = TEST_TMP . '/worker-snapshot-settings.conf';
|
||||
test_write($settingsPath, "GLOBAL_AUTORESPONDER_BACKEND=exim\n");
|
||||
$settings = Settings::load($settingsPath);
|
||||
|
||||
$virtualRoot = TEST_TMP . '/worker-snapshot-virtual';
|
||||
test_write($virtualRoot . '/domainowners', "example.com: alice\n");
|
||||
test_write($virtualRoot . '/example.com/passwd', "info:x:1000:12::/home/alice/imap/example.com/info:/bin/false\nsales:x:1000:12::/home/alice/imap/example.com/sales:/bin/false\n");
|
||||
|
||||
$repo = new RuleRepository(TEST_TMP . '/worker-snapshot-data');
|
||||
$repo->create('alice', [
|
||||
'subject_prefix' => 'Urlop',
|
||||
'reply_every_message' => true,
|
||||
'repeat_minutes' => 0,
|
||||
'body' => 'Body',
|
||||
'start_ts' => 1,
|
||||
'end_ts' => 2000,
|
||||
'enabled' => true,
|
||||
'dynamic_scope' => false,
|
||||
'mailbox_snapshot' => [
|
||||
['domain' => 'example.com', 'mailbox' => 'info', 'email' => 'info@example.com'],
|
||||
],
|
||||
]);
|
||||
|
||||
$sent = 0;
|
||||
$worker = new GlobalAutoresponderWorker(
|
||||
$settings,
|
||||
$repo,
|
||||
new MailboxDirectory($virtualRoot),
|
||||
new RepeatState(TEST_TMP . '/worker-snapshot-state', 1000),
|
||||
static function () use (&$sent): bool {
|
||||
$sent++;
|
||||
return true;
|
||||
},
|
||||
1000
|
||||
);
|
||||
|
||||
assert_same(0, $worker->handle(
|
||||
['SENDER_ADDRESS' => 'person@example.net', 'RECIPIENT' => 'sales@example.com'],
|
||||
"Auto-Submitted: no\n\nBody"
|
||||
));
|
||||
assert_same(1, $worker->handle(
|
||||
['SENDER_ADDRESS' => 'person@example.net', 'RECIPIENT' => 'info@example.com'],
|
||||
"Auto-Submitted: no\n\nBody"
|
||||
));
|
||||
assert_same(1, $sent);
|
||||
});
|
||||
+304
-20
@@ -1,12 +1,12 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
test('mockup and planned UI do not expose backend terms', function (): void {
|
||||
test('mockup and planned UI do not expose removed internal mail terms', function (): void {
|
||||
foreach (glob(dirname(__DIR__, 2) . '/docs/mockups/*.html') ?: [] as $file) {
|
||||
$html = file_get_contents($file) ?: '';
|
||||
assert_false(stripos($html, 'Exim') !== false, basename($file) . ' exposes Exim');
|
||||
assert_false(stripos($html, 'Ex' . 'im') !== false, basename($file) . ' exposes removed mail integration');
|
||||
assert_false(stripos($html, 'DirectAdmin API') !== false, basename($file) . ' exposes API');
|
||||
assert_false(stripos($html, 'backend.sh') !== false, basename($file) . ' exposes backend script');
|
||||
assert_false(stripos($html, 'back' . 'end.sh') !== false, basename($file) . ' exposes removed switch script');
|
||||
}
|
||||
});
|
||||
|
||||
@@ -46,7 +46,7 @@ test('autoresponder index keeps add button only in top navigation', function ():
|
||||
assert_false(strpos($source, "ctx->t('Add autoresponder')") !== false);
|
||||
});
|
||||
|
||||
test('rule form uses minute time input and no summary box in exim mode', function (): void {
|
||||
test('rule form uses minute time input and directadmin frequency range', function (): void {
|
||||
require_once PLUGIN_ROOT . '/exec/lib/Settings.php';
|
||||
require_once PLUGIN_ROOT . '/exec/lib/Lang.php';
|
||||
require_once PLUGIN_ROOT . '/exec/lib/DirectAdminUser.php';
|
||||
@@ -57,7 +57,7 @@ test('rule form uses minute time input and no summary box in exim mode', functio
|
||||
require_once PLUGIN_ROOT . '/exec/handlers/_form_helpers.php';
|
||||
|
||||
$settingsPath = TEST_TMP . '/form.conf';
|
||||
test_write($settingsPath, "DEFAULT_PLUGIN_LANGUAGE=pl\nGLOBAL_AUTORESPONDER_BACKEND=exim\n");
|
||||
test_write($settingsPath, "DEFAULT_PLUGIN_LANGUAGE=pl\n");
|
||||
$settings = Settings::load($settingsPath);
|
||||
$ctx = new AppContext(
|
||||
new DirectAdminUser('alice', 'enhanced', 'pl', TEST_TMP . '/config'),
|
||||
@@ -69,21 +69,230 @@ test('rule form uses minute time input and no summary box in exim mode', functio
|
||||
);
|
||||
|
||||
$html = render_rule_form($ctx, 'create', null);
|
||||
assert_contains('name="name"', $html);
|
||||
assert_contains('Nazwa autorespondera', $html);
|
||||
assert_contains('Ta nazwa jest wykorzystywana tylko w celach opisowych', $html);
|
||||
assert_contains('type="time"', $html);
|
||||
assert_contains('step="60"', $html);
|
||||
assert_false(strpos($html, 'summary-card') !== false, 'Summary box should not be rendered in create/edit form');
|
||||
assert_contains('Przedrostek tematu', $html);
|
||||
assert_contains(': pierwotny temat', $html);
|
||||
assert_contains('Częstość odpowiedzi', $html);
|
||||
assert_contains('Wysyłaj automatyczną odpowiedź dla każdej wiadomości', $html);
|
||||
assert_false(strpos($html, 'Wysyłaj automatyczną odpowiedź dla każdej wiadomości') !== false);
|
||||
assert_contains('14 dni', $html);
|
||||
assert_contains('1 minuta', $html);
|
||||
assert_contains('1 dzień', $html);
|
||||
assert_contains('Treść wiadomości', $html);
|
||||
});
|
||||
|
||||
test('rule form uses exact hour selector and directadmin frequency range in da mode', function (): void {
|
||||
test('autoresponder index shows descriptive name and created timestamp columns', function (): void {
|
||||
$settingsPath = TEST_TMP . '/index-columns.conf';
|
||||
test_write($settingsPath, "DEFAULT_PLUGIN_LANGUAGE=pl\n");
|
||||
$settings = Settings::load($settingsPath);
|
||||
$repo = new RuleRepository(TEST_TMP . '/index-data');
|
||||
$repo->create('alice', [
|
||||
'name' => 'Urlop zarządu',
|
||||
'subject_prefix' => 'Urlop',
|
||||
'repeat_minutes' => 1440,
|
||||
'body' => 'Body',
|
||||
'enabled' => true,
|
||||
'start_ts' => 1780495200,
|
||||
'end_ts' => 1780581540,
|
||||
]);
|
||||
$ctx = new AppContext(
|
||||
new DirectAdminUser('alice', 'enhanced', 'pl', TEST_TMP . '/config'),
|
||||
$settings,
|
||||
$repo,
|
||||
new CsrfGuard('secret', 'alice', 'sid'),
|
||||
Lang::load('pl', $settings),
|
||||
new AuditLog(TEST_TMP . '/audit.log')
|
||||
);
|
||||
|
||||
$html = render_rules_index_body($ctx);
|
||||
assert_contains('Nazwa autorespondera', $html);
|
||||
assert_contains('Utworzono', $html);
|
||||
assert_contains('Urlop zarządu', $html);
|
||||
assert_false(strpos($html, 'Zaktualizowano') !== false);
|
||||
});
|
||||
|
||||
test('dashboard omits account mailbox helper subtitles', function (): void {
|
||||
$settingsPath = TEST_TMP . '/index-subtitles.conf';
|
||||
test_write($settingsPath, "DEFAULT_PLUGIN_LANGUAGE=pl\n");
|
||||
$settings = Settings::load($settingsPath);
|
||||
$repo = new RuleRepository(TEST_TMP . '/index-subtitles-data');
|
||||
$repo->create('alice', [
|
||||
'name' => 'Urlop zarządu',
|
||||
'subject_prefix' => 'Urlop',
|
||||
'repeat_minutes' => 1440,
|
||||
'body' => 'Body',
|
||||
'enabled' => true,
|
||||
'start_ts' => 1780495200,
|
||||
'end_ts' => 1780581540,
|
||||
]);
|
||||
$ctx = new AppContext(
|
||||
new DirectAdminUser('alice', 'enhanced', 'pl', TEST_TMP . '/config'),
|
||||
$settings,
|
||||
$repo,
|
||||
new CsrfGuard('secret', 'alice', 'sid'),
|
||||
Lang::load('pl', $settings),
|
||||
new AuditLog(TEST_TMP . '/audit.log')
|
||||
);
|
||||
|
||||
$index = render_rules_index_body($ctx);
|
||||
$chrome = file_get_contents(PLUGIN_ROOT . '/exec/lib/AppContext.php') ?: '';
|
||||
|
||||
assert_false(strpos($index, 'Wszystkie prawidłowe skrzynki POP/IMAP konta') !== false);
|
||||
assert_false(strpos($chrome, 'Manage automatic replies for account mailboxes') !== false);
|
||||
});
|
||||
|
||||
test('create conflict modal offers replacing active rule or adding disabled rule', function (): void {
|
||||
$settingsPath = TEST_TMP . '/create-conflict.conf';
|
||||
test_write($settingsPath, "DEFAULT_PLUGIN_LANGUAGE=pl\n");
|
||||
$settings = Settings::load($settingsPath);
|
||||
$repo = new RuleRepository(TEST_TMP . '/create-conflict-data');
|
||||
$existing = $repo->create('alice', [
|
||||
'name' => 'Stary urlop',
|
||||
'subject_prefix' => 'Urlop',
|
||||
'repeat_minutes' => 1440,
|
||||
'body' => 'Body',
|
||||
'enabled' => true,
|
||||
'start_ts' => 1780495200,
|
||||
'end_ts' => 1780581540,
|
||||
]);
|
||||
$ctx = new AppContext(
|
||||
new DirectAdminUser('alice', 'enhanced', 'pl', TEST_TMP . '/config'),
|
||||
$settings,
|
||||
$repo,
|
||||
new CsrfGuard('secret', 'alice', 'sid'),
|
||||
Lang::load('pl', $settings),
|
||||
new AuditLog(TEST_TMP . '/audit.log')
|
||||
);
|
||||
|
||||
$modal = render_create_conflict_modal($ctx, [
|
||||
'name' => 'Nowy urlop',
|
||||
'subject_prefix' => 'Nowy',
|
||||
'repeat_minutes' => 1440,
|
||||
'body' => 'Nowa treść',
|
||||
'enabled' => true,
|
||||
'start_value' => '2026-06-10T00:00',
|
||||
'end_value' => '2026-06-24T23:59',
|
||||
], $existing);
|
||||
|
||||
assert_contains('Dla użytkownika alice istnieje już globalny autoresponder', $modal);
|
||||
assert_contains('Stary urlop', $modal);
|
||||
assert_contains('Nowy urlop', $modal);
|
||||
assert_contains('name="conflict_action" value="replace"', $modal);
|
||||
assert_contains('name="conflict_action" value="create_disabled"', $modal);
|
||||
assert_contains('Włącz autoresponder (Nowy urlop) i wyłącz poprzedni (Stary urlop)', $modal);
|
||||
assert_contains('Dodaj autoresponder (Nowy urlop) jako wyłączony', $modal);
|
||||
});
|
||||
|
||||
test('native directadmin autoresponder modal lists entries before creating global rule', function (): void {
|
||||
$settingsPath = TEST_TMP . '/native-conflict.conf';
|
||||
test_write($settingsPath, "DEFAULT_PLUGIN_LANGUAGE=pl\n");
|
||||
$settings = Settings::load($settingsPath);
|
||||
$ctx = new AppContext(
|
||||
new DirectAdminUser('alice', 'enhanced', 'pl', TEST_TMP . '/config'),
|
||||
$settings,
|
||||
new RuleRepository(TEST_TMP . '/native-conflict-data'),
|
||||
new CsrfGuard('secret', 'alice', 'sid'),
|
||||
Lang::load('pl', $settings),
|
||||
new AuditLog(TEST_TMP . '/audit.log')
|
||||
);
|
||||
|
||||
$modal = render_native_vacation_conflict_modal($ctx, [
|
||||
'name' => 'Nowy urlop',
|
||||
'subject_prefix' => 'Nowy',
|
||||
'repeat_minutes' => 1440,
|
||||
'body' => 'Nowa treść',
|
||||
'enabled' => true,
|
||||
'start_value' => '2026-06-10T00:00',
|
||||
'end_value' => '2026-06-24T23:59',
|
||||
], [
|
||||
['domain' => 'example.com', 'mailbox' => 'info', 'email' => 'info@example.com'],
|
||||
['domain' => 'example.com', 'mailbox' => 'sales', 'email' => 'sales@example.com'],
|
||||
]);
|
||||
|
||||
assert_contains('użytkownik alice ma już utworzone natywne autorespondery', $modal);
|
||||
assert_contains('info@example.com', $modal);
|
||||
assert_contains('sales@example.com', $modal);
|
||||
assert_contains('name="native_conflict_action" value="disable_native"', $modal);
|
||||
assert_contains('<strong>Istniejące autorespondery / wiadomości urlopowe zostaną usunięte w przypadku kontynuacji.</strong>', $modal);
|
||||
assert_contains('class="danger-fill" type="submit">USUŃ ISTNIEJĄCE AUTORESPONDERY</button>', $modal);
|
||||
assert_contains('Anuluj', $modal);
|
||||
});
|
||||
|
||||
test('delete confirmation only asks yes no with rule name and created date', function (): void {
|
||||
$settingsPath = TEST_TMP . '/delete-confirm.conf';
|
||||
test_write($settingsPath, "DEFAULT_PLUGIN_LANGUAGE=pl\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 . '/delete-confirm-data'),
|
||||
new CsrfGuard('secret', 'alice', 'sid'),
|
||||
Lang::load('pl', $settings),
|
||||
new AuditLog(TEST_TMP . '/audit.log')
|
||||
);
|
||||
$rule = [
|
||||
'id' => 'rule-delete',
|
||||
'name' => 'Urlop testowy',
|
||||
'subject_prefix' => 'Urlop',
|
||||
'created_at' => 1780495200,
|
||||
];
|
||||
|
||||
$html = render_delete_confirmation_body($ctx, $rule);
|
||||
|
||||
assert_contains('Czy napewno chcesz usunąć globalny autoresponder Urlop testowy utworzony 2026-06-03 16:00?', $html);
|
||||
assert_contains('>Tak</button>', $html);
|
||||
assert_contains('>Nie</a>', $html);
|
||||
assert_false(strpos($html, 'Preview autoresponder') !== false);
|
||||
assert_false(strpos($html, 'Deleting this rule will disable') !== false);
|
||||
assert_false(strpos($html, 'Treść odpowiedzi') !== false);
|
||||
});
|
||||
|
||||
test('toggle conflict modal asks before replacing currently active rule', function (): void {
|
||||
$settingsPath = TEST_TMP . '/toggle-conflict.conf';
|
||||
test_write($settingsPath, "DEFAULT_PLUGIN_LANGUAGE=pl\n");
|
||||
$settings = Settings::load($settingsPath);
|
||||
$repo = new RuleRepository(TEST_TMP . '/toggle-conflict-data');
|
||||
$existing = $repo->create('alice', [
|
||||
'name' => 'Aktywny urlop',
|
||||
'subject_prefix' => 'Urlop',
|
||||
'repeat_minutes' => 1440,
|
||||
'body' => 'Body',
|
||||
'enabled' => true,
|
||||
'start_ts' => 1780495200,
|
||||
'end_ts' => 1780581540,
|
||||
]);
|
||||
$target = $repo->create('alice', [
|
||||
'name' => 'Nowy aktywny',
|
||||
'subject_prefix' => 'Nowy',
|
||||
'repeat_minutes' => 1440,
|
||||
'body' => 'Body',
|
||||
'enabled' => false,
|
||||
'start_ts' => 1780495200,
|
||||
'end_ts' => 1780581540,
|
||||
]);
|
||||
$ctx = new AppContext(
|
||||
new DirectAdminUser('alice', 'enhanced', 'pl', TEST_TMP . '/config'),
|
||||
$settings,
|
||||
$repo,
|
||||
new CsrfGuard('secret', 'alice', 'sid'),
|
||||
Lang::load('pl', $settings),
|
||||
new AuditLog(TEST_TMP . '/audit.log')
|
||||
);
|
||||
|
||||
$modal = render_toggle_conflict_modal($ctx, $target, $existing);
|
||||
assert_contains('może być aktywny tylko jeden globalny autoresponder', $modal);
|
||||
assert_contains('Włącz autoresponder', $modal);
|
||||
assert_contains('name="conflict_action" value="replace"', $modal);
|
||||
assert_contains('name="id" value="' . $target['id'] . '"', $modal);
|
||||
});
|
||||
|
||||
test('rule form uses exact hour selector and directadmin frequency range', function (): void {
|
||||
$settingsPath = TEST_TMP . '/form-da.conf';
|
||||
test_write($settingsPath, "DEFAULT_PLUGIN_LANGUAGE=pl\nGLOBAL_AUTORESPONDER_BACKEND=da\n");
|
||||
test_write($settingsPath, "DEFAULT_PLUGIN_LANGUAGE=pl\n");
|
||||
$settings = Settings::load($settingsPath);
|
||||
$ctx = new AppContext(
|
||||
new DirectAdminUser('alice', 'enhanced', 'pl', TEST_TMP . '/config'),
|
||||
@@ -102,22 +311,69 @@ test('rule form uses exact hour selector and directadmin frequency range in da m
|
||||
assert_false(strpos($html, 'name="start_value_period"') !== false);
|
||||
});
|
||||
|
||||
test('rule form groups start and end calendars in one schedule panel', function (): void {
|
||||
$settingsPath = TEST_TMP . '/form-schedule-layout.conf';
|
||||
test_write($settingsPath, "DEFAULT_PLUGIN_LANGUAGE=pl\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')
|
||||
);
|
||||
|
||||
$html = render_rule_form($ctx, 'create', null);
|
||||
assert_same(1, substr_count($html, 'schedule-panel'));
|
||||
assert_contains('schedule-grid', $html);
|
||||
assert_contains('schedule-column schedule-start', $html);
|
||||
assert_contains('schedule-column schedule-end', $html);
|
||||
assert_contains('Data rozpoczęcia', $html);
|
||||
assert_contains('Godzina rozpoczęcia', $html);
|
||||
assert_contains('Data zakończenia', $html);
|
||||
assert_contains('Godzina zakończenia', $html);
|
||||
});
|
||||
|
||||
test('skins define different schedule calendar layouts', function (): void {
|
||||
$enhanced = file_get_contents(PLUGIN_ROOT . '/user/enhanced.css') ?: '';
|
||||
$evolution = file_get_contents(PLUGIN_ROOT . '/user/evolution.css') ?: '';
|
||||
$appContext = file_get_contents(PLUGIN_ROOT . '/exec/lib/AppContext.php') ?: '';
|
||||
|
||||
assert_contains('.schedule-grid { grid-template-columns: 1fr;', $enhanced);
|
||||
assert_contains('.schedule-grid { grid-template-columns: repeat(2, minmax(460px, 1fr));', $evolution);
|
||||
assert_contains('.schedule-scroll { overflow-x: auto;', $evolution);
|
||||
assert_contains('width: 100% !important;', $evolution);
|
||||
assert_contains('margin-left: 0 !important;', $evolution);
|
||||
assert_contains('max-width: none !important;', $evolution);
|
||||
assert_false(str_contains($evolution, '#content'), 'Evolution CSS must not override DirectAdmin shell containers globally');
|
||||
assert_false((bool)preg_match('/^\\.container,$/m', $evolution), 'Evolution CSS must not override every DirectAdmin container globally');
|
||||
assert_false(str_contains($evolution, '.content-wrapper'), 'Evolution CSS must not override shell wrappers globally');
|
||||
assert_false(str_contains($evolution, '@import'));
|
||||
assert_contains("skin === 'evolution'", $appContext);
|
||||
assert_contains("enhanced.css", $appContext);
|
||||
assert_contains("evolution.css", $appContext);
|
||||
assert_contains('expandDirectAdminPluginContainers', $appContext);
|
||||
assert_contains("pluginSkin !== 'evolution'", $appContext);
|
||||
assert_contains("wrap.parentElement", $appContext);
|
||||
});
|
||||
|
||||
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 {
|
||||
test('mutating handlers synchronize directadmin vacations after storage changes', function (): void {
|
||||
foreach (['create.php', 'update.php', 'delete.php', 'toggle.php'] as $handler) {
|
||||
$source = file_get_contents(PLUGIN_ROOT . '/exec/handlers/' . $handler) ?: '';
|
||||
assert_contains('syncActiveBackend', $source, $handler . ' must synchronize backend after mutation');
|
||||
assert_contains('syncDirectAdminVacations', $source, $handler . ' must synchronize native vacations after mutation');
|
||||
}
|
||||
});
|
||||
|
||||
test('calendar picker is based on selected rule month and supports month navigation', function (): void {
|
||||
$settingsPath = TEST_TMP . '/form-calendar.conf';
|
||||
test_write($settingsPath, "DEFAULT_PLUGIN_LANGUAGE=pl\nGLOBAL_AUTORESPONDER_BACKEND=exim\n");
|
||||
test_write($settingsPath, "DEFAULT_PLUGIN_LANGUAGE=pl\n");
|
||||
$settings = Settings::load($settingsPath);
|
||||
$ctx = new AppContext(
|
||||
new DirectAdminUser('alice', 'enhanced', 'pl', TEST_TMP . '/config'),
|
||||
@@ -131,7 +387,6 @@ test('calendar picker is based on selected rule month and supports month navigat
|
||||
$html = render_rule_form($ctx, 'update', [
|
||||
'id' => 'abc',
|
||||
'subject_prefix' => 'Urlop',
|
||||
'reply_every_message' => false,
|
||||
'repeat_minutes' => 1440,
|
||||
'body' => 'Body',
|
||||
'enabled' => true,
|
||||
@@ -148,7 +403,7 @@ test('calendar picker is based on selected rule month and supports month navigat
|
||||
|
||||
test('calendar picker disables dates before today', function (): void {
|
||||
$settingsPath = TEST_TMP . '/form-calendar-min.conf';
|
||||
test_write($settingsPath, "DEFAULT_PLUGIN_LANGUAGE=pl\nGLOBAL_AUTORESPONDER_BACKEND=exim\n");
|
||||
test_write($settingsPath, "DEFAULT_PLUGIN_LANGUAGE=pl\n");
|
||||
$settings = Settings::load($settingsPath);
|
||||
$ctx = new AppContext(
|
||||
new DirectAdminUser('alice', 'enhanced', 'pl', TEST_TMP . '/config'),
|
||||
@@ -164,9 +419,39 @@ 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');
|
||||
});
|
||||
|
||||
test('update form calendar allows existing past schedule dates', function (): void {
|
||||
$settingsPath = TEST_TMP . '/form-calendar-update-past.conf';
|
||||
test_write($settingsPath, "DEFAULT_PLUGIN_LANGUAGE=pl\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')
|
||||
);
|
||||
|
||||
$html = render_rule_form($ctx, 'update', [
|
||||
'id' => 'abc',
|
||||
'name' => 'Historyczny urlop',
|
||||
'subject_prefix' => 'Urlop',
|
||||
'repeat_minutes' => 1440,
|
||||
'body' => 'Body',
|
||||
'enabled' => true,
|
||||
'start_value' => '2000-01-10T09:00',
|
||||
'end_value' => '2000-01-11T17:00',
|
||||
]);
|
||||
|
||||
assert_contains('data-min-date=""', $html);
|
||||
assert_contains('data-date-value="2000-01-10"', $html);
|
||||
assert_contains('data-date-value="2000-01-11"', $html);
|
||||
assert_false(str_contains($html, 'br-cal-day-disabled'), 'Update form must not disable past dates');
|
||||
});
|
||||
|
||||
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");
|
||||
test_write($settingsPath, "DEFAULT_PLUGIN_LANGUAGE=pl\nGLOBAL_AUTORESPONDER_TIMEZONE=Europe/Warsaw\n");
|
||||
$settings = Settings::load($settingsPath);
|
||||
$ctx = new AppContext(
|
||||
new DirectAdminUser('alice', 'enhanced', 'pl', TEST_TMP . '/config'),
|
||||
@@ -188,7 +473,7 @@ test('new rule form selects current date for start and end calendars by default'
|
||||
|
||||
test('rule form localizes calendar and preview labels without translating user content globally', function (): void {
|
||||
$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\n");
|
||||
$settings = Settings::load($settingsPath);
|
||||
$ctx = new AppContext(
|
||||
new DirectAdminUser('alice', 'enhanced', 'en', TEST_TMP . '/config'),
|
||||
@@ -210,14 +495,13 @@ test('rule form localizes calendar and preview labels without translating user c
|
||||
assert_contains('Cancel', $preview);
|
||||
});
|
||||
|
||||
test('directadmin backend allows only one enabled global rule per account', function (): void {
|
||||
test('plugin allows only one enabled global rule per account', function (): void {
|
||||
$settingsPath = TEST_TMP . '/form-da-single.conf';
|
||||
test_write($settingsPath, "DEFAULT_PLUGIN_LANGUAGE=pl\nGLOBAL_AUTORESPONDER_BACKEND=da\n");
|
||||
test_write($settingsPath, "DEFAULT_PLUGIN_LANGUAGE=pl\n");
|
||||
$settings = Settings::load($settingsPath);
|
||||
$repo = new RuleRepository(TEST_TMP . '/single-data');
|
||||
$repo->create('alice', [
|
||||
'subject_prefix' => 'Pierwsza',
|
||||
'reply_every_message' => false,
|
||||
'repeat_minutes' => 1440,
|
||||
'body' => 'Body',
|
||||
'enabled' => true,
|
||||
@@ -235,10 +519,10 @@ test('directadmin backend allows only one enabled global rule per account', func
|
||||
|
||||
$thrown = false;
|
||||
try {
|
||||
enforce_rule_backend_constraints($ctx, null, ['enabled' => true]);
|
||||
enforce_rule_directadmin_constraints($ctx, null, ['enabled' => true]);
|
||||
} catch (RuntimeException $e) {
|
||||
$thrown = true;
|
||||
assert_contains('Backend DirectAdmin obsługuje tylko jedną aktywną regułę globalną.', $e->getMessage());
|
||||
assert_contains('W ramach użytkownika może być aktywny tylko jeden globalny autoresponder.', $e->getMessage());
|
||||
}
|
||||
assert_true($thrown);
|
||||
});
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
require_once PLUGIN_ROOT . '/exec/lib/MailSender.php';
|
||||
|
||||
test('mail sender rejects subject header injection and builds utf8 message', function (): void {
|
||||
try {
|
||||
MailSender::buildMessage('from@example.com', 'to@example.com', "Bad\nSubject", 'Body');
|
||||
} catch (InvalidArgumentException $e) {
|
||||
assert_contains('subject', strtolower($e->getMessage()));
|
||||
}
|
||||
|
||||
$message = MailSender::buildMessage('from@example.com', 'to@example.com', 'Temat', "Treść\nDruga linia");
|
||||
assert_contains('Auto-Submitted: auto-replied', $message);
|
||||
assert_contains('Content-Type: text/plain; charset=UTF-8', $message);
|
||||
assert_contains("Subject: =?UTF-8?B?", $message);
|
||||
});
|
||||
@@ -1,13 +0,0 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
require_once PLUGIN_ROOT . '/exec/lib/MessageClassifier.php';
|
||||
|
||||
test('message classifier suppresses automated and list messages', function (): void {
|
||||
assert_true(MessageClassifier::shouldSuppress(['auto-submitted' => 'auto-replied'], 'sender@example.com'));
|
||||
assert_true(MessageClassifier::shouldSuppress(['precedence' => 'bulk'], 'sender@example.com'));
|
||||
assert_true(MessageClassifier::shouldSuppress(['list-id' => '<list.example.com>'], 'sender@example.com'));
|
||||
assert_true(MessageClassifier::shouldSuppress([], ''));
|
||||
assert_true(MessageClassifier::shouldSuppress([], 'MAILER-DAEMON@example.com'));
|
||||
assert_false(MessageClassifier::shouldSuppress(['auto-submitted' => 'no'], 'person@example.com'));
|
||||
});
|
||||
@@ -29,24 +29,30 @@ test('shipped plugin files do not contain placeholders', function (): void {
|
||||
continue;
|
||||
}
|
||||
$content = file_get_contents($path) ?: '';
|
||||
if (preg_match('/placeholder|TODO|FIXME|not implemented|pending_exim_validation|stub/i', $content)) {
|
||||
if (preg_match('/placeholder|TODO|FIXME|not implemented|stub/i', $content)) {
|
||||
$bad[] = $relative;
|
||||
}
|
||||
}
|
||||
assert_same([], $bad);
|
||||
});
|
||||
|
||||
test('backend script protects custom exim config with rollback and exact section insertion checks', function (): void {
|
||||
$script = file_get_contents(PLUGIN_ROOT . '/scripts/backend.sh') ?: '';
|
||||
assert_contains('backup_custom_conf()', $script);
|
||||
assert_contains('restore_custom_conf()', $script);
|
||||
assert_contains("trap 'restore_custom_conf' EXIT", $script);
|
||||
assert_contains('ROLLBACK_REBUILD=1', $script);
|
||||
assert_contains('if ! awk -v section="$section" -v snippet="$snippet"', $script);
|
||||
assert_contains('if (inserted != 1)', $script);
|
||||
test('package source does not ship removed custom mail integration files', function (): void {
|
||||
$removedPaths = [
|
||||
'scripts/' . 'back' . 'end.sh',
|
||||
'scripts/' . 'ex' . 'im',
|
||||
'scripts/global_auto' . 'responder_worker.php',
|
||||
'exec/lib/Back' . 'endRuntimeConfig.php',
|
||||
'exec/lib/Message' . 'Classifier.php',
|
||||
'exec/lib/Mail' . 'Sender.php',
|
||||
'exec/lib/Repeat' . 'State.php',
|
||||
];
|
||||
foreach ($removedPaths as $relative) {
|
||||
$path = PLUGIN_ROOT . '/' . $relative;
|
||||
assert_false(is_file($path) || is_dir($path), $relative . ' must not exist');
|
||||
}
|
||||
});
|
||||
|
||||
test('lifecycle scripts install cron sync and remove exim integration on uninstall', function (): void {
|
||||
test('lifecycle scripts install directadmin sync cron only', function (): void {
|
||||
$install = file_get_contents(PLUGIN_ROOT . '/scripts/install.sh') ?: '';
|
||||
$update = file_get_contents(PLUGIN_ROOT . '/scripts/update.sh') ?: '';
|
||||
$uninstall = file_get_contents(PLUGIN_ROOT . '/scripts/uninstall.sh') ?: '';
|
||||
@@ -55,5 +61,7 @@ test('lifecycle scripts install cron sync and remove exim integration on uninsta
|
||||
assert_contains('sync_directadmin_vacations.php', $install);
|
||||
assert_contains('/etc/cron.d/global-autoresponder', $update);
|
||||
assert_contains('sync_directadmin_vacations.php', $update);
|
||||
assert_contains('backend.sh" da', $uninstall);
|
||||
assert_false(str_contains($install, 'back' . 'end-state.json'));
|
||||
assert_false(str_contains($install, 'state/' . 'replies'));
|
||||
assert_false(str_contains($uninstall, 'back' . 'end.sh'));
|
||||
});
|
||||
|
||||
@@ -7,6 +7,9 @@ test('plugin logger writes exceptions to plugin log file', function (): void {
|
||||
$path = TEST_TMP . '/plugin.log';
|
||||
|
||||
PluginLogger::init($path);
|
||||
assert_true(is_file($path), 'Logger should create plugin.log during init');
|
||||
assert_same('0600', substr(sprintf('%o', fileperms($path)), -4));
|
||||
|
||||
PluginLogger::exception(new RuntimeException('DirectAdmin API command failed'), 'CREATE');
|
||||
|
||||
$log = file_get_contents($path) ?: '';
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
require_once PLUGIN_ROOT . '/exec/lib/RepeatState.php';
|
||||
|
||||
test('repeat state allows first reply and blocks repeated reply until ttl', function (): void {
|
||||
$state = new RepeatState(TEST_TMP . '/state', 1000);
|
||||
assert_true($state->shouldSend('alice', 'rule', 'info@example.com', 'sender@example.com', 60));
|
||||
$state->record('alice', 'rule', 'info@example.com', 'sender@example.com');
|
||||
assert_false($state->shouldSend('alice', 'rule', 'info@example.com', 'sender@example.com', 60));
|
||||
|
||||
$later = new RepeatState(TEST_TMP . '/state', 5000);
|
||||
assert_true($later->shouldSend('alice', 'rule', 'info@example.com', 'sender@example.com', 60));
|
||||
});
|
||||
@@ -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']);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user