测试: 快捷筛选不继承工具型开关护栏

This commit is contained in:
萝卜
2026-03-18 13:53:14 +08:00
parent 7a369d7653
commit 506f5c17ba

View File

@@ -0,0 +1,57 @@
<?php
namespace Tests\Feature;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class AdminPlatformOrderIndexQuickFiltersShouldNotInheritToolTogglesTest extends TestCase
{
use RefreshDatabase;
protected function loginAsPlatformAdmin(): void
{
$this->seed();
$this->post('/admin/login', [
'email' => 'platform.admin@demo.local',
'password' => 'Platform@123456',
])->assertRedirect('/admin');
}
public function test_quick_filters_should_not_inherit_tool_toggles(): void
{
$this->loginAsPlatformAdmin();
// 模拟用户从某个“工具型集合”进入fail_only/bmpa_failed_only 等),
// 再点击快捷筛选时,不应把这些工具型开关继承过去,避免叠加冲突导致空结果。
$res = $this->get('/admin/platform-orders?merchant_id=1&bmpa_failed_only=1&fail_only=1');
$res->assertOk();
$html = (string) $res->getContent();
// 1) 快捷筛选:同步失败
$this->assertMatchesRegularExpression('/<a[^>]*href="([^"]+)"[^>]*class="muted"[^>]*>同步失败<\/a>/', $html);
preg_match('/<a[^>]*href="([^"]+)"[^>]*class="muted"[^>]*>同步失败<\/a>/', $html, $m1);
$href1 = html_entity_decode($m1[1] ?? '');
$query1 = parse_url($href1, PHP_URL_QUERY) ?: '';
parse_str($query1, $q1);
$this->assertSame('failed', (string) ($q1['sync_status'] ?? ''));
$this->assertSame('1', (string) ($q1['merchant_id'] ?? ''));
$this->assertArrayNotHasKey('bmpa_failed_only', $q1);
$this->assertArrayNotHasKey('fail_only', $q1);
// 2) 快捷筛选可BMPA处理
$this->assertMatchesRegularExpression('/<a[^>]*href="([^"]+)"[^>]*class="muted"[^>]*>可BMPA处理<\/a>/', $html);
preg_match('/<a[^>]*href="([^"]+)"[^>]*class="muted"[^>]*>可BMPA处理<\/a>/', $html, $m2);
$href2 = html_entity_decode($m2[1] ?? '');
$query2 = parse_url($href2, PHP_URL_QUERY) ?: '';
parse_str($query2, $q2);
$this->assertSame('1', (string) ($q2['bmpa_processable_only'] ?? ''));
$this->assertSame('1', (string) ($q2['merchant_id'] ?? ''));
$this->assertArrayNotHasKey('bmpa_failed_only', $q2);
$this->assertArrayNotHasKey('fail_only', $q2);
}
}