url('create.html')") !== false); assert_false(strpos($source, "ctx->t('Add autoresponder')") !== false); }); 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'; require_once PLUGIN_ROOT . '/exec/lib/CsrfGuard.php'; require_once PLUGIN_ROOT . '/exec/lib/RuleRepository.php'; require_once PLUGIN_ROOT . '/exec/lib/AuditLog.php'; require_once PLUGIN_ROOT . '/exec/lib/AppContext.php'; require_once PLUGIN_ROOT . '/exec/handlers/_form_helpers.php'; $settingsPath = TEST_TMP . '/form.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_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_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('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('Istniejące autorespondery / wiadomości urlopowe zostaną usunięte w przypadku kontynuacji.', $modal); assert_contains('class="danger-fill" type="submit">USUŃ ISTNIEJĄCE AUTORESPONDERY', $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', $html); assert_contains('>Nie', $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\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_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('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 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('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\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', 'subject_prefix' => 'Urlop', 'repeat_minutes' => 1440, 'body' => 'Body', 'enabled' => true, 'start_value' => '2027-02-14T20:00', 'end_value' => '2027-03-01T09:30', ]); assert_contains('data-calendar-picker', $html); assert_contains('data-calendar-prev', $html); assert_contains('data-calendar-next', $html); assert_contains('Luty 2027', $html); assert_false(strpos($html, 'Czerwiec 2026') !== false); }); test('calendar picker disables dates before today', function (): void { $settingsPath = TEST_TMP . '/form-calendar-min.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_calendar_picker($ctx, 'start_value', $ctx->t('Start date'), '2000-01-15T09:00'); assert_contains('br-cal-day-disabled', $html); 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_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') ); $today = (new DateTimeImmutable('today', new DateTimeZone($settings->timezone())))->format('Y-m-d'); $html = render_rule_form($ctx, 'create', null); 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 . '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 { $settingsPath = TEST_TMP . '/form-i18n.conf'; test_write($settingsPath, "DEFAULT_PLUGIN_LANGUAGE=en\n"); $settings = Settings::load($settingsPath); $ctx = new AppContext( new DirectAdminUser('alice', 'enhanced', 'en', TEST_TMP . '/config'), $settings, new RuleRepository(TEST_TMP . '/data'), new CsrfGuard('secret', 'alice', 'sid'), Lang::load('en', $settings), new AuditLog(TEST_TMP . '/audit.log') ); $html = render_rule_form($ctx, 'create', null); assert_contains('Mon', $html); assert_contains('Selected:', $html); assert_false(strpos($html, 'Wybrano') !== false); assert_false(strpos($html, 'Pn') !== false); $preview = render_preview_box($ctx, ['subject_prefix' => 'Delete', 'body' => 'Cancel']); assert_contains('Subject prefix: Delete', $preview); assert_contains('Cancel', $preview); }); 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\n"); $settings = Settings::load($settingsPath); $repo = new RuleRepository(TEST_TMP . '/single-data'); $repo->create('alice', [ 'subject_prefix' => 'Pierwsza', 'repeat_minutes' => 1440, 'body' => 'Body', 'enabled' => true, 'start_value' => '2026-06-10T00:00', 'end_value' => '2026-06-24T23:59', ]); $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') ); $thrown = false; try { enforce_rule_directadmin_constraints($ctx, null, ['enabled' => true]); } catch (RuntimeException $e) { $thrown = true; assert_contains('W ramach użytkownika może być aktywny tylko jeden globalny autoresponder.', $e->getMessage()); } assert_true($thrown); });