40 lines
1.0 KiB
PHP
40 lines
1.0 KiB
PHP
<?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);
|
|
}
|
|
}
|