63 lines
2.0 KiB
PHP
63 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Models\Admin;
|
|
use App\Models\Device;
|
|
use App\Models\PageVisit;
|
|
use App\Services\CorunaCrypto;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use PHPUnit\Framework\Attributes\Test;
|
|
use Tests\TestCase;
|
|
|
|
class DeviceCountryTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
#[Test]
|
|
public function xxbb_profile_stores_cf_country_and_show_renders_it(): void
|
|
{
|
|
$ts = '1786468227899';
|
|
$enc = (new CorunaCrypto('Ek8pl31K2yeHgQwy'))->encryptJson([
|
|
'd' => '000C30D83CD0402E',
|
|
'c' => '202700cfb1ad3de68e11239dcc26c30b',
|
|
'deviceInfo' => ['productType' => 'iPhone12,8', 'productVersion' => '16.6'],
|
|
], $ts);
|
|
|
|
$this->call('POST', '/a', [], [], [], [
|
|
'CONTENT_TYPE' => 'text/plain',
|
|
'HTTP_X_TS' => $ts,
|
|
'HTTP_CF_IPCOUNTRY' => 'US',
|
|
], $enc['body'])->assertOk();
|
|
|
|
$device = Device::query()->where('device_id', '000C30D83CD0402E')->first();
|
|
$this->assertNotNull($device);
|
|
$this->assertSame('US', $device->country);
|
|
$this->assertStringContainsString('(美国)', $device->formattedIp());
|
|
|
|
$admin = Admin::query()->create(['username' => 'admin', 'password' => 'admin123']);
|
|
$this->actingAs($admin, 'admin')
|
|
->get(route('admin.devices.show', $device))
|
|
->assertOk()
|
|
->assertSee('(美国)', false);
|
|
}
|
|
|
|
#[Test]
|
|
public function show_falls_back_to_visit_country_when_device_country_empty(): void
|
|
{
|
|
$device = Device::query()->create([
|
|
'device_id' => '000C30D83CD0402E',
|
|
'ip' => '1.2.3.4',
|
|
]);
|
|
PageVisit::query()->create([
|
|
'channel_id' => '0.0.01',
|
|
'client_uid' => 'aaaaaaaaaaaaaaaa',
|
|
'ip' => '1.2.3.4',
|
|
'country' => 'FR',
|
|
]);
|
|
|
|
$this->assertSame('FR', $device->resolvedCountry());
|
|
$this->assertSame('1.2.3.4(法国)', $device->formattedIp());
|
|
}
|
|
}
|