feat: plans index add create order quick link
This commit is contained in:
@@ -176,8 +176,16 @@
|
|||||||
<td>
|
<td>
|
||||||
@php
|
@php
|
||||||
$editPlanUrl = '/admin/plans/' . $plan->id . '/edit?' . \Illuminate\Support\Arr::query(['back' => $selfWithoutBack]);
|
$editPlanUrl = '/admin/plans/' . $plan->id . '/edit?' . \Illuminate\Support\Arr::query(['back' => $selfWithoutBack]);
|
||||||
|
$createOrderUrl = '/admin/platform-orders/create?' . \Illuminate\Support\Arr::query([
|
||||||
|
'plan_id' => $plan->id,
|
||||||
|
'order_type' => 'new_purchase',
|
||||||
|
'back' => $selfWithoutBack,
|
||||||
|
]);
|
||||||
@endphp
|
@endphp
|
||||||
<a href="{!! $editPlanUrl !!}" class="link">编辑</a>
|
<div style="display:flex; gap:10px; flex-wrap:wrap;">
|
||||||
|
<a href="{!! $editPlanUrl !!}" class="link">编辑</a>
|
||||||
|
<a href="{!! $createOrderUrl !!}" class="link">创建订单</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
<form method="post" action="/admin/plans/{{ $plan->id }}/set-status" style="margin-top:6px;">
|
<form method="post" action="/admin/plans/{{ $plan->id }}/set-status" style="margin-top:6px;">
|
||||||
@csrf
|
@csrf
|
||||||
|
|||||||
66
tests/Feature/AdminPlanIndexCreateOrderLinkTest.php
Normal file
66
tests/Feature/AdminPlanIndexCreateOrderLinkTest.php
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
<?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);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user