优化屏蔽,可以保存状态

This commit is contained in:
2026-04-14 22:48:29 +08:00
parent 7255d50966
commit 1a39ddd725
8 changed files with 279 additions and 5 deletions
+47
View File
@@ -1,5 +1,10 @@
<?php
/**
* 文件功能:用户控制器功能测试
* 覆盖个人资料、密码与聊天室偏好设置等关键接口。
*/
namespace Tests\Feature;
use App\Models\Room;
@@ -15,6 +20,9 @@ class UserControllerTest extends TestCase
{
use RefreshDatabase;
/**
* 初始化用户控制器测试所需的系统参数。
*/
protected function setUp(): void
{
parent::setUp();
@@ -27,6 +35,9 @@ class UserControllerTest extends TestCase
Sysparam::updateOrCreate(['alias' => 'smtp_enabled'], ['body' => '1']); // Allow email changing in tests
}
/**
* 测试可以查看用户资料卡接口。
*/
public function test_can_view_user_profile()
{
$user = User::factory()->create([
@@ -43,6 +54,9 @@ class UserControllerTest extends TestCase
->assertJsonPath('data.user_level', 10);
}
/**
* 测试不改邮箱时可以正常更新个人资料。
*/
public function test_can_update_profile_without_email_change()
{
$user = User::factory()->create([
@@ -67,6 +81,9 @@ class UserControllerTest extends TestCase
$this->assertEquals('new sign', $user->sign);
}
/**
* 测试改邮箱但未提交验证码时会被拒绝。
*/
public function test_cannot_update_email_without_verification_code()
{
$user = User::factory()->create([
@@ -87,6 +104,9 @@ class UserControllerTest extends TestCase
->assertJsonPath('message', '新邮箱需要验证码,请先获取并填写验证码。');
}
/**
* 测试提供有效验证码后可以成功修改邮箱。
*/
public function test_can_update_email_with_valid_code()
{
$user = User::factory()->create([
@@ -111,6 +131,33 @@ class UserControllerTest extends TestCase
$this->assertEquals('new@example.com', $user->email);
}
/**
* 测试可以保存聊天室屏蔽与禁音偏好。
*/
public function test_can_update_chat_preferences(): void
{
$user = User::factory()->create([
'chat_preferences' => null,
]);
$response = $this->actingAs($user)->putJson('/user/chat-preferences', [
'blocked_system_senders' => ['钓鱼播报', '跑马'],
'sound_muted' => true,
]);
$response->assertOk()
->assertJsonPath('status', 'success')
->assertJsonPath('data.blocked_system_senders.0', '钓鱼播报')
->assertJsonPath('data.blocked_system_senders.1', '跑马')
->assertJsonPath('data.sound_muted', true);
$user->refresh();
$this->assertEquals([
'blocked_system_senders' => ['钓鱼播报', '跑马'],
'sound_muted' => true,
], $user->chat_preferences);
}
public function test_can_change_password()
{
$user = User::factory()->create([