fix: harden backend synchronization

This commit is contained in:
Marek Miklewicz
2026-06-02 21:06:25 +02:00
parent 4b531a4c24
commit 64b62a5793
20 changed files with 254 additions and 16 deletions
+55
View File
@@ -112,3 +112,58 @@ test('calendar picker is based on selected rule month and supports month navigat
assert_contains('Luty 2027', $html);
assert_false(strpos($html, 'Czerwiec 2026') !== false);
});
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('<th>Mon</th>', $html);
assert_contains('Selected:', $html);
assert_false(strpos($html, 'Wybrano') !== false);
assert_false(strpos($html, '<th>Pn</th>') !== false);
$preview = render_preview_box($ctx, ['subject' => 'Delete', 'body' => 'Cancel']);
assert_contains('<strong>Subject:</strong> 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' => 'Pierwsza',
'body' => 'Body',
'enabled' => true,
'start_value' => '2026-06-10|morning',
'end_value' => '2026-06-24|evening',
]);
$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);
});