订阅列表:订阅号链接用 Arr::query 统一 back 且避免嵌套

This commit is contained in:
萝卜
2026-03-13 20:07:00 +00:00
parent dca04f48b4
commit 6f3d293aaa
2 changed files with 78 additions and 1 deletions

View File

@@ -0,0 +1,72 @@
<?php
namespace Tests\Feature;
use App\Models\Merchant;
use App\Models\Plan;
use App\Models\SiteSubscription;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Arr;
use Tests\TestCase;
class AdminSiteSubscriptionIndexSubscriptionNoLinkContainsBackTest extends TestCase
{
use RefreshDatabase;
protected function loginAsPlatformAdmin(): void
{
$this->seed();
$this->post('/admin/login', [
'email' => 'platform.admin@demo.local',
'password' => 'Platform@123456',
])->assertRedirect('/admin');
}
public function test_subscription_no_link_should_carry_back_to_index_self_without_back(): void
{
$this->loginAsPlatformAdmin();
$merchant = Merchant::query()->firstOrFail();
$plan = Plan::query()->create([
'code' => 'sub_index_sub_no_back_plan',
'name' => '订阅列表订阅号 back 口径测试套餐',
'billing_cycle' => 'monthly',
'price' => 10,
'list_price' => 10,
'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_INDEX_BACK_0001',
'plan_name' => $plan->name,
'billing_cycle' => $plan->billing_cycle,
'period_months' => 1,
'amount' => 10,
'starts_at' => now()->subDay(),
'ends_at' => now()->addMonth(),
'activated_at' => now()->subDay(),
]);
// 列表页带 back模拟从其它页面跳回index 内 back 口径用 selfWithoutBack去掉 back
$res = $this->get('/admin/site-subscriptions?status=activated&back=' . urlencode('/admin/plans'));
$res->assertOk();
$expectedBack = '/admin/site-subscriptions?' . Arr::query([
'status' => 'activated',
]);
$expectedUrl = '/admin/site-subscriptions/' . $sub->id . '?' . Arr::query([
'back' => $expectedBack,
]);
$res->assertSee($expectedUrl, false);
$res->assertDontSee('back%3D', false);
}
}