mirror of
https://gitee.com/ulthon/ulthon_admin.git
synced 2026-11-08 03:50:50 +08:00
fix(notice): 发送事务包裹与软删过滤加固
This commit is contained in:
@@ -12,7 +12,7 @@ use think\facade\Db;
|
||||
/**
|
||||
* NoticeService 核心行为集成测试.
|
||||
*
|
||||
* 覆盖 11 个契约点(与计划任务 3 逐项对齐,每项一个 test 方法):
|
||||
* 覆盖 13 个契约点(与计划任务 3 逐项对齐,每项一个 test 方法):
|
||||
* 1. send 主体 + target 展开
|
||||
* 2. 'all' 广播(仅 status=1,含无 email 管理员)
|
||||
* 3. channels 缺省按 scene.channels 展开
|
||||
@@ -24,6 +24,8 @@ use think\facade\Db;
|
||||
* 9. inmail 全局总闸关闭跳过(键不存在视为开)
|
||||
* 10. unreadCount/markRead/markAllRead 数字正确
|
||||
* 11. markRead 越权防护
|
||||
* 12. 'all' 广播过滤软删管理员(F2-C10)
|
||||
* 13. unreadCount 不受软删通知影响(F2-C6 个人域口径)
|
||||
*
|
||||
* fixture 均为事务内自造数据,tearDown 自动回滚;缓存清理显式执行
|
||||
* (Cache 不受事务回滚影响,见 setInmailSwitch/clearInmailSwitch)。
|
||||
@@ -335,6 +337,44 @@ class NoticeServiceTest extends TestCase
|
||||
$this->assertSame(1, NoticeService::unreadCount($adminB), 'markAllRead 不得触碰他人行');
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
// 12. 'all' 广播过滤软删管理员(F2-C10)
|
||||
// =========================================================================
|
||||
|
||||
public function test_send_all_excludes_soft_deleted_admins(): void
|
||||
{
|
||||
$aliveAdmin = $this->createAdmin();
|
||||
$softDeletedAdmin = $this->createAdmin(['delete_time' => time()]);
|
||||
|
||||
$noticeId = NoticeService::send('all', '软删过滤广播', '内容');
|
||||
|
||||
$this->assertGreaterThan(0, Db::name('system_notice_target')
|
||||
->where('notice_id', $noticeId)->where('admin_id', $aliveAdmin)->count(), '在册管理员应收到广播');
|
||||
$this->assertSame(
|
||||
0,
|
||||
Db::name('system_notice_target')->where('notice_id', $noticeId)->where('admin_id', $softDeletedAdmin)->count(),
|
||||
'软删管理员不应收到广播'
|
||||
);
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
// 13. unreadCount 不受软删通知影响(F2-C6 个人域口径)
|
||||
// =========================================================================
|
||||
|
||||
public function test_unread_count_ignores_soft_deleted_notices(): void
|
||||
{
|
||||
$adminId = $this->createAdmin();
|
||||
|
||||
NoticeService::send([$adminId], '正常通知', '内容');
|
||||
$softDeletedNoticeId = NoticeService::send([$adminId], '将被删除的通知', '内容');
|
||||
$this->assertSame(2, NoticeService::unreadCount($adminId));
|
||||
|
||||
// 管理页删除 = 软删 notice 主体(delete_time 置时间戳)
|
||||
Db::name('system_notice')->where('id', $softDeletedNoticeId)->update(['delete_time' => time()]);
|
||||
|
||||
$this->assertSame(1, NoticeService::unreadCount($adminId), '软删通知不应计入未读数');
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
// fixture 工厂(事务内运行,tearDown 自动回滚)
|
||||
// =========================================================================
|
||||
|
||||
Reference in New Issue
Block a user