test: export ledger link assertion parse href query

This commit is contained in:
萝卜
2026-03-13 21:31:30 +00:00
parent 9c700b2241
commit 4947074142

View File

@@ -154,9 +154,34 @@ class AdminPlatformOrderExportLedgerTest extends TestCase
$res = $this->get('/admin/platform-orders/' . $order->id);
$res->assertOk();
// 页面应包含两条导出链接注意Arr::query 可能调整 query 顺序,因此断言只锁定关键片段)
$res->assertSee('/admin/platform-orders/' . $order->id . '/export-ledger?download=1', false);
$res->assertSee('include_order_snapshot=1', false);
$html = $res->getContent();
// 页面应包含两条导出链接(解析 HTML按 query 键值断言,避免参数顺序导致脆弱)
preg_match_all('/href="([^"]+)"/', $html, $matches);
$hrefs = $matches[1] ?? [];
$exportUrls = array_values(array_filter($hrefs, fn ($u) => str_contains($u, '/admin/platform-orders/' . $order->id . '/export-ledger')));
$this->assertGreaterThanOrEqual(2, count($exportUrls));
$foundBase = false;
$foundWithSnapshot = false;
foreach ($exportUrls as $u) {
$parts = parse_url($u);
parse_str($parts['query'] ?? '', $q);
if (($q['download'] ?? null) === '1' && !isset($q['include_order_snapshot'])) {
$foundBase = true;
}
if (($q['download'] ?? null) === '1' && (string)($q['include_order_snapshot'] ?? '') === '1') {
$foundWithSnapshot = true;
}
}
$this->assertTrue($foundBase, '未找到 download=1 的基础导出链接');
$this->assertTrue($foundWithSnapshot, '未找到 download=1 且 include_order_snapshot=1 的导出链接');
$res->assertSee('导出对账明细CSV', false);
$res->assertSee('导出含订单摘要CSV', false);