diff --git a/tests/Feature/AdminSiteSubscriptionShowIndexLinkKeepsContextTest.php b/tests/Feature/AdminSiteSubscriptionShowIndexLinkKeepsContextTest.php index 24f75e3..4598864 100644 --- a/tests/Feature/AdminSiteSubscriptionShowIndexLinkKeepsContextTest.php +++ b/tests/Feature/AdminSiteSubscriptionShowIndexLinkKeepsContextTest.php @@ -75,4 +75,51 @@ class AdminSiteSubscriptionShowIndexLinkKeepsContextTest extends TestCase $res2->assertSee('返回上一页(保留上下文)'); $res2->assertDontSee('返回订阅列表(保留上下文)'); } + + public function test_show_page_should_fall_back_to_subscription_index_link_with_self_back_when_back_is_unsafe(): void + { + $this->loginAsPlatformAdmin(); + + $merchant = Merchant::query()->firstOrFail(); + + $plan = Plan::query()->create([ + 'code' => 'sub_show_index_link_unsafe_back_test', + 'name' => '订阅详情 unsafe back 兜底返回测试套餐', + 'billing_cycle' => 'monthly', + 'price' => 20, + 'list_price' => 20, + 'status' => 'active', + 'sort' => 10, + 'published_at' => now(), + ]); + + $sub = SiteSubscription::query()->create([ + 'merchant_id' => $merchant->id, + 'plan_id' => $plan->id, + 'status' => 'activated', + 'source' => 'manual', + 'subscription_no' => 'SUB_SHOW_INDEX_LINK_UNSAFE_BACK_0001', + 'plan_name' => $plan->name, + 'billing_cycle' => $plan->billing_cycle, + 'period_months' => 1, + 'amount' => 20, + 'starts_at' => now()->subDay(), + 'ends_at' => now()->addMonth(), + 'activated_at' => now()->subDay(), + ]); + + $unsafeBack = '/admin/site-subscriptions?status=active&back=/admin/platform-orders'; + + $res = $this->get('/admin/site-subscriptions/' . $sub->id . '?back=' . urlencode($unsafeBack)); + $res->assertOk(); + + $expectedIndexUrl = '/admin/site-subscriptions?' . Arr::query([ + 'back' => '/admin/site-subscriptions/' . $sub->id, + ]); + + $res->assertDontSee('返回上一页(保留上下文)'); + $res->assertSee('返回订阅列表(保留上下文)'); + $res->assertSee($expectedIndexUrl, false); + $res->assertDontSee('back=' . $unsafeBack, false); + } }