Files
saasshop/tests/Feature/AdminPlatformOrderShowBackSafetyValveRejectsNestedBackTest.php

77 lines
2.3 KiB
PHP

<?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 AdminPlatformOrderShowBackSafetyValveRejectsNestedBackTest 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_show_should_not_render_back_link_when_back_contains_nested_back(): void
{
$this->loginAsPlatformAdmin();
$merchant = Merchant::query()->firstOrFail();
$plan = Plan::query()->create([
'code' => 'show_back_nested_plan',
'name' => '订单详情back嵌套测试套餐',
'billing_cycle' => 'monthly',
'price' => 10,
'list_price' => 10,
'status' => 'active',
'sort' => 10,
'published_at' => now(),
]);
$order = PlatformOrder::query()->create([
'merchant_id' => $merchant->id,
'plan_id' => $plan->id,
'site_subscription_id' => null,
'created_by_admin_id' => 1,
'order_no' => 'PO_SHOW_BACK_NESTED_0001',
'order_type' => 'new_purchase',
'status' => 'pending',
'payment_status' => 'unpaid',
'payment_channel' => null,
'plan_name' => $plan->name,
'billing_cycle' => $plan->billing_cycle,
'period_months' => 1,
'quantity' => 1,
'list_amount' => 10,
'discount_amount' => 0,
'payable_amount' => 10,
'paid_amount' => 0,
'placed_at' => now(),
'plan_snapshot' => ['plan_id' => $plan->id],
'meta' => [],
'remark' => 'test',
]);
$nestedBack = '/admin/platform-orders?back=' . urlencode('/admin');
$res = $this->get('/admin/platform-orders/' . $order->id . '?' . Arr::query([
'back' => $nestedBack,
]));
$res->assertOk();
$res->assertDontSee('返回上一页(保留上下文)', false);
}
}