This commit is contained in:
hashbro
2026-08-24 06:23:07 +08:00
parent c00396dc1f
commit db574cc629
114 changed files with 108297 additions and 266 deletions
+59 -7
View File
@@ -3,6 +3,7 @@
namespace Tests\Feature;
use App\Models\Admin;
use App\Models\DsChainLog;
use App\Models\PageVisit;
use App\Support\UserAgentParser;
use Illuminate\Foundation\Testing\RefreshDatabase;
@@ -52,6 +53,8 @@ class PageVisitTest extends TestCase
$row = PageVisit::query()->first();
$this->assertNotNull($row);
$this->assertSame(self::CHANNEL, $row->channel_id);
$this->assertSame(PageVisit::CHAIN_CORUNA, $row->chain);
$this->assertSame('Coruna', PageVisit::chainLabel((int) $row->chain));
$this->assertSame(PageVisit::visitorUid($row->domain ?? 'localhost', $row->ip), $row->client_uid);
$this->assertSame(PageVisit::VISITOR_UID_LENGTH, strlen($row->client_uid));
$this->assertSame('iOS', $row->os);
@@ -156,6 +159,30 @@ class PageVisitTest extends TestCase
$this->assertSame('15.6.7', $parsed['browser_version']);
}
#[Test]
public function user_agent_parser_maps_ios26_compat_ua(): void
{
$parsed = UserAgentParser::parse(
'Mozilla/5.0 (iPhone; CPU iPhone OS 18_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/26.6 Mobile/15E148 Safari/604.1'
);
$this->assertSame('iOS', $parsed['os']);
$this->assertSame('26.6', $parsed['os_version']);
$this->assertSame('Safari', $parsed['browser']);
$this->assertSame('26.6', $parsed['browser_version']);
}
#[Test]
public function user_agent_parser_keeps_real_ios_18_7(): void
{
$parsed = UserAgentParser::parse(
'Mozilla/5.0 (iPhone; CPU iPhone OS 18_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.7 Mobile/15E148 Safari/604.1'
);
$this->assertSame('iOS', $parsed['os']);
$this->assertSame('18.7', $parsed['os_version']);
$this->assertSame('Safari', $parsed['browser']);
$this->assertSame('18.7', $parsed['browser_version']);
}
#[Test]
public function dashboard_includes_pv_uv(): void
{
@@ -233,23 +260,48 @@ class PageVisitTest extends TestCase
}
#[Test]
public function visits_groups_by_os_version(): void
public function visits_data_labels_chain(): void
{
PageVisit::query()->create([
'channel_id' => self::CHANNEL,
'client_uid' => 'u1',
'client_uid' => '50624FE26CC4A0DF689EAEA117557C3E',
'chain' => PageVisit::CHAIN_DARKSWORD,
'os' => 'iOS',
'os_version' => '16.6',
'os_version' => '18.6',
'browser' => 'Safari',
'created_at' => now(),
]);
$admin = Admin::query()->create(['username' => 'admin', 'password' => 'admin123']);
$this->actingAs($admin, 'admin')
->getJson(route('admin.visits.groups', ['range' => 'today', 'group' => 'os_version']))
->getJson(route('admin.visits.data', ['range' => 'today']))
->assertOk()
->assertJsonPath('data.rows.0.label', 'iOS 16.6')
->assertJsonPath('data.rows.0.pv', 1)
->assertJsonPath('data.rows.0.uv', 1);
->assertJsonPath('data.0.chain', 1)
->assertJsonPath('data.0.chain_label', 'DarkSword')
->assertJsonPath('data.0.client_uid', '50624FE26CC4A0DF689EAEA117557C3E');
}
#[Test]
public function visits_logs_returns_ds_stages(): void
{
$uid = '50624FE26CC4A0DF689EAEA117557C3E';
PageVisit::query()->create([
'channel_id' => self::CHANNEL,
'client_uid' => $uid,
'chain' => PageVisit::CHAIN_DARKSWORD,
'os' => 'iOS',
'created_at' => now(),
]);
DsChainLog::record($uid, 'boot', 8, 'frame_boot', self::CHANNEL);
DsChainLog::record($uid, 'pe', 86, 'pe', self::CHANNEL);
$admin = Admin::query()->create(['username' => 'admin', 'password' => 'admin123']);
$this->actingAs($admin, 'admin')
->getJson(route('admin.visits.logs', ['range' => 'today', 'client_uid' => $uid]))
->assertOk()
->assertJsonPath('data.0.stage', 'boot')
->assertJsonPath('data.0.stage_label', '启动')
->assertJsonPath('data.1.stage', 'pe')
->assertJsonPath('data.1.stage_label', '权限提升');
}
}