提交
This commit is contained in:
53
tests/unit/AppUpdateServiceTest.php
Normal file
53
tests/unit/AppUpdateServiceTest.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?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'));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user