Files
XC_VM/tests/Unit/ThemeEnumTest.php
T
Divarion_D c27950093f refactor(admin): replace admin_constants globals with reference classes and enums
Move the 17 global lookup arrays from resources/data/admin_constants.php
into PSR-4 classes and enums, eliminating the last big pile of `global`
reference data.

New XcVm\Core\Reference\* (const + static accessors, FfmpegBinaries-style):
GeoReference, LocaleReference, DeviceReference, UiReference,
PermissionReference, StatusBadge. New XcVm\Core\Enum\* (backed enums with
label()/options(), ModuleState-style): Theme (int), ResellerAction and
ClientFilter (string).

All consumers migrated off `global $rX` / `$GLOBALS['rX']` and the
BaseAdminController extract bridge: TableController, DashboardController,
SearchAjaxController, SettingsController, ResellerAPI and
ResellerLoginController call the classes directly, and 21 view templates
import them via `use`. The extract whitelist entries, the bootstrap
require and admin_constants.php itself are removed.

Fixes a latent bug: TableController read $rClientFilters without a
`global`, so the client-request log showed raw status codes instead of
labels; ClientFilter::labelFor() now resolves them.

The reference classes and the three new enums are excluded from the
load-balancer build (all consumers are already MAIN-only).

Adds unit tests for the enums, StatusBadge and the reference data.
2026-08-31 20:58:23 +03:00

39 lines
1.2 KiB
PHP

<?php
use XcVm\Core\Enum\Theme;
use PHPUnit\Framework\TestCase;
final class ThemeEnumTest extends TestCase {
public function testCasesAreIntBackedByLegacyIndex(): void {
$this->assertSame(0, Theme::Light->value);
$this->assertSame(1, Theme::Dark->value);
}
public function testIsDark(): void {
$this->assertFalse(Theme::Light->isDark());
$this->assertTrue(Theme::Dark->isDark());
}
public function testLabel(): void {
$this->assertSame('Light', Theme::Light->label());
$this->assertSame('Dark', Theme::Dark->label());
}
public function testFromIdMapsStoredValues(): void {
$this->assertSame(Theme::Light, Theme::fromId(0));
$this->assertSame(Theme::Dark, Theme::fromId(1));
$this->assertSame(Theme::Dark, Theme::fromId('1'));
}
public function testFromIdFallsBackToLightForInvalid(): void {
$this->assertSame(Theme::Light, Theme::fromId(99));
$this->assertSame(Theme::Light, Theme::fromId(''));
$this->assertSame(Theme::Light, Theme::fromId(null));
}
public function testOptionsPreserveLegacyOrder(): void {
$this->assertSame([0 => 'Light', 1 => 'Dark'], Theme::options());
}
}