mirror of
https://github.com/Vateron-Media/XC_VM.git
synced 2026-09-25 12:01:55 +02:00
Namespace the rest of Core, completing the Core layer:
- Backup, Boundary, Cache (CacheInterface/FileCache/RedisCache), Diagnostics,
GeoIP (GeoIPService/MaxMindUpdater), Init (LegacyInitializer), Localization
(Translator), Process (Thread/Multithread/ProcessManager), Updates
(GitHubReleases), Util (NetworkUtils, AdminHelpers, Encryption, GeoIP,
ImageUtils/ImageResizeService, Mobile_Detect, StreamUtils, SystemInfo,
TimeUtils), Validation (InputValidator) → XcVm\Core\<Subdir>.
- Rename GithubReleases.php → GitHubReleases.php so the file matches its class
name (PSR-4 is case-sensitive); fix the WebApiBootstrap require accordingly.
- Qualify built-ins (\Exception, \DateTime, \DateTimeZone, \Redis,
\RuntimeException, \BadMethodCallException, ...) and still-global deps
(\ServerRepository, \CacheReader, \DatabaseFactory, \BouquetService,
\CategoryService, \FfmpegPaths, \StreamSorter, \XC_VM). LegacyInitializer's
Domain calls stay \-qualified (the known Core→Domain exception).
- Add use to referrers; fix leading-backslash refs from earlier commits; fix
string class refs class_exists('Translator'/'NetworkUtils'/...) → ::class.
Remove the duplicate global 'use BoundaryInterface;' in MinistraModule.
- phpstan-baseline.neon regenerated.
Core is now fully namespaced (procedural constant/error/RequestGuard files stay
global by design; M3uParser/PhpM3u8 remain vendored). Verified: php -l clean;
PHPStan no errors; PHPUnit 295/295; leading-backslash re-sweep clean.
85 lines
2.6 KiB
PHP
85 lines
2.6 KiB
PHP
<?php
|
|
|
|
use XcVm\Core\Util\AdminHelpers;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
/**
|
|
* @covers AdminHelpers
|
|
*/
|
|
final class AdminHelpersTest extends TestCase {
|
|
|
|
public function testValidateCidrAcceptsValidAddressesAndMasks() {
|
|
$this->assertTrue(AdminHelpers::validateCIDR('192.168.1.1'));
|
|
$this->assertTrue(AdminHelpers::validateCIDR('192.168.1.0/24'));
|
|
$this->assertTrue(AdminHelpers::validateCIDR('::1'));
|
|
}
|
|
|
|
public function testValidateCidrRejectsInvalidInput() {
|
|
$this->assertFalse(AdminHelpers::validateCIDR('not-an-ip'));
|
|
$this->assertFalse(AdminHelpers::validateCIDR('10.0.0.0/33'));
|
|
$this->assertFalse(AdminHelpers::validateCIDR('2001:db8::/129'));
|
|
}
|
|
|
|
public function testRoundUpToAny() {
|
|
$this->assertEquals(10, AdminHelpers::roundUpToAny(7, 5));
|
|
$this->assertEquals(15, AdminHelpers::roundUpToAny(13, 5));
|
|
$this->assertEquals(5, AdminHelpers::roundUpToAny(3, 5));
|
|
}
|
|
|
|
public function testGenerateStringLengthAndUnambiguousCharset() {
|
|
$charset = '23456789abcdefghjkmnpqrstuvwxyzABCDEFGHJKMNPQRSTUVWXYZ';
|
|
$s = AdminHelpers::generateString(16);
|
|
$this->assertSame(16, strlen($s));
|
|
$this->assertSame(strlen($s), strspn($s, $charset));
|
|
}
|
|
|
|
public function testSortArrayByArray() {
|
|
$this->assertSame(
|
|
array('c', 'b', 'a'),
|
|
AdminHelpers::sortArrayByArray(array('a', 'b', 'c'), array('c', 'b', 'a'))
|
|
);
|
|
}
|
|
|
|
public function testGetBarColourThresholds() {
|
|
$this->assertSame('bg-danger', AdminHelpers::getBarColour(80));
|
|
$this->assertSame('bg-danger', AdminHelpers::getBarColour(75));
|
|
$this->assertSame('bg-warning', AdminHelpers::getBarColour(50));
|
|
$this->assertSame('bg-success', AdminHelpers::getBarColour(10));
|
|
}
|
|
|
|
public function testFormatUptime() {
|
|
$this->assertSame('01h 01m 01s', AdminHelpers::formatUptime(3661));
|
|
$this->assertSame('01d 01h 00m', AdminHelpers::formatUptime(90000));
|
|
}
|
|
|
|
public function testFilterIdsKeepsOnlyAllowedPositiveInts() {
|
|
$this->assertSame(
|
|
array(1, 2),
|
|
AdminHelpers::filterIDs(array('1', '2', 'x', 5), array(1, 2, 3))
|
|
);
|
|
}
|
|
|
|
public function testGetPageFromUrl() {
|
|
$this->assertSame('bouquet', AdminHelpers::getPageFromURL('http://host/admin/bouquet.php'));
|
|
$this->assertNull(AdminHelpers::getPageFromURL(''));
|
|
}
|
|
|
|
public function testProtocolDetectionFromServerVars() {
|
|
$saved = $_SERVER;
|
|
|
|
$_SERVER['HTTPS'] = 'on';
|
|
$this->assertTrue(AdminHelpers::issecure());
|
|
$this->assertSame('https', AdminHelpers::getProtocol());
|
|
|
|
unset($_SERVER['HTTPS']);
|
|
$_SERVER['SERVER_PORT'] = 80;
|
|
$this->assertFalse(AdminHelpers::issecure());
|
|
$this->assertSame('http', AdminHelpers::getProtocol());
|
|
|
|
$_SERVER['SERVER_PORT'] = 443;
|
|
$this->assertTrue(AdminHelpers::issecure());
|
|
|
|
$_SERVER = $saved;
|
|
}
|
|
}
|