From ca9d598ca3184fbb50cefc65a7bfd2c72ce42065 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=90=9D=E5=8D=9C?= Date: Sat, 14 Mar 2026 00:25:11 +0000 Subject: [PATCH] =?UTF-8?q?test:=20=E5=90=8C=E6=AD=A5=E8=AE=A2=E9=98=85?= =?UTF-8?q?=E6=B2=BB=E7=90=86=E6=8F=90=E7=A4=BA=E5=9D=97=E8=A6=86=E7=9B=96?= =?UTF-8?q?=20refund=5Finconsistent=20=E5=9C=BA=E6=99=AF=E5=B9=B6=E5=8A=A0?= =?UTF-8?q?=E4=B8=A5=E9=93=BE=E6=8E=A5=E6=96=AD=E8=A8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...ttonDisabledWhenGovernanceMismatchTest.php | 82 ++++++++++++++++++- 1 file changed, 81 insertions(+), 1 deletion(-) diff --git a/tests/Feature/AdminPlatformOrderShowActivateSubscriptionButtonDisabledWhenGovernanceMismatchTest.php b/tests/Feature/AdminPlatformOrderShowActivateSubscriptionButtonDisabledWhenGovernanceMismatchTest.php index 3a7a24f..e26e94f 100644 --- a/tests/Feature/AdminPlatformOrderShowActivateSubscriptionButtonDisabledWhenGovernanceMismatchTest.php +++ b/tests/Feature/AdminPlatformOrderShowActivateSubscriptionButtonDisabledWhenGovernanceMismatchTest.php @@ -78,7 +78,87 @@ class AdminPlatformOrderShowActivateSubscriptionButtonDisabledWhenGovernanceMism $res->assertSee('同步订阅治理提示', false); $res->assertSee('去补回执', false); - $res->assertSee('href="/admin/platform-orders/' . $order->id, false); // should include a link back to this page + anchor $res->assertSee('disabled', false); + + $html = (string) $res->getContent(); + preg_match_all('/href="([^"]+)"/', $html, $m); + $hrefs = $m[1] ?? []; + + $links = array_values(array_filter($hrefs, fn ($u) => str_starts_with($u, '/admin/platform-orders/' . $order->id) && str_contains($u, '#add-payment-receipt'))); + $this->assertGreaterThanOrEqual(1, count($links), '未找到指向 #add-payment-receipt 的治理链接'); + + $parts = parse_url($links[0]); + $this->assertSame('/admin/platform-orders/' . $order->id, $parts['path'] ?? ''); + $this->assertSame('add-payment-receipt', $parts['fragment'] ?? ''); + } + + public function test_activate_subscription_button_should_be_disabled_and_show_governance_block_when_refund_inconsistent(): void + { + $this->loginAsPlatformAdmin(); + + $merchant = Merchant::query()->firstOrFail(); + $plan = Plan::query()->create([ + 'code' => 'po_show_disable_sync_refund_inconsistent_plan', + 'name' => '同步订阅禁用-退款不一致测试套餐', + 'billing_cycle' => 'monthly', + 'price' => 10, + 'list_price' => 10, + 'status' => 'active', + 'sort' => 10, + 'published_at' => now(), + ]); + + // 已支付+已生效,且 payment_status!=refunded,但退款总额 >= 已付 + 容差 => refund_inconsistent=true + $order = PlatformOrder::query()->create([ + 'merchant_id' => $merchant->id, + 'plan_id' => $plan->id, + 'order_no' => 'PO_SHOW_DISABLE_SYNC_REFUND_INCONS_0001', + 'order_type' => 'new_purchase', + 'status' => 'activated', + 'payment_status' => 'paid', + 'plan_name' => $plan->name, + 'billing_cycle' => $plan->billing_cycle, + 'period_months' => 1, + 'quantity' => 1, + 'payable_amount' => 10, + 'paid_amount' => 10, + 'placed_at' => now(), + 'paid_at' => now(), + 'activated_at' => now(), + 'meta' => [ + 'refund_summary' => [ + 'count' => 1, + 'total_amount' => 10.01, + ], + 'refund_receipts' => [ + [ + 'type' => 'refund', + 'channel' => 'offline', + 'amount' => 10.01, + 'refunded_at' => now()->toDateTimeString(), + 'created_at' => now()->toDateTimeString(), + 'admin_id' => 1, + ], + ], + ], + ]); + + $res = $this->get('/admin/platform-orders/' . $order->id); + $res->assertOk(); + + $res->assertSee('同步订阅治理提示', false); + $res->assertSee('去核对退款', false); + $res->assertSee('disabled', false); + + $html = (string) $res->getContent(); + preg_match_all('/href="([^"]+)"/', $html, $m); + $hrefs = $m[1] ?? []; + + $links = array_values(array_filter($hrefs, fn ($u) => str_starts_with($u, '/admin/platform-orders/' . $order->id) && str_contains($u, '#refund-receipts'))); + $this->assertGreaterThanOrEqual(1, count($links), '未找到指向 #refund-receipts 的治理链接'); + + $parts = parse_url($links[0]); + $this->assertSame('/admin/platform-orders/' . $order->id, $parts['path'] ?? ''); + $this->assertSame('refund-receipts', $parts['fragment'] ?? ''); } }