套餐:快捷筛选护栏测试升级(不依赖 query 顺序,断言仅保留 back/keyword)
This commit is contained in:
@@ -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 的快捷筛选链接用于断言');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user