From 4947074142993d106b03472e9e50933f64350c2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=90=9D=E5=8D=9C?= Date: Fri, 13 Mar 2026 21:31:30 +0000 Subject: [PATCH] test: export ledger link assertion parse href query --- .../AdminPlatformOrderExportLedgerTest.php | 31 +++++++++++++++++-- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/tests/Feature/AdminPlatformOrderExportLedgerTest.php b/tests/Feature/AdminPlatformOrderExportLedgerTest.php index ed820dd..d78fd6a 100644 --- a/tests/Feature/AdminPlatformOrderExportLedgerTest.php +++ b/tests/Feature/AdminPlatformOrderExportLedgerTest.php @@ -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);