Files
chatroom/tests/Feature/SecurityBindAlertTest.php
T

93 lines
2.6 KiB
PHP

<?php
/**
* 文件功能:大厅安全绑定强引导(邮箱/微信二选一)提示弹窗 Feature 测试
*
* @author ChatRoom Laravel
*
* @version 1.0.0
*/
namespace Tests\Feature;
use App\Models\Room;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class SecurityBindAlertTest extends TestCase
{
use RefreshDatabase;
/**
* 创建测试用房间,防范 Room 未配置 Factory
*/
protected function createRoom(): Room
{
return Room::query()->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('账号安全绑定提醒');
}
}