2026-03-07 20:14:29 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace MintyPHP\Tests\Support;
|
|
|
|
|
|
|
|
|
|
use MintyPHP\App\AppContainer;
|
|
|
|
|
use MintyPHP\Service\Settings\SettingCacheService;
|
2026-03-13 11:31:33 +01:00
|
|
|
use MintyPHP\Service\Settings\ThemeConfigGateway;
|
2026-03-07 20:14:29 +01:00
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
|
|
|
|
|
|
class ThemeResolutionTest extends TestCase
|
|
|
|
|
{
|
feat: extend module platform with UI slots, runtime components, CLI tooling and {{userId}} search support
Completes the generic module platform that enables modules to contribute
UI elements, runtime JS components, and search resources without any
core hardcoding.
New generic UI slot types:
- topbar.right_item: module-contributed topbar buttons
- layout.body_end_template: module-contributed dialog/overlay templates
- layout.head_style: module-contributed global CSS
- runtime.component: declarative JS component registration with phase ordering
New infrastructure:
- ModuleAutoloader: PSR-4 autoloading for module-local PHP classes
- ModuleRuntimePageBuilder: symlinks module pages into runtime directory
- ModuleRuntimeAssetPublisher: publishes module CSS/JS to web/modules/
- ModulePermissionSynchronizer: syncs module permissions to DB
- CLI scripts: module-runtime-sync, module-build, module-migrate,
module-permissions-sync, module-assets-sync
- {{userId}} placeholder in SearchDataService for user-scoped search queries
- Component runtime with phased initialization (early/default/late)
- AppContainer.protectExistingBindings() to prevent module→core overwrites
- Architecture tests: ModuleStructureContractTest, CoreTemplateIsolationTest,
FrontendComponentRuntimeContractTest, AppContainerIsolationContractTest
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-18 22:19:56 +01:00
|
|
|
use AppContainerIsolationTrait;
|
|
|
|
|
|
2026-03-07 20:14:29 +01:00
|
|
|
private AppContainer $container;
|
|
|
|
|
|
|
|
|
|
protected function setUp(): void
|
|
|
|
|
{
|
|
|
|
|
$_SESSION = [];
|
|
|
|
|
|
|
|
|
|
$this->container = new AppContainer();
|
|
|
|
|
|
2026-03-13 11:31:33 +01:00
|
|
|
$themeConfig = $this->createMock(ThemeConfigGateway::class);
|
2026-03-07 20:14:29 +01:00
|
|
|
$themeConfig->method('all')->willReturn(['light' => 'Light', 'dark' => 'Dark']);
|
2026-03-13 11:31:33 +01:00
|
|
|
$this->container->set(ThemeConfigGateway::class, fn () => $themeConfig);
|
2026-03-07 20:14:29 +01:00
|
|
|
|
|
|
|
|
$this->setAppSettings([]);
|
|
|
|
|
|
feat: extend module platform with UI slots, runtime components, CLI tooling and {{userId}} search support
Completes the generic module platform that enables modules to contribute
UI elements, runtime JS components, and search resources without any
core hardcoding.
New generic UI slot types:
- topbar.right_item: module-contributed topbar buttons
- layout.body_end_template: module-contributed dialog/overlay templates
- layout.head_style: module-contributed global CSS
- runtime.component: declarative JS component registration with phase ordering
New infrastructure:
- ModuleAutoloader: PSR-4 autoloading for module-local PHP classes
- ModuleRuntimePageBuilder: symlinks module pages into runtime directory
- ModuleRuntimeAssetPublisher: publishes module CSS/JS to web/modules/
- ModulePermissionSynchronizer: syncs module permissions to DB
- CLI scripts: module-runtime-sync, module-build, module-migrate,
module-permissions-sync, module-assets-sync
- {{userId}} placeholder in SearchDataService for user-scoped search queries
- Component runtime with phased initialization (early/default/late)
- AppContainer.protectExistingBindings() to prevent module→core overwrites
- Architecture tests: ModuleStructureContractTest, CoreTemplateIsolationTest,
FrontendComponentRuntimeContractTest, AppContainerIsolationContractTest
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-18 22:19:56 +01:00
|
|
|
$this->pushAppContainer($this->container);
|
2026-03-07 20:14:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function tearDown(): void
|
|
|
|
|
{
|
feat: extend module platform with UI slots, runtime components, CLI tooling and {{userId}} search support
Completes the generic module platform that enables modules to contribute
UI elements, runtime JS components, and search resources without any
core hardcoding.
New generic UI slot types:
- topbar.right_item: module-contributed topbar buttons
- layout.body_end_template: module-contributed dialog/overlay templates
- layout.head_style: module-contributed global CSS
- runtime.component: declarative JS component registration with phase ordering
New infrastructure:
- ModuleAutoloader: PSR-4 autoloading for module-local PHP classes
- ModuleRuntimePageBuilder: symlinks module pages into runtime directory
- ModuleRuntimeAssetPublisher: publishes module CSS/JS to web/modules/
- ModulePermissionSynchronizer: syncs module permissions to DB
- CLI scripts: module-runtime-sync, module-build, module-migrate,
module-permissions-sync, module-assets-sync
- {{userId}} placeholder in SearchDataService for user-scoped search queries
- Component runtime with phased initialization (early/default/late)
- AppContainer.protectExistingBindings() to prevent module→core overwrites
- Architecture tests: ModuleStructureContractTest, CoreTemplateIsolationTest,
FrontendComponentRuntimeContractTest, AppContainerIsolationContractTest
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-18 22:19:56 +01:00
|
|
|
$this->restoreAppContainer();
|
2026-03-07 20:14:29 +01:00
|
|
|
$_SESSION = [];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// -- appDefaultTheme priority chain --
|
|
|
|
|
|
|
|
|
|
public function testDefaultThemeFallsBackToLight(): void
|
|
|
|
|
{
|
|
|
|
|
$this->assertSame('light', appDefaultTheme());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testDefaultThemeReadsAppSetting(): void
|
|
|
|
|
{
|
|
|
|
|
$this->setAppSettings(['app_theme' => 'dark']);
|
|
|
|
|
|
|
|
|
|
$this->assertSame('dark', appDefaultTheme());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testDefaultThemeTenantOverridesAppSetting(): void
|
|
|
|
|
{
|
|
|
|
|
$this->setAppSettings(['app_theme' => 'light']);
|
|
|
|
|
$_SESSION['current_tenant'] = ['default_theme' => 'dark'];
|
|
|
|
|
|
|
|
|
|
$this->assertSame('dark', appDefaultTheme());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testDefaultThemeIgnoresInvalidTenantTheme(): void
|
|
|
|
|
{
|
|
|
|
|
$_SESSION['current_tenant'] = ['default_theme' => 'nonexistent'];
|
|
|
|
|
|
|
|
|
|
$this->assertSame('light', appDefaultTheme());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testDefaultThemeIgnoresEmptyTenantTheme(): void
|
|
|
|
|
{
|
|
|
|
|
$this->setAppSettings(['app_theme' => 'dark']);
|
|
|
|
|
$_SESSION['current_tenant'] = ['default_theme' => ''];
|
|
|
|
|
|
|
|
|
|
$this->assertSame('dark', appDefaultTheme());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// -- currentTheme with user override --
|
|
|
|
|
|
|
|
|
|
public function testCurrentThemeReturnsDefaultWhenUserThemeDisabled(): void
|
|
|
|
|
{
|
|
|
|
|
$_SESSION['current_tenant'] = ['allow_user_theme' => '0', 'default_theme' => 'dark'];
|
|
|
|
|
$_SESSION['user'] = ['theme' => 'light'];
|
|
|
|
|
|
|
|
|
|
$this->assertSame('dark', currentTheme());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testCurrentThemeReturnsUserThemeWhenAllowed(): void
|
|
|
|
|
{
|
|
|
|
|
$_SESSION['current_tenant'] = ['allow_user_theme' => '1', 'default_theme' => 'light'];
|
|
|
|
|
$_SESSION['user'] = ['theme' => 'dark'];
|
|
|
|
|
|
|
|
|
|
$this->assertSame('dark', currentTheme());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testCurrentThemeFallsBackToDefaultForEmptyUserTheme(): void
|
|
|
|
|
{
|
|
|
|
|
$_SESSION['current_tenant'] = ['allow_user_theme' => '1', 'default_theme' => 'dark'];
|
|
|
|
|
$_SESSION['user'] = ['theme' => ''];
|
|
|
|
|
|
|
|
|
|
$this->assertSame('dark', currentTheme());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testCurrentThemeFallsBackToDefaultForInvalidUserTheme(): void
|
|
|
|
|
{
|
|
|
|
|
$_SESSION['current_tenant'] = ['allow_user_theme' => '1'];
|
|
|
|
|
$_SESSION['user'] = ['theme' => 'nonexistent'];
|
|
|
|
|
|
|
|
|
|
$this->assertSame('light', currentTheme());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// -- allowUserTheme feature flag --
|
|
|
|
|
|
|
|
|
|
public function testAllowUserThemeDefaultsToTrue(): void
|
|
|
|
|
{
|
|
|
|
|
$this->assertTrue(allowUserTheme());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testAllowUserThemeTenantExplicitlyEnabled(): void
|
|
|
|
|
{
|
|
|
|
|
$_SESSION['current_tenant'] = ['allow_user_theme' => '1'];
|
|
|
|
|
|
|
|
|
|
$this->assertTrue(allowUserTheme());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testAllowUserThemeTenantExplicitlyDisabled(): void
|
|
|
|
|
{
|
|
|
|
|
$_SESSION['current_tenant'] = ['allow_user_theme' => '0'];
|
|
|
|
|
|
|
|
|
|
$this->assertFalse(allowUserTheme());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testAllowUserThemeTenantOverridesAppSetting(): void
|
|
|
|
|
{
|
|
|
|
|
$this->setAppSettings(['app_theme_user' => '1']);
|
|
|
|
|
$_SESSION['current_tenant'] = ['allow_user_theme' => '0'];
|
|
|
|
|
|
|
|
|
|
$this->assertFalse(allowUserTheme());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testAllowUserThemeFallsBackToAppSettingWhenTenantNull(): void
|
|
|
|
|
{
|
|
|
|
|
$this->setAppSettings(['app_theme_user' => '0']);
|
|
|
|
|
|
|
|
|
|
$this->assertFalse(allowUserTheme());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// -- Tenant switch scenarios --
|
|
|
|
|
|
|
|
|
|
public function testThemeResolvesCorrectlyAfterTenantSwitch(): void
|
|
|
|
|
{
|
|
|
|
|
$_SESSION['user'] = ['theme' => 'dark'];
|
|
|
|
|
$_SESSION['current_tenant'] = ['allow_user_theme' => '1', 'default_theme' => 'light'];
|
|
|
|
|
|
|
|
|
|
$this->assertSame('dark', currentTheme());
|
|
|
|
|
|
|
|
|
|
// Simulate tenant switch: new tenant disallows user theme
|
|
|
|
|
$_SESSION['current_tenant'] = ['allow_user_theme' => '0', 'default_theme' => 'light'];
|
|
|
|
|
|
|
|
|
|
$this->assertSame('light', currentTheme());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testThemeResolvesNewDefaultAfterTenantSwitch(): void
|
|
|
|
|
{
|
|
|
|
|
$_SESSION['user'] = ['theme' => 'light'];
|
|
|
|
|
$_SESSION['current_tenant'] = ['allow_user_theme' => '0', 'default_theme' => 'light'];
|
|
|
|
|
|
|
|
|
|
$this->assertSame('light', currentTheme());
|
|
|
|
|
|
|
|
|
|
// Switch to tenant with dark default
|
|
|
|
|
$_SESSION['current_tenant'] = ['allow_user_theme' => '0', 'default_theme' => 'dark'];
|
|
|
|
|
|
|
|
|
|
$this->assertSame('dark', currentTheme());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param array<string, string|null> $settings
|
|
|
|
|
*/
|
|
|
|
|
private function setAppSettings(array $settings): void
|
|
|
|
|
{
|
|
|
|
|
$cache = $this->createMock(SettingCacheService::class);
|
|
|
|
|
$cache->method('get')->willReturnCallback(fn (string $key) => $settings[$key] ?? null);
|
|
|
|
|
$this->container->set(SettingCacheService::class, fn () => $cache);
|
|
|
|
|
}
|
|
|
|
|
}
|