From 8e13497547f6a31c9d296f02ba0c43514469bdde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=90=9D=E5=8D=9C?= Date: Sat, 14 Mar 2026 15:09:16 +0000 Subject: [PATCH] =?UTF-8?q?=E5=A5=97=E9=A4=90=EF=BC=9A=E5=BF=AB=E6=8D=B7?= =?UTF-8?q?=E7=AD=9B=E9=80=89=E6=8A=A4=E6=A0=8F=E6=B5=8B=E8=AF=95=E5=8D=87?= =?UTF-8?q?=E7=BA=A7=EF=BC=88=E4=B8=8D=E4=BE=9D=E8=B5=96=20query=20?= =?UTF-8?q?=E9=A1=BA=E5=BA=8F=EF=BC=8C=E6=96=AD=E8=A8=80=E4=BB=85=E4=BF=9D?= =?UTF-8?q?=E7=95=99=20back/keyword=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...anIndexQuickFilterLinksKeepContextTest.php | 47 ++++++++++++++++--- 1 file changed, 40 insertions(+), 7 deletions(-) diff --git a/tests/Feature/AdminPlanIndexQuickFilterLinksKeepContextTest.php b/tests/Feature/AdminPlanIndexQuickFilterLinksKeepContextTest.php index 6341db6..3704224 100644 --- a/tests/Feature/AdminPlanIndexQuickFilterLinksKeepContextTest.php +++ b/tests/Feature/AdminPlanIndexQuickFilterLinksKeepContextTest.php @@ -23,19 +23,52 @@ class AdminPlanIndexQuickFilterLinksKeepContextTest extends TestCase { $this->loginAsPlatformAdmin(); - // 目前 plans/index 没有“快捷筛选”区块,这个测试先作为护栏: - // 一旦我们加上快捷筛选,就要求它只保留上下文键(back/keyword),不继承 page。 - // 这里先访问带筛选与 page/back 的页面,确保不会出现携带 page 的快捷筛选链接(未来回归用)。 + // 快捷筛选应只保留上下文键(back/keyword),不继承 page/status 等其它筛选。 $res = $this->get('/admin/plans?status=active&billing_cycle=monthly&keyword=abc&page=9&back=%2Fadmin%2Fplatform-orders'); $res->assertOk(); $html = (string) $res->getContent(); - // 当前版本没有快捷筛选区块:先断言页面中存在返回链接与新建套餐链接(保证页面渲染正常) - $res->assertSee('套餐管理', false); - $res->assertSee('/admin/plans/create?', false); + // 页面渲染正常 + $res->assertSee('快捷筛选', false); - // 兜底护栏:页面中不应出现带 page=9 的“固定快捷筛选链接”(避免未来引入时误带 page) + // 快捷筛选链接不应携带 page=9 $this->assertStringNotContainsString('page=9', $html); + + // 快捷筛选链接应保留 back(上下文) + $this->assertStringContainsString('back=%2Fadmin%2Fplatform-orders', $html); + + // 快捷筛选链接应保留 keyword(上下文) + $this->assertStringContainsString('keyword=abc', $html); + + // 同时不应把当前 status/billing_cycle/page 继承到快捷筛选链接中(避免叠加导致空结果)。 + // 这里定位“启用中(status=active)”的快捷筛选链接做断言(不依赖 query 参数顺序)。 + preg_match_all('/href="([^"]+)"/', $html, $m); + $hrefs = $m[1] ?? []; + + $found = false; + foreach ($hrefs as $u) { + if (!str_starts_with($u, '/admin/plans?')) { + continue; + } + + $parts = parse_url($u); + parse_str($parts['query'] ?? '', $q); + + if (($q['status'] ?? null) !== 'active') { + continue; + } + + $found = true; + + $this->assertSame('abc', $q['keyword'] ?? null); + $this->assertSame('/admin/platform-orders', $q['back'] ?? null); + + $this->assertArrayNotHasKey('page', $q); + $this->assertArrayNotHasKey('billing_cycle', $q); + break; + } + + $this->assertTrue($found, '未找到 status=active 的快捷筛选链接用于断言'); } }