补齐套餐详情页与订阅无回执治理入口测试

This commit is contained in:
萝卜
2026-03-20 07:45:29 +08:00
parent 50f73d2222
commit 7bd40a5527
7 changed files with 536 additions and 0 deletions

View File

@@ -0,0 +1,182 @@
<?php
namespace Tests\Feature;
use App\Models\Merchant;
use App\Models\Plan;
use App\Models\PlatformOrder;
use App\Models\SiteSubscription;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Arr;
use Tests\TestCase;
class AdminPlanShowTest 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_platform_admin_can_open_plan_show_page(): void
{
$this->loginAsPlatformAdmin();
$merchant = Merchant::query()->firstOrFail();
$plan = Plan::query()->create([
'code' => 'plan_show_test',
'name' => '套餐详情测试套餐',
'billing_cycle' => 'monthly',
'price' => 99,
'list_price' => 199,
'status' => 'active',
'sort' => 10,
'description' => '用于验证套餐详情页',
'published_at' => now(),
]);
$subscription = SiteSubscription::query()->create([
'merchant_id' => $merchant->id,
'plan_id' => $plan->id,
'status' => 'activated',
'source' => 'manual',
'subscription_no' => 'SUB_PLAN_SHOW_0001',
'plan_name' => $plan->name,
'billing_cycle' => $plan->billing_cycle,
'period_months' => 1,
'amount' => 99,
'starts_at' => now()->subDay(),
'ends_at' => now()->addDays(5),
'activated_at' => now()->subDay(),
]);
PlatformOrder::query()->create([
'merchant_id' => $merchant->id,
'plan_id' => $plan->id,
'site_subscription_id' => $subscription->id,
'order_no' => 'PO_PLAN_SHOW_0001',
'order_type' => 'renewal',
'status' => 'activated',
'payment_status' => 'paid',
'plan_name' => $plan->name,
'billing_cycle' => $plan->billing_cycle,
'period_months' => 1,
'quantity' => 1,
'list_amount' => 99,
'discount_amount' => 0,
'payable_amount' => 99,
'paid_amount' => 99,
'placed_at' => now()->subHour(),
'paid_at' => now()->subMinutes(50),
'activated_at' => now()->subMinutes(40),
'meta' => [],
]);
$res = $this->get('/admin/plans/' . $plan->id);
$res->assertOk()
->assertSee('套餐详情')
->assertSee('套餐详情测试套餐')
->assertSee('查看已付无回执订单')
->assertSee('查看续费缺订阅订单');
}
public function test_guest_cannot_open_plan_show_page(): void
{
$plan = Plan::query()->create([
'code' => 'plan_show_guest_test',
'name' => '游客不可见套餐',
'billing_cycle' => 'monthly',
'price' => 10,
'list_price' => 10,
'status' => 'active',
'sort' => 10,
]);
$this->get('/admin/plans/' . $plan->id)->assertRedirect('/admin/login');
}
public function test_plan_show_links_to_subscriptions_and_orders_should_contain_back_to_plan_show(): void
{
$this->loginAsPlatformAdmin();
$plan = Plan::query()->create([
'code' => 'plan_show_back_test',
'name' => '套餐详情 back 测试套餐',
'billing_cycle' => 'monthly',
'price' => 88,
'list_price' => 108,
'status' => 'active',
'sort' => 10,
'published_at' => now(),
]);
$res = $this->get('/admin/plans/' . $plan->id);
$res->assertOk();
$back = '/admin/plans/' . $plan->id;
$expectedSubscriptionUrl = '/admin/site-subscriptions?' . Arr::query([
'plan_id' => $plan->id,
'back' => $back,
]);
$expectedOrderUrl = '/admin/platform-orders?' . Arr::query([
'plan_id' => $plan->id,
'back' => $back,
]);
$expectedPaidNoReceiptUrl = '/admin/platform-orders?' . Arr::query([
'plan_id' => $plan->id,
'payment_status' => 'paid',
'receipt_status' => 'none',
'back' => $back,
]);
$expectedRenewalMissingUrl = '/admin/platform-orders?' . Arr::query([
'plan_id' => $plan->id,
'renewal_missing_subscription' => '1',
'back' => $back,
]);
$res->assertSee($expectedSubscriptionUrl, false);
$res->assertSee($expectedOrderUrl, false);
$res->assertSee($expectedPaidNoReceiptUrl, false);
$res->assertSee($expectedRenewalMissingUrl, false);
}
public function test_plan_index_show_link_should_carry_back_to_index_self_without_back(): void
{
$this->loginAsPlatformAdmin();
$plan = Plan::query()->create([
'code' => 'plan_index_show_link_test',
'name' => '套餐列表详情入口测试套餐',
'billing_cycle' => 'monthly',
'price' => 18,
'list_price' => 18,
'status' => 'active',
'sort' => 10,
]);
$res = $this->get('/admin/plans?status=active&back=' . urlencode('/admin/platform-orders'));
$res->assertOk();
$expectedBack = '/admin/plans?' . Arr::query([
'status' => 'active',
]);
$expectedShowUrl = '/admin/plans/' . $plan->id . '?' . Arr::query([
'back' => $expectedBack,
]);
$res->assertSee($expectedShowUrl, false);
$res->assertSee('查看详情');
}
}

View File

@@ -0,0 +1,74 @@
<?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 AdminSiteSubscriptionShowBroadNoReceiptOrdersLinkShouldUseSubscriptionShowSelfBackTest 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_broad_no_receipt_orders_link_should_use_subscription_show_self_as_back(): void
{
$this->loginAsPlatformAdmin();
$merchant = Merchant::query()->firstOrFail();
$plan = Plan::query()->create([
'code' => 'sub_show_broad_no_receipt_self_back_plan',
'name' => '订阅详情广义无回执回跳自环测试套餐',
'billing_cycle' => 'monthly',
'price' => 66,
'list_price' => 66,
'status' => 'active',
'sort' => 10,
'published_at' => now(),
]);
$subscription = SiteSubscription::query()->create([
'merchant_id' => $merchant->id,
'plan_id' => $plan->id,
'status' => 'active',
'source' => 'manual',
'subscription_no' => 'SS_SHOW_BNR_SELF_BACK_0001',
'plan_name' => $plan->name,
'billing_cycle' => $plan->billing_cycle,
'period_months' => 1,
'amount' => 66,
'starts_at' => now()->subDay(),
'ends_at' => now()->addMonth(),
]);
$res = $this->get('/admin/site-subscriptions/' . $subscription->id . '?back=' . urlencode('/admin/platform-orders?payment_status=paid'));
$res->assertOk();
$html = (string) $res->getContent();
$matched = preg_match('/无回执订单(广义):\s*<a[^>]+href="([^"]+)"/u', $html, $m);
$this->assertSame(1, $matched, '未找到订阅详情页“无回执订单(广义)”链接');
$href = html_entity_decode($m[1] ?? '');
$expectedUrl = '/admin/platform-orders?' . Arr::query([
'site_subscription_id' => $subscription->id,
'receipt_status' => 'none',
'back' => '/admin/site-subscriptions/' . $subscription->id,
]);
$this->assertSame($expectedUrl, $href);
$this->assertStringNotContainsString('payment_status=paid', $href);
$this->assertStringNotContainsString(urlencode('/admin/platform-orders?payment_status=paid'), $href);
}
}