test: export ledger link assertion parse href query
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user