Files
global-autoresponder/tests/bootstrap_test.php
T
2026-06-02 19:55:07 +02:00

67 lines
2.7 KiB
PHP

<?php
declare(strict_types=1);
require_once PLUGIN_ROOT . '/exec/lib/Settings.php';
require_once PLUGIN_ROOT . '/exec/lib/DirectAdminUser.php';
test('settings validate defaults and external paths', function (): void {
$path = TEST_TMP . '/settings.conf';
test_write($path, implode("\n", [
'DEFAULT_PLUGIN_LANGUAGE=pl',
'DEFAULT_ENABLE=false',
'GLOBAL_AUTORESPONDER_TIMEZONE=Europe/Warsaw',
'GLOBAL_AUTORESPONDER_BACKEND=exim',
'GLOBAL_AUTORESPONDER_REPLY_EVERY_MESSAGE=false',
'GLOBAL_AUTORESPONDER_REPEAT_MINUTES=60',
'GLOBAL_AUTORESPONDER_DYNAMIC_MAILBOX_SCOPE=true',
'GLOBAL_AUTORESPONDER_MAX_SUBJECT_BYTES=255',
'GLOBAL_AUTORESPONDER_MAX_BODY_BYTES=20000',
]) . "\n");
$settings = Settings::load($path);
assert_same('pl', $settings->defaultLanguage());
assert_false($settings->defaultEnable());
assert_same('Europe/Warsaw', $settings->timezone());
assert_same('exact_hour', $settings->scheduleMode());
assert_same('exim', $settings->backendMode());
assert_same(60, $settings->repeatMinutes());
assert_same('/usr/local/hitme_plugins/global-autoresponders/config', Settings::CONFIG_DIR);
assert_same('/usr/local/hitme_plugins/global-autoresponders/data', Settings::DATA_DIR);
});
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");
try {
Settings::load($path);
} catch (InvalidArgumentException $e) {
assert_contains('timezone', $e->getMessage());
return;
}
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('directadmin_period', $settings->scheduleMode());
test_write($path, "GLOBAL_AUTORESPONDER_BACKEND=exim\n");
$settings = Settings::load($path);
assert_same('exim', $settings->backendMode());
assert_same('exact_hour', $settings->scheduleMode());
});
test('directadmin user access follows DEFAULT_ENABLE and per-user overrides', function (): void {
$settingsPath = TEST_TMP . '/access.conf';
test_write($settingsPath, "DEFAULT_ENABLE=false\n");
$settings = Settings::load($settingsPath);
$user = new DirectAdminUser('marek', 'enhanced', 'en', TEST_TMP . '/config');
assert_false($user->hasPluginAccess($settings));
test_write(TEST_TMP . '/config/users/marek.conf', "enabled=true\n");
assert_true($user->hasPluginAccess($settings));
});