2026-03-19 19:43:55 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace MintyPHP\Tests\Service\Settings;
|
|
|
|
|
|
|
|
|
|
use MintyPHP\Repository\Settings\SettingRepositoryInterface;
|
|
|
|
|
use MintyPHP\Service\Settings\SettingsAppGateway;
|
|
|
|
|
use MintyPHP\Service\Settings\SettingsFrontendTelemetryGateway;
|
|
|
|
|
use MintyPHP\Service\Settings\SettingsMetadataGateway;
|
|
|
|
|
use MintyPHP\Service\Settings\SettingsSmtpGateway;
|
|
|
|
|
use MintyPHP\Service\Settings\SettingsSystemAuditGateway;
|
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
|
|
|
|
|
|
final class SettingsGatewayNormalizationTest extends TestCase
|
|
|
|
|
{
|
|
|
|
|
public function testAppLocaleStoresNullForEmptyValue(): void
|
|
|
|
|
{
|
|
|
|
|
$settings = $this->createMock(SettingRepositoryInterface::class);
|
|
|
|
|
$settings->expects($this->once())
|
|
|
|
|
->method('set')
|
|
|
|
|
->with('app_locale', null, 'setting.app_locale')
|
|
|
|
|
->willReturn(true);
|
|
|
|
|
|
|
|
|
|
$gateway = $this->newAppGateway($settings);
|
|
|
|
|
self::assertTrue($gateway->setAppLocale(' '));
|
|
|
|
|
}
|
|
|
|
|
|
refactor(settings): remove global appearance settings — tenant is sole source
Removes the global app_theme, app_theme_user and app_primary_color settings
from the admin/settings area and the underlying service/cache/API/i18n/docs
layers. The tenant columns (tenants.primary_color, default_theme,
allow_user_theme) become the single source of truth for appearance.
Branding helpers are tenant-only and fall back to a hardcoded 'light' theme
with no brand color when no tenant context is available (login, error,
pre-session pages). The APP_THEME env var is removed.
Scope:
- UI: Appearance tab gone from /admin/settings; tenant edit form drops the
global-fallback color preview.
- Service: SettingsAppGateway no longer exposes setting-backed accessors
for theme/user-theme/primary-color. Theme catalog utilities (listThemes,
isAllowedTheme, normalizeTheme, resolveDefaultTheme) stay and are used
across Tenant / Auth / User flows; resolveDefaultTheme now hardcodes
'light' with a catalog fallback (no global/env lookup).
- AdminSettingsService: buildPageData, sanitization, audit snapshot, apply
step and cache payload are all stripped of the three keys. Dead helper
applyAppPrimaryColor + normalizePrimaryColor removed.
- Cache: SettingCacheService HOT_PATH_KEYS drops the three keys.
- API: /settings (GET/PUT) and /settings/public (GET) no longer expose
appearance fields; OpenAPI schemas pruned accordingly.
- Audit redaction list shortened.
- DB: db/init/init.sql seed rows removed. No migration for existing
installs — legacy rows stay inert.
- i18n + docs: setting.app_theme, setting.app_theme_user,
setting.app_primary_color removed from de+en locales; reference and
explanation docs updated.
- Tests: covering tests for the removed methods pruned; ThemeResolutionTest
rewritten for tenant-only semantics. One unrelated PHP-CS-Fixer issue in
UserRegistrar.php cleaned up to keep QG-006 green.
Workflow: .agents/runs/SETTINGS-APPEARANCE-TENANT-ONLY/ (gitignored).
Gates: QG-001..003, QG-006, QG-008 all pass (1985 tests, 28764 assertions).
Reviews: code, security, acceptance all pass.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-22 22:40:15 +02:00
|
|
|
public function testAppRegistrationDefaultIsTrueWhenUnset(): void
|
2026-03-19 19:43:55 +01:00
|
|
|
{
|
|
|
|
|
$settings = $this->createMock(SettingRepositoryInterface::class);
|
|
|
|
|
$settings->method('getValue')->willReturnMap([
|
|
|
|
|
['app_registration', null],
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$gateway = $this->newAppGateway($settings);
|
|
|
|
|
self::assertTrue($gateway->isRegistrationEnabled());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testSystemAuditUsesFallbacksAndRejectsOutOfRangeRetention(): void
|
|
|
|
|
{
|
|
|
|
|
$settings = $this->createMock(SettingRepositoryInterface::class);
|
|
|
|
|
$settings->method('getValue')->willReturnCallback(static function (string $key): ?string {
|
|
|
|
|
return $key === 'system_audit_retention_days' ? '5' : null;
|
|
|
|
|
});
|
|
|
|
|
$settings->expects($this->never())->method('set');
|
|
|
|
|
|
|
|
|
|
$gateway = new SettingsSystemAuditGateway(new SettingsMetadataGateway($settings));
|
|
|
|
|
self::assertTrue($gateway->isSystemAuditEnabled());
|
|
|
|
|
self::assertSame(365, $gateway->getSystemAuditRetentionDays());
|
|
|
|
|
self::assertFalse($gateway->setSystemAuditRetentionDays(10));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testFrontendTelemetryUsesDefaultsWhenSettingsMissing(): void
|
|
|
|
|
{
|
|
|
|
|
$settings = $this->createMock(SettingRepositoryInterface::class);
|
|
|
|
|
$settings->method('getValue')->willReturn(null);
|
|
|
|
|
|
|
|
|
|
$gateway = new SettingsFrontendTelemetryGateway(new SettingsMetadataGateway($settings));
|
|
|
|
|
self::assertFalse($gateway->isFrontendTelemetryEnabled());
|
|
|
|
|
self::assertSame(0.2, $gateway->getFrontendTelemetrySampleRate());
|
|
|
|
|
self::assertSame(['warn_once', 'ajax_error'], $gateway->getFrontendTelemetryAllowedEvents());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testFrontendTelemetryRejectsOutOfRangeSampleRate(): void
|
|
|
|
|
{
|
|
|
|
|
$settings = $this->createMock(SettingRepositoryInterface::class);
|
|
|
|
|
$settings->expects($this->never())->method('set');
|
|
|
|
|
|
|
|
|
|
$gateway = new SettingsFrontendTelemetryGateway(new SettingsMetadataGateway($settings));
|
|
|
|
|
self::assertFalse($gateway->setFrontendTelemetrySampleRate(1.5));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testFrontendTelemetryNormalizesAllowedEvents(): void
|
|
|
|
|
{
|
|
|
|
|
$settings = $this->createMock(SettingRepositoryInterface::class);
|
|
|
|
|
$settings->expects($this->once())
|
|
|
|
|
->method('set')
|
|
|
|
|
->with(
|
|
|
|
|
'frontend_telemetry_allowed_events',
|
|
|
|
|
'ajax_error,warn_once',
|
|
|
|
|
'setting.frontend_telemetry_allowed_events'
|
|
|
|
|
)
|
|
|
|
|
->willReturn(true);
|
|
|
|
|
|
|
|
|
|
$gateway = new SettingsFrontendTelemetryGateway(new SettingsMetadataGateway($settings));
|
|
|
|
|
self::assertTrue($gateway->setFrontendTelemetryAllowedEvents(['frontend.warn_once', 'ajax_error', 'invalid']));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testSmtpSecureReturnsNullForNone(): void
|
|
|
|
|
{
|
|
|
|
|
$settings = $this->createMock(SettingRepositoryInterface::class);
|
|
|
|
|
$settings->method('getValue')->willReturnCallback(static function (string $key): ?string {
|
|
|
|
|
if ($key === 'smtp_secure') {
|
|
|
|
|
return 'none';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$gateway = new SettingsSmtpGateway(new SettingsMetadataGateway($settings));
|
|
|
|
|
self::assertNull($gateway->getSmtpSecure());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testSmtpSecureRejectsInvalidValue(): void
|
|
|
|
|
{
|
|
|
|
|
$settings = $this->createMock(SettingRepositoryInterface::class);
|
|
|
|
|
$settings->expects($this->never())->method('set');
|
|
|
|
|
|
|
|
|
|
$gateway = new SettingsSmtpGateway(new SettingsMetadataGateway($settings));
|
|
|
|
|
self::assertFalse($gateway->setSmtpSecure('starttls'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testSmtpHostPersistsNullForEmptyString(): void
|
|
|
|
|
{
|
|
|
|
|
$settings = $this->createMock(SettingRepositoryInterface::class);
|
|
|
|
|
$settings->expects($this->once())
|
|
|
|
|
->method('set')
|
|
|
|
|
->with('smtp_host', null, 'setting.smtp_host')
|
|
|
|
|
->willReturn(true);
|
|
|
|
|
|
|
|
|
|
$gateway = new SettingsSmtpGateway(new SettingsMetadataGateway($settings));
|
|
|
|
|
self::assertTrue($gateway->setSmtpHost(' '));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function newAppGateway(SettingRepositoryInterface $settingRepository): SettingsAppGateway
|
|
|
|
|
{
|
2026-04-24 16:15:10 +02:00
|
|
|
return new SettingsAppGateway(new SettingsMetadataGateway($settingRepository));
|
2026-03-19 19:43:55 +01:00
|
|
|
}
|
|
|
|
|
}
|