Files
saasshop/tests/Feature/AdminPlanIndexSetStatusAndPublishedFormsShouldDisableOnSubmitTest.php

51 lines
1.5 KiB
PHP

<?php
namespace Tests\Feature;
use App\Models\Plan;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class AdminPlanIndexSetStatusAndPublishedFormsShouldDisableOnSubmitTest 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_plans_index_inline_forms_should_disable_on_submit(): void
{
$this->loginAsPlatformAdmin();
Plan::query()->create([
'code' => 'plan_inline_disable_submit_01',
'name' => '套餐行内表单禁用提交测试',
'billing_cycle' => 'monthly',
'price' => 9.9,
'list_price' => 9.9,
'status' => 'active',
'sort' => 1,
'published_at' => now(),
]);
$res = $this->get('/admin/plans');
$res->assertOk();
$html = (string) $res->getContent();
$this->assertStringContainsString('data-role="plan-set-status"', $html);
$this->assertStringContainsString('data-role="plan-set-published"', $html);
// 两个表单都应启用 disable-on-submit 机制,避免重复提交。
$this->assertStringContainsString('action="/admin/plans/', $html);
$this->assertStringContainsString('data-action="disable-on-submit"', $html);
}
}