Files
saasshop/tests/Feature/AdminPlatformOrderIndexBatchBmpaButtonShouldDisableWhenNotPendingUnpaidTest.php

73 lines
2.5 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\Merchant;
use App\Models\Plan;
use App\Models\PlatformOrder;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class AdminPlatformOrderIndexBatchBmpaButtonShouldDisableWhenNotPendingUnpaidTest 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_batch_bmpa_button_should_disable_when_filters_not_pending_unpaid(): void
{
$this->loginAsPlatformAdmin();
$merchant = Merchant::query()->firstOrFail();
$plan = Plan::query()->create([
'code' => 'po_index_batch_bmpa_btn_disable_plan',
'name' => '批量BMPA按钮禁用测试套餐',
'billing_cycle' => 'monthly',
'price' => 10,
'list_price' => 10,
'status' => 'active',
'sort' => 10,
'published_at' => now(),
]);
PlatformOrder::query()->create([
'merchant_id' => $merchant->id,
'plan_id' => $plan->id,
'order_no' => 'PO_IDX_BATCH_BMPA_BTN_DISABLE_0001',
'order_type' => 'new_purchase',
'status' => 'activated',
'payment_status' => 'paid',
'plan_name' => $plan->name,
'billing_cycle' => $plan->billing_cycle,
'period_months' => 1,
'quantity' => 1,
'payable_amount' => 10,
'paid_amount' => 10,
'placed_at' => now(),
'meta' => [],
]);
// 当前筛选口径不为 pending+unpaid前端按钮应禁用并提示原因后端也会阻断双保险
$res = $this->get('/admin/platform-orders?status=activated&payment_status=paid');
$res->assertOk();
$html = (string) $res->getContent();
$this->assertStringContainsString('批量标记支付并生效(含订阅同步)(当前筛选范围)', $html);
$this->assertStringContainsString('data-role="batch-bmpa-blocked-hint"', $html);
$this->assertStringContainsString('待处理', $html);
$this->assertStringContainsString('未支付', $html);
// 按钮 disabled用宽松断言避免受 HTML 格式影响)
$this->assertTrue(str_contains($html, 'type="submit" disabled') || str_contains($html, 'disabled="disabled"'));
}
}