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>
113 lines
5.0 KiB
PHP
113 lines
5.0 KiB
PHP
<?php
|
|
|
|
namespace MintyPHP\Tests\Service\User;
|
|
|
|
use MintyPHP\Service\Settings\SettingsAppGateway;
|
|
use MintyPHP\Service\Settings\SettingsDefaultsGateway;
|
|
use MintyPHP\Service\Settings\SettingsUserLifecycleGateway;
|
|
use MintyPHP\Service\User\UserSettingsGateway;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class UserSettingsGatewayTest extends TestCase
|
|
{
|
|
public function testGetDefaultTenantIdDelegates(): void
|
|
{
|
|
$defaults = $this->createMock(SettingsDefaultsGateway::class);
|
|
$defaults->method('getDefaultTenantId')->willReturn(5);
|
|
|
|
$gateway = new UserSettingsGateway($defaults, $this->createMock(SettingsAppGateway::class), $this->createMock(SettingsUserLifecycleGateway::class));
|
|
$this->assertSame(5, $gateway->getDefaultTenantId());
|
|
}
|
|
|
|
public function testGetDefaultTenantIdReturnsNullWhenUnset(): void
|
|
{
|
|
$defaults = $this->createMock(SettingsDefaultsGateway::class);
|
|
$defaults->method('getDefaultTenantId')->willReturn(null);
|
|
|
|
$gateway = new UserSettingsGateway($defaults, $this->createMock(SettingsAppGateway::class), $this->createMock(SettingsUserLifecycleGateway::class));
|
|
$this->assertNull($gateway->getDefaultTenantId());
|
|
}
|
|
|
|
public function testGetDefaultRoleIdDelegates(): void
|
|
{
|
|
$defaults = $this->createMock(SettingsDefaultsGateway::class);
|
|
$defaults->method('getDefaultRoleId')->willReturn(12);
|
|
|
|
$gateway = new UserSettingsGateway($defaults, $this->createMock(SettingsAppGateway::class), $this->createMock(SettingsUserLifecycleGateway::class));
|
|
$this->assertSame(12, $gateway->getDefaultRoleId());
|
|
}
|
|
|
|
public function testGetDefaultRoleIdReturnsNullWhenUnset(): void
|
|
{
|
|
$defaults = $this->createMock(SettingsDefaultsGateway::class);
|
|
$defaults->method('getDefaultRoleId')->willReturn(null);
|
|
|
|
$gateway = new UserSettingsGateway($defaults, $this->createMock(SettingsAppGateway::class), $this->createMock(SettingsUserLifecycleGateway::class));
|
|
$this->assertNull($gateway->getDefaultRoleId());
|
|
}
|
|
|
|
public function testGetDefaultDepartmentIdDelegates(): void
|
|
{
|
|
$defaults = $this->createMock(SettingsDefaultsGateway::class);
|
|
$defaults->method('getDefaultDepartmentId')->willReturn(8);
|
|
|
|
$gateway = new UserSettingsGateway($defaults, $this->createMock(SettingsAppGateway::class), $this->createMock(SettingsUserLifecycleGateway::class));
|
|
$this->assertSame(8, $gateway->getDefaultDepartmentId());
|
|
}
|
|
|
|
public function testAppThemesDelegatesToListThemes(): void
|
|
{
|
|
$themes = ['light' => 'Light', 'dark' => 'Dark'];
|
|
$app = $this->createMock(SettingsAppGateway::class);
|
|
$app->method('listThemes')->willReturn($themes);
|
|
|
|
$gateway = new UserSettingsGateway($this->createMock(SettingsDefaultsGateway::class), $app, $this->createMock(SettingsUserLifecycleGateway::class));
|
|
$this->assertSame($themes, $gateway->appThemes());
|
|
}
|
|
|
|
public function testDefaultThemeDelegates(): void
|
|
{
|
|
$app = $this->createMock(SettingsAppGateway::class);
|
|
$app->method('resolveDefaultTheme')->willReturn('light');
|
|
|
|
$gateway = new UserSettingsGateway($this->createMock(SettingsDefaultsGateway::class), $app, $this->createMock(SettingsUserLifecycleGateway::class));
|
|
$this->assertSame('light', $gateway->defaultTheme());
|
|
}
|
|
|
|
public function testNormalizeThemeDelegates(): void
|
|
{
|
|
$app = $this->createMock(SettingsAppGateway::class);
|
|
$app->method('normalizeTheme')->willReturn('dark');
|
|
|
|
$gateway = new UserSettingsGateway($this->createMock(SettingsDefaultsGateway::class), $app, $this->createMock(SettingsUserLifecycleGateway::class));
|
|
$this->assertSame('dark', $gateway->normalizeTheme('DARK'));
|
|
}
|
|
|
|
public function testNormalizeThemeWithNullDelegates(): void
|
|
{
|
|
$app = $this->createMock(SettingsAppGateway::class);
|
|
$app->method('normalizeTheme')->willReturn('light');
|
|
|
|
$gateway = new UserSettingsGateway($this->createMock(SettingsDefaultsGateway::class), $app, $this->createMock(SettingsUserLifecycleGateway::class));
|
|
$this->assertSame('light', $gateway->normalizeTheme(null));
|
|
}
|
|
|
|
public function testGetUserInactivityDeactivateDaysDelegates(): void
|
|
{
|
|
$lifecycle = $this->createMock(SettingsUserLifecycleGateway::class);
|
|
$lifecycle->method('getUserInactivityDeactivateDays')->willReturn(180);
|
|
|
|
$gateway = new UserSettingsGateway($this->createMock(SettingsDefaultsGateway::class), $this->createMock(SettingsAppGateway::class), $lifecycle);
|
|
$this->assertSame(180, $gateway->getUserInactivityDeactivateDays());
|
|
}
|
|
|
|
public function testGetUserInactivityDeleteDaysDelegates(): void
|
|
{
|
|
$lifecycle = $this->createMock(SettingsUserLifecycleGateway::class);
|
|
$lifecycle->method('getUserInactivityDeleteDays')->willReturn(365);
|
|
|
|
$gateway = new UserSettingsGateway($this->createMock(SettingsDefaultsGateway::class), $this->createMock(SettingsAppGateway::class), $lifecycle);
|
|
$this->assertSame(365, $gateway->getUserInactivityDeleteDays());
|
|
}
|
|
}
|