refactor(admin): AdminFlash增加apply并在批量动作成功提示复用
This commit is contained in:
39
tests/Unit/AdminFlashApplyTest.php
Normal file
39
tests/Unit/AdminFlashApplyTest.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit;
|
||||
|
||||
use App\Support\AdminFlash;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class AdminFlashApplyTest extends TestCase
|
||||
{
|
||||
public function test_apply_should_call_with_for_non_empty_values(): void
|
||||
{
|
||||
$redirect = new class {
|
||||
public array $calls = [];
|
||||
|
||||
public function with($k, $v)
|
||||
{
|
||||
$this->calls[] = [$k, $v];
|
||||
return $this;
|
||||
}
|
||||
};
|
||||
|
||||
$payload = [
|
||||
'success' => 'ok',
|
||||
'success_link_href' => '/admin/x',
|
||||
'success_link_label' => '查看',
|
||||
'warning_copy_text' => '', // 空字符串应跳过
|
||||
];
|
||||
|
||||
AdminFlash::apply($redirect, $payload);
|
||||
|
||||
$this->assertNotEmpty($redirect->calls);
|
||||
$keys = array_map(fn ($x) => (string) $x[0], $redirect->calls);
|
||||
|
||||
$this->assertContains('success', $keys);
|
||||
$this->assertContains('success_link_href', $keys);
|
||||
$this->assertContains('success_link_label', $keys);
|
||||
$this->assertNotContains('warning_copy_text', $keys);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user