refactor(admin): 增加AdminFlash::warning并让BatchDispatchWarning复用

This commit is contained in:
萝卜
2026-03-17 19:01:43 +08:00
parent 3f471aa8db
commit bfc04d8f36
3 changed files with 71 additions and 12 deletions

View File

@@ -0,0 +1,29 @@
<?php
namespace Tests\Unit;
use App\Support\AdminFlash;
use PHPUnit\Framework\TestCase;
class AdminFlashWarningPayloadTest extends TestCase
{
public function test_warning_should_return_message_only_when_no_link_and_no_copy(): void
{
$p = AdminFlash::warning('warn');
$this->assertSame('warn', (string) ($p['warning'] ?? ''));
$this->assertArrayNotHasKey('warning_link_href', $p);
$this->assertArrayNotHasKey('warning_copy_text', $p);
}
public function test_warning_should_include_link_and_copy_when_provided(): void
{
$p = AdminFlash::warning('warn', '/admin/x', '查看', 'ABC', '复制run_id');
$this->assertSame('warn', (string) ($p['warning'] ?? ''));
$this->assertSame('/admin/x', (string) ($p['warning_link_href'] ?? ''));
$this->assertSame('查看', (string) ($p['warning_link_label'] ?? ''));
$this->assertSame('ABC', (string) ($p['warning_copy_text'] ?? ''));
$this->assertSame('复制run_id', (string) ($p['warning_copy_label'] ?? ''));
}
}