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());
|
||
|
|
}
|
||
|
|
}
|