test(platform-orders): guardrail scope=all tool forms should not carry filters

This commit is contained in:
萝卜
2026-03-17 09:58:55 +08:00
parent 9873b1efff
commit 54521e5f24

View File

@@ -19,7 +19,7 @@ class AdminPlatformOrderIndexScopeAllToolFormsShouldNotCarryFiltersTest extends
])->assertRedirect('/admin'); ])->assertRedirect('/admin');
} }
protected function assertScopeAllToolFormDoesNotCarryFilters(string $html, string $action): void protected function assertScopeAllFormDoesNotCarryFilters(string $html, string $action): void
{ {
$pattern = sprintf( $pattern = sprintf(
'/<form[^>]*method="post"[^>]*action="%s"[^>]*>(.*?)<\\/form>/si', '/<form[^>]*method="post"[^>]*action="%s"[^>]*>(.*?)<\\/form>/si',
@@ -37,34 +37,30 @@ class AdminPlatformOrderIndexScopeAllToolFormsShouldNotCarryFiltersTest extends
$checked++; $checked++;
// scope=all 属于全量动作,不应承载“当前筛选集合”的字段,避免语义误导。 // Guardrailscope=all 属于全量动作,不应携带当前筛选字段,避免造成“看起来只处理当前筛选”的误导。
$this->assertStringNotContainsString('name="status"', $formHtml, 'scope=all 表单不应透传 status' . $action); $this->assertStringNotContainsString('name="status"', $formHtml, 'scope=all 表单不应透传 status' . $action);
$this->assertStringNotContainsString('name="payment_status"', $formHtml, 'scope=all 表单不应透传 payment_status' . $action); $this->assertStringNotContainsString('name="merchant_id"', $formHtml, 'scope=all 表单不应透传 merchant_id' . $action);
$this->assertStringNotContainsString('name="sync_status"', $formHtml, 'scope=all 表单不应透传 sync_status' . $action); $this->assertStringNotContainsString('name="sync_status"', $formHtml, 'scope=all 表单不应透传 sync_status' . $action);
$this->assertStringNotContainsString('name="renewal_missing_subscription"', $formHtml, 'scope=all 表单不应透传 renewal_missing_subscription' . $action); $this->assertStringNotContainsString('name="renewal_missing_subscription"', $formHtml, 'scope=all 表单不应透传 renewal_missing_subscription' . $action);
$this->assertStringNotContainsString('name="refund_status"', $formHtml, 'scope=all 表单不应透传 refund_status' . $action);
$this->assertStringNotContainsString('name="receipt_status"', $formHtml, 'scope=all 表单不应透传 receipt_status' . $action);
$this->assertStringNotContainsString('name="created_from"', $formHtml, 'scope=all 表单不应透传 created_from' . $action);
$this->assertStringNotContainsString('name="created_to"', $formHtml, 'scope=all 表单不应透传 created_to' . $action);
} }
$this->assertGreaterThan(0, $checked, '未找到 scope=all 的工具表单:' . $action); $this->assertGreaterThan(0, $checked, '未找到 scope=all 的工具表单:' . $action);
} }
public function test_platform_orders_index_scope_all_tool_forms_should_not_carry_filters(): void public function test_platform_orders_scope_all_tool_forms_should_not_carry_filters(): void
{ {
$this->loginAsPlatformAdmin(); $this->loginAsPlatformAdmin();
// 故意带很多筛选参数,确保如果 view 不小心透传,会被本用例抓住 // 构造一个“筛选很复杂”的场景,确保如果页面上误透传筛选字段,测试能命中
$page = $this->get('/admin/platform-orders?status=pending&payment_status=paid&sync_status=unsynced&receipt_status=none&refund_status=has&renewal_missing_subscription=1&created_from=2026-03-01&created_to=2026-03-17'); $res = $this->get('/admin/platform-orders?status=pending&payment_status=paid&merchant_id=1&sync_status=unsynced&renewal_missing_subscription=1');
$page->assertOk(); $res->assertOk();
$html = (string) $page->getContent(); $html = (string) $res->getContent();
$this->assertScopeAllToolFormDoesNotCarryFilters($html, '/admin/platform-orders/batch-activate-subscriptions'); $this->assertScopeAllFormDoesNotCarryFilters($html, '/admin/platform-orders/batch-activate-subscriptions');
$this->assertScopeAllToolFormDoesNotCarryFilters($html, '/admin/platform-orders/batch-mark-paid-and-activate'); $this->assertScopeAllFormDoesNotCarryFilters($html, '/admin/platform-orders/batch-mark-paid-and-activate');
$this->assertScopeAllToolFormDoesNotCarryFilters($html, '/admin/platform-orders/batch-mark-activated'); $this->assertScopeAllFormDoesNotCarryFilters($html, '/admin/platform-orders/batch-mark-activated');
$this->assertScopeAllToolFormDoesNotCarryFilters($html, '/admin/platform-orders/clear-sync-errors'); $this->assertScopeAllFormDoesNotCarryFilters($html, '/admin/platform-orders/clear-sync-errors');
$this->assertScopeAllToolFormDoesNotCarryFilters($html, '/admin/platform-orders/clear-bmpa-errors'); $this->assertScopeAllFormDoesNotCarryFilters($html, '/admin/platform-orders/clear-bmpa-errors');
} }
} }