diff --git a/tests/Feature/AdminPlatformOrderIndexScopeAllToolFormsShouldNotCarryFiltersTest.php b/tests/Feature/AdminPlatformOrderIndexScopeAllToolFormsShouldNotCarryFiltersTest.php index 6536cfa..76ebe5b 100644 --- a/tests/Feature/AdminPlatformOrderIndexScopeAllToolFormsShouldNotCarryFiltersTest.php +++ b/tests/Feature/AdminPlatformOrderIndexScopeAllToolFormsShouldNotCarryFiltersTest.php @@ -19,7 +19,7 @@ class AdminPlatformOrderIndexScopeAllToolFormsShouldNotCarryFiltersTest extends ])->assertRedirect('/admin'); } - protected function assertScopeAllToolFormDoesNotCarryFilters(string $html, string $action): void + protected function assertScopeAllFormDoesNotCarryFilters(string $html, string $action): void { $pattern = sprintf( '/]*method="post"[^>]*action="%s"[^>]*>(.*?)<\\/form>/si', @@ -37,34 +37,30 @@ class AdminPlatformOrderIndexScopeAllToolFormsShouldNotCarryFiltersTest extends $checked++; - // scope=all 属于全量动作,不应承载“当前筛选集合”的字段,避免语义误导。 + // Guardrail:scope=all 属于“全量动作”,不应携带当前筛选字段,避免造成“看起来只处理当前筛选”的误导。 $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="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); } - 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(); - // 故意带很多筛选参数,确保如果 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'); - $page->assertOk(); + // 构造一个“筛选很复杂”的场景,确保如果页面上误透传筛选字段,测试能命中。 + $res = $this->get('/admin/platform-orders?status=pending&payment_status=paid&merchant_id=1&sync_status=unsynced&renewal_missing_subscription=1'); + $res->assertOk(); - $html = (string) $page->getContent(); + $html = (string) $res->getContent(); - $this->assertScopeAllToolFormDoesNotCarryFilters($html, '/admin/platform-orders/batch-activate-subscriptions'); - $this->assertScopeAllToolFormDoesNotCarryFilters($html, '/admin/platform-orders/batch-mark-paid-and-activate'); - $this->assertScopeAllToolFormDoesNotCarryFilters($html, '/admin/platform-orders/batch-mark-activated'); - $this->assertScopeAllToolFormDoesNotCarryFilters($html, '/admin/platform-orders/clear-sync-errors'); - $this->assertScopeAllToolFormDoesNotCarryFilters($html, '/admin/platform-orders/clear-bmpa-errors'); + $this->assertScopeAllFormDoesNotCarryFilters($html, '/admin/platform-orders/batch-activate-subscriptions'); + $this->assertScopeAllFormDoesNotCarryFilters($html, '/admin/platform-orders/batch-mark-paid-and-activate'); + $this->assertScopeAllFormDoesNotCarryFilters($html, '/admin/platform-orders/batch-mark-activated'); + $this->assertScopeAllFormDoesNotCarryFilters($html, '/admin/platform-orders/clear-sync-errors'); + $this->assertScopeAllFormDoesNotCarryFilters($html, '/admin/platform-orders/clear-bmpa-errors'); } }