Files
XC_VM/tests/Unit/UiPrefsTest.php
T
Divarion_D fcba3d31cf fix(reseller): persist the customizer theme and seed it from the profile
Resellers could not save their customizer state: the reseller header
never set uiPrefsUrl and no save_ui_prefs endpoint existed on the
reseller API. config.js then primed "light" over the saved choice on
every page load.

- Add save_ui_prefs to the reseller API (own row only, XHR-guarded).
- Move the whitelist and the save/reset logic into Domain\User\UiPrefs,
  shared by the admin and reseller endpoints.
- Compute the first-paint prefs in UiPrefs::pageState(): an unset theme
  is seeded from the profile's System Theme.
- Share the customizer script block between the admin and reseller
  headers via layouts/ui_prefs_head.php.

Admin behaviour change: with no saved theme, admin now follows the
profile theme instead of always starting in light.
2026-10-26 21:35:16 +03:00

42 lines
1.3 KiB
PHP

<?php
use PHPUnit\Framework\TestCase;
use XcVm\Domain\User\UiPrefs;
/**
* The whitelist shared by the admin and reseller customizer endpoints: unknown
* keys and invalid values must never reach users.ui_prefs.
*/
final class UiPrefsTest extends TestCase {
public function testKeepsValidWhitelistedValues(): void {
$rIn = ['theme' => 'dark', 'color' => '#7367f0', 'semiDark' => 'true', 'lang' => 'en'];
$this->assertSame(
['theme' => 'dark', 'semiDark' => true, 'color' => '#7367f0', 'lang' => 'en'],
UiPrefs::sanitize($rIn)
);
}
public function testUnsetThemeIsSeededFromTheProfile(): void {
[$rPrefs, $rBsTheme] = UiPrefs::pageState(['theme' => 1, 'ui_prefs' => null], false);
$this->assertSame('dark', $rPrefs['theme']);
$this->assertSame('dark', $rBsTheme);
$this->assertFalse($rPrefs['rtl']);
}
public function testSavedThemeWinsOverTheProfile(): void {
[$rPrefs, $rBsTheme] = UiPrefs::pageState(['theme' => 1, 'ui_prefs' => '{"theme":"light"}'], true);
$this->assertSame('light', $rPrefs['theme']);
$this->assertSame('light', $rBsTheme);
$this->assertTrue($rPrefs['rtl']);
}
public function testDropsUnknownKeysAndInvalidValues(): void {
$rIn = ['theme' => 'neon', 'color' => 'red', 'skin' => 1, 'evil' => '<script>', 'rtl' => 'maybe'];
$this->assertSame([], UiPrefs::sanitize($rIn));
}
}