Cover Settings gateways (Session, LoginPersistence, SystemAudit, Smtp, FrontendTelemetry, Metadata, App), Auth gateways (ExternalIdentity, Tenant), DirectorySettings, UserSettings, and HotkeyService. Gateway test coverage rises from 25% to 52%, overall service/gateway coverage from 58.6% to 70.7%. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
107 lines
4.0 KiB
PHP
107 lines
4.0 KiB
PHP
<?php
|
|
|
|
namespace MintyPHP\Tests\Service\Settings;
|
|
|
|
use MintyPHP\Repository\Settings\SettingRepositoryInterface;
|
|
use MintyPHP\Service\Settings\SettingsAppGateway;
|
|
use MintyPHP\Service\Settings\SettingsMetadataGateway;
|
|
use MintyPHP\Service\Settings\ThemeConfigGateway;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class SettingsAppGatewayTest extends TestCase
|
|
{
|
|
private function createGateway(SettingRepositoryInterface $settings, ?ThemeConfigGateway $themeConfig = null): SettingsAppGateway
|
|
{
|
|
$themeConfig ??= $this->createDefaultThemeConfig();
|
|
|
|
return new SettingsAppGateway(new SettingsMetadataGateway($settings), $themeConfig);
|
|
}
|
|
|
|
private function createDefaultThemeConfig(): ThemeConfigGateway
|
|
{
|
|
$themeConfig = $this->createMock(ThemeConfigGateway::class);
|
|
$themeConfig->method('all')->willReturn(['light' => 'Light', 'dark' => 'Dark']);
|
|
|
|
return $themeConfig;
|
|
}
|
|
|
|
public function testGetAppTitleReturnsNullWhenEmpty(): void
|
|
{
|
|
$settings = $this->createMock(SettingRepositoryInterface::class);
|
|
$settings->expects($this->any())->method('getValue')->with('app_title')->willReturn(null);
|
|
|
|
$gateway = $this->createGateway($settings);
|
|
$this->assertNull($gateway->getAppTitle());
|
|
}
|
|
|
|
public function testGetAppTitleReturnsTrimmedValue(): void
|
|
{
|
|
$settings = $this->createMock(SettingRepositoryInterface::class);
|
|
$settings->expects($this->any())->method('getValue')->with('app_title')->willReturn(' My App ');
|
|
|
|
$gateway = $this->createGateway($settings);
|
|
$this->assertSame('My App', $gateway->getAppTitle());
|
|
}
|
|
|
|
public function testGetAppLocaleReturnsNullWhenNotSet(): void
|
|
{
|
|
$settings = $this->createMock(SettingRepositoryInterface::class);
|
|
$settings->expects($this->any())->method('getValue')->with('app_locale')->willReturn(null);
|
|
|
|
$gateway = $this->createGateway($settings);
|
|
$this->assertNull($gateway->getAppLocale());
|
|
}
|
|
|
|
public function testIsRegistrationEnabledDefaultsToTrue(): void
|
|
{
|
|
$settings = $this->createMock(SettingRepositoryInterface::class);
|
|
$settings->expects($this->any())->method('getValue')->with('app_registration')->willReturn(null);
|
|
|
|
$gateway = $this->createGateway($settings);
|
|
$this->assertTrue($gateway->isRegistrationEnabled());
|
|
}
|
|
|
|
public function testIsRegistrationEnabledReturnsFalseWhenDisabled(): void
|
|
{
|
|
$settings = $this->createMock(SettingRepositoryInterface::class);
|
|
$settings->expects($this->any())->method('getValue')->with('app_registration')->willReturn('0');
|
|
|
|
$gateway = $this->createGateway($settings);
|
|
$this->assertFalse($gateway->isRegistrationEnabled());
|
|
}
|
|
|
|
public function testGetAppPrimaryColorRejectsInvalidFormat(): void
|
|
{
|
|
$settings = $this->createMock(SettingRepositoryInterface::class);
|
|
$settings->expects($this->any())->method('getValue')->with('app_primary_color')->willReturn('not-a-color');
|
|
|
|
$gateway = $this->createGateway($settings);
|
|
$this->assertNull($gateway->getAppPrimaryColor());
|
|
}
|
|
|
|
public function testGetAppPrimaryColorReturnsValidHex(): void
|
|
{
|
|
$settings = $this->createMock(SettingRepositoryInterface::class);
|
|
$settings->expects($this->any())->method('getValue')->with('app_primary_color')->willReturn('#ff5500');
|
|
|
|
$gateway = $this->createGateway($settings);
|
|
$this->assertSame('#ff5500', $gateway->getAppPrimaryColor());
|
|
}
|
|
|
|
public function testIsAllowedThemeReturnsTrueForKnownTheme(): void
|
|
{
|
|
$settings = $this->createMock(SettingRepositoryInterface::class);
|
|
|
|
$gateway = $this->createGateway($settings);
|
|
$this->assertTrue($gateway->isAllowedTheme('dark'));
|
|
}
|
|
|
|
public function testIsAllowedThemeReturnsFalseForUnknownTheme(): void
|
|
{
|
|
$settings = $this->createMock(SettingRepositoryInterface::class);
|
|
|
|
$gateway = $this->createGateway($settings);
|
|
$this->assertFalse($gateway->isAllowedTheme('neon'));
|
|
}
|
|
}
|