Files
miniapi/tests/unit/AppUpdateServiceTest.php
gaofeng e0aeff2af7 提交
2026-09-01 11:07:13 +08:00

54 lines
1.7 KiB
PHP

<?php
declare(strict_types=1);
namespace tests\unit;
use app\miniapi\service\AppUpdateService;
use PHPUnit\Framework\TestCase;
final class AppUpdateServiceTest extends TestCase
{
public function testBootstrapUsesStableGatewayForRequestedStoreChannel(): void
{
$result = (new AppUpdateService())->bootstrap([
'latest_version_code' => 21,
'latest_version_name' => '1.0.19',
'gateway_url' => 'https://miniapi.jzvisa.cn/miniapi/app/update',
], 'huawei');
self::assertSame(21, $result['latest_version_code']);
self::assertSame('https://miniapi.jzvisa.cn/miniapi/app/update?channel=huawei', $result['download_url']);
}
public function testUnknownChannelFallsBackToOfficial(): void
{
$service = new AppUpdateService();
self::assertSame('official', $service->normalizeChannel('unknown-store'));
self::assertSame('official', $service->normalizeChannel(''));
}
public function testTextFalseDoesNotEnableForcedUpdate(): void
{
$result = (new AppUpdateService())->bootstrap([
'force_update' => 'false',
], 'official');
self::assertFalse($result['force_update']);
}
public function testStoreTargetFallsBackToOfficialAndRejectsUnsafeUrls(): void
{
$service = new AppUpdateService();
$config = [
'store_urls' => [
'official' => 'https://jzvisa.cn/evus',
'huawei' => 'javascript:alert(1)',
],
];
self::assertSame('https://jzvisa.cn/evus', $service->storeTarget($config, 'huawei'));
self::assertSame('https://jzvisa.cn/evus', $service->storeTarget($config, 'xiaomi'));
}
}