| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- <?php
- namespace Tests\Integration;
- use Illuminate\Support\Facades\DB;
- use PDO;
- /** Runs the login log scenarios on a disposable MySQL server without loading .env. */
- class AdminUserLoginLogMysqlTest extends AdminUserLoginLogTest
- {
- private ?PDO $control = null;
- private string $database;
- protected function setUp(): void
- {
- $socket = getenv('LOGIN_LOG_TEST_MYSQL_SOCKET');
- if (!$socket) {
- $this->markTestSkipped('Set LOGIN_LOG_TEST_MYSQL_SOCKET to a disposable MySQL server.');
- }
- $this->control = new PDO('mysql:unix_socket=' . $socket, 'root', '', [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]);
- $this->database = 'bot28_login_log_test_' . bin2hex(random_bytes(8));
- $this->control->exec('CREATE DATABASE `' . $this->database . '` CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci');
- parent::setUp();
- // Reproduce the deployed schema: accounts and user IDs can have different collations.
- DB::statement('ALTER TABLE bot_users
- MODIFY user_id VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL,
- MODIFY account VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL');
- }
- protected function tearDown(): void
- {
- if ($this->control !== null) {
- parent::tearDown();
- $this->control->exec('DROP DATABASE `' . $this->database . '`');
- $this->control = null;
- }
- }
- protected function connectionConfig(): array
- {
- return [
- 'driver' => 'mysql', 'unix_socket' => getenv('LOGIN_LOG_TEST_MYSQL_SOCKET'),
- 'database' => $this->database, 'username' => 'root', 'password' => '',
- 'prefix' => 'bot_', 'charset' => 'utf8mb4', 'collation' => 'utf8mb4_general_ci',
- ];
- }
- public function test_account_matching_keeps_case_insensitive_and_unicode_semantics(): void
- {
- DB::table('users')->insert([
- 'user_id' => '9004', 'member_id' => 'support-unicode', 'account' => '客服É', 'from' => '0',
- ]);
- $this->log('', 'KEFU001', 0);
- $this->log('', '客服é', 0);
- $expected = [$this->log('', '其他账号', 0), $this->log('1001', 'ALICE', 0)];
- $data = $this->logs(['status' => 0]);
- $this->assertSame(2, $data['total']);
- $this->assertSame(array_reverse($expected), array_column($data['data'], 'id'));
- }
- }
|