补齐平台订单详情页查找订阅回链测试

This commit is contained in:
萝卜
2026-03-20 10:55:47 +08:00
parent 7ce509d7f6
commit 8e21ab6e46

View File

@@ -0,0 +1,80 @@
<?php
namespace Tests\Feature;
use App\Models\Merchant;
use App\Models\Plan;
use App\Models\PlatformOrder;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Arr;
use Tests\TestCase;
class AdminPlatformOrderShowFindSubscriptionLinkShouldUseOrderShowSelfBackWhenOuterBackSafeTest 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_find_subscription_link_should_still_use_order_show_self_back_and_attach_back_when_outer_back_is_safe(): void
{
$this->loginAsPlatformAdmin();
$merchant = Merchant::query()->firstOrFail();
$plan = Plan::query()->create([
'code' => 'po_show_find_sub_safe_back_plan',
'name' => '订单详情查找订阅 safe back 测试套餐',
'billing_cycle' => 'monthly',
'price' => 30,
'list_price' => 30,
'status' => 'active',
'sort' => 10,
'published_at' => now(),
]);
$order = PlatformOrder::query()->create([
'merchant_id' => $merchant->id,
'plan_id' => $plan->id,
'order_no' => 'PO_SHOW_FIND_SUB_SAFE_BACK_0001',
'order_type' => 'renewal',
'status' => 'pending',
'payment_status' => 'unpaid',
'plan_name' => $plan->name,
'billing_cycle' => $plan->billing_cycle,
'period_months' => 1,
'quantity' => 1,
'payable_amount' => 30,
'paid_amount' => 0,
'placed_at' => now(),
'meta' => [],
]);
$safeBack = '/admin/platform-orders?' . Arr::query([
'status' => 'pending',
'keyword' => '续费缺订阅',
]);
$res = $this->get('/admin/platform-orders/' . $order->id . '?back=' . urlencode($safeBack));
$res->assertOk();
$html = (string) $res->getContent();
$orderShowSelf = '/admin/platform-orders/' . $order->id;
$this->assertStringContainsString('href="' . $safeBack . '"', $html);
$this->assertStringContainsString('← 返回上一页(保留上下文)', $html);
$this->assertStringContainsString('/admin/site-subscriptions?', $html);
$this->assertStringContainsString('merchant_id=' . $merchant->id, $html);
$this->assertStringContainsString('plan_id=' . $plan->id, $html);
$this->assertStringContainsString('back=' . urlencode($orderShowSelf), $html);
$this->assertStringContainsString('attach_order_id=' . $order->id, $html);
$this->assertStringContainsString('attach_back=' . urlencode($orderShowSelf), $html);
$this->assertStringNotContainsString('back%3D', $html);
}
}