create([ 'room_name' => '大厅', 'room_owner' => '站长', 'room_des' => '欢迎光临', 'permit_level' => 0, ]); } /** * 测试当用户邮箱和微信均未绑定时,进入聊天室大厅页面会渲染安全绑定遮罩弹窗提示 */ public function test_shows_bind_alert_modal_when_user_has_no_email_and_no_wechat(): void { $user = User::factory()->create([ 'email' => null, 'wxid' => null, ]); $room = $this->createRoom(); $response = $this->actingAs($user)->get(route('chat.room', $room->id)); $response->assertStatus(200); $response->assertSee('security-bind-modal'); $response->assertSee('账号安全绑定提醒'); $response->assertSee('立即前往设置(查看微信小小二维码)'); } /** * 测试当用户已经设置了邮箱时,进入聊天室大厅页面不会弹出安全绑定提醒 */ public function test_does_not_show_bind_alert_when_user_has_email(): void { $user = User::factory()->create([ 'email' => 'has.email@example.com', 'wxid' => null, ]); $room = $this->createRoom(); $response = $this->actingAs($user)->get(route('chat.room', $room->id)); $response->assertStatus(200); $response->assertDontSee('security-bind-modal'); $response->assertDontSee('账号安全绑定提醒'); } /** * 测试当用户已经绑定了微信时,进入聊天室大厅页面不会弹出安全提醒 */ public function test_does_not_show_bind_alert_when_user_has_wechat(): void { $user = User::factory()->create([ 'email' => null, 'wxid' => 'wxid_test_123', ]); $room = $this->createRoom(); $response = $this->actingAs($user)->get(route('chat.room', $room->id)); $response->assertStatus(200); $response->assertDontSee('security-bind-modal'); $response->assertDontSee('账号安全绑定提醒'); } }