feat: implement global autoresponder plugin
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
<?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_SCHEDULE_MODE=exact_hour',
|
||||
'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(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_SCHEDULE_MODE=bad\n");
|
||||
try {
|
||||
Settings::load($path);
|
||||
} catch (InvalidArgumentException $e) {
|
||||
assert_contains('timezone', $e->getMessage());
|
||||
return;
|
||||
}
|
||||
throw new RuntimeException('Expected invalid settings to fail');
|
||||
});
|
||||
|
||||
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));
|
||||
});
|
||||
Reference in New Issue
Block a user