t('Scope')") !== false); assert_false(strpos($source, "ctx->t(\$rule['dynamic_scope']") !== false); }); test('mutating handlers synchronize active backend 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'); } }); 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"); $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', 'reply_every_message' => false, '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\nGLOBAL_AUTORESPONDER_BACKEND=exim\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('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"); $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\nGLOBAL_AUTORESPONDER_BACKEND=exim\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('directadmin backend 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"); $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, '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_backend_constraints($ctx, null, ['enabled' => true]); } catch (RuntimeException $e) { $thrown = true; assert_contains('Backend DirectAdmin obsługuje tylko jedną aktywną regułę globalną.', $e->getMessage()); } assert_true($thrown); });