test: export lead_id filter should be precise
This commit is contained in:
@@ -211,7 +211,7 @@ class AdminPlatformOrderExportTest extends TestCase
|
||||
|
||||
$this->get('/admin/platform-orders/export')
|
||||
->assertRedirect('/admin/login');
|
||||
}
|
||||
}
|
||||
|
||||
public function test_platform_admin_can_export_platform_orders_csv_with_lead_id_column(): void
|
||||
{
|
||||
@@ -255,6 +255,32 @@ class AdminPlatformOrderExportTest extends TestCase
|
||||
],
|
||||
]);
|
||||
|
||||
$otherLead = \App\Models\PlatformLead::query()->create([
|
||||
'name' => 'Lead Export Other',
|
||||
'mobile' => '13800000888',
|
||||
'company' => 'Other Inc',
|
||||
'status' => 'new',
|
||||
]);
|
||||
|
||||
PlatformOrder::query()->create([
|
||||
'merchant_id' => $merchant->id,
|
||||
'plan_id' => $plan->id,
|
||||
'order_no' => 'PO_EXPORT_LEAD_0002',
|
||||
'order_type' => 'new_purchase',
|
||||
'status' => 'pending',
|
||||
'payment_status' => 'unpaid',
|
||||
'plan_name' => $plan->name,
|
||||
'billing_cycle' => $plan->billing_cycle,
|
||||
'period_months' => 1,
|
||||
'quantity' => 1,
|
||||
'payable_amount' => 10,
|
||||
'paid_amount' => 0,
|
||||
'placed_at' => now(),
|
||||
'meta' => [
|
||||
'platform_lead_id' => $otherLead->id,
|
||||
],
|
||||
]);
|
||||
|
||||
$res = $this->get('/admin/platform-orders/export?download=1&lead_id=' . $lead->id);
|
||||
$res->assertOk();
|
||||
|
||||
@@ -262,6 +288,23 @@ class AdminPlatformOrderExportTest extends TestCase
|
||||
$this->assertStringContainsString('线索ID', $content);
|
||||
$this->assertStringContainsString('PO_EXPORT_LEAD_0001', $content);
|
||||
$this->assertStringContainsString((string) $lead->id, $content);
|
||||
|
||||
// lead_id 精确过滤:不应导出其它线索的订单
|
||||
$this->assertStringNotContainsString('PO_EXPORT_LEAD_0002', $content);
|
||||
|
||||
// 更稳健断言:逐行解析 CSV,确保“线索ID”列全部等于目标 lead_id
|
||||
$contentNoBom = ltrim($content, "\xEF\xBB\xBF");
|
||||
$lines = array_values(array_filter(preg_split("/\r\n|\n|\r/", $contentNoBom)));
|
||||
$this->assertGreaterThanOrEqual(2, count($lines));
|
||||
|
||||
$headers = str_getcsv($lines[0]);
|
||||
$leadIdx = array_search('线索ID', $headers, true);
|
||||
$this->assertNotFalse($leadIdx);
|
||||
|
||||
for ($i = 1; $i < count($lines); $i++) {
|
||||
$row = str_getcsv($lines[$i]);
|
||||
$this->assertSame((string) $lead->id, (string) ($row[$leadIdx] ?? ''));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user