Files
saasshop/tests/Feature/AdminPlanIndexCreateOrderLinkTest.php
2026-03-13 22:09:04 +00:00

67 lines
1.9 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
namespace Tests\Feature;
use App\Models\Plan;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Arr;
use Tests\TestCase;
class AdminPlanIndexCreateOrderLinkTest 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_plan_index_should_render_create_order_link_with_plan_id_and_back(): void
{
$this->loginAsPlatformAdmin();
$plan = Plan::query()->create([
'code' => 'plan_create_order_link_test',
'name' => '套餐创建订单链接测试',
'billing_cycle' => 'monthly',
'price' => 99,
'list_price' => 99,
'status' => 'active',
'sort' => 1,
'published_at' => now(),
]);
// 访问列表页时带 back模拟来自别处链接 back 应回到 selfWithoutBack去掉 back
$currentUrl = '/admin/plans?' . Arr::query([
'status' => 'active',
'billing_cycle' => 'monthly',
'back' => '/admin',
]);
$res = $this->get($currentUrl);
$res->assertOk();
$selfWithoutBack = '/admin/plans?' . Arr::query([
'status' => 'active',
'billing_cycle' => 'monthly',
]);
$expectedCreateUrl = '/admin/platform-orders/create?' . Arr::query([
'plan_id' => $plan->id,
'order_type' => 'new_purchase',
'back' => $selfWithoutBack,
]);
$res->assertSee($expectedCreateUrl, false);
$res->assertSee('创建订单', false);
// 防 back 嵌套
$res->assertDontSee('back%3D', false);
}
}