Files
saasshop/tests/Feature/AdminPlatformBatchShowPageTopReasonTooLongShouldNotRenderGovernanceLinkTest.php
2026-03-20 08:39:08 +08:00

128 lines
4.7 KiB
PHP

<?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 AdminPlatformBatchShowPageTopReasonTooLongShouldNotRenderGovernanceLinkTest 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_show_page_should_not_render_top_reason_governance_link_when_reason_too_long(): void
{
$this->loginAsPlatformAdmin();
$merchant = Merchant::query()->firstOrFail();
$plan = Plan::query()->create([
'code' => 'plan_batch_show_long_reason_0001',
'name' => '批次页长原因护栏测试套餐',
'billing_cycle' => 'monthly',
'price' => 10,
'list_price' => 10,
'status' => 'active',
'sort' => 10,
'published_at' => now(),
]);
$longReasonBas = str_repeat('B', 260);
$longReasonBmpa = str_repeat('P', 260);
PlatformOrder::query()->create([
'merchant_id' => $merchant->id,
'plan_id' => $plan->id,
'order_no' => 'PO_BATCH_SHOW_LONG_REASON_BAS_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()->subMinutes(10),
'paid_at' => now()->subMinutes(9),
'activated_at' => now()->subMinutes(8),
'meta' => [
'batch_activation' => [
'run_id' => 'BAS_LONG_REASON_0001',
'last_result' => [
'run_id' => 'BAS_LONG_REASON_0001',
'success' => 1,
'failed' => 1,
'matched' => 2,
'processed' => 2,
'top_reasons' => [
['reason' => $longReasonBas, 'count' => 1],
],
'at' => now()->toDateTimeString(),
],
],
],
]);
PlatformOrder::query()->create([
'merchant_id' => $merchant->id,
'plan_id' => $plan->id,
'order_no' => 'PO_BATCH_SHOW_LONG_REASON_BMPA_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()->subMinutes(7),
'paid_at' => now()->subMinutes(6),
'activated_at' => now()->subMinutes(5),
'meta' => [
'batch_mark_paid_and_activate' => [
'run_id' => 'BMPA_LONG_REASON_0001',
'last_result' => [
'run_id' => 'BMPA_LONG_REASON_0001',
'success' => 1,
'failed' => 1,
'matched' => 2,
'processed' => 2,
'top_reasons' => [
['reason' => $longReasonBmpa, 'count' => 1],
],
'at' => now()->toDateTimeString(),
],
],
],
]);
$basHtml = $this->get('/admin/platform-batches/show?type=bas&run_id=BAS_LONG_REASON_0001')
->assertOk()
->getContent();
$bmpaHtml = $this->get('/admin/platform-batches/show?type=bmpa&run_id=BMPA_LONG_REASON_0001')
->assertOk()
->getContent();
$this->assertStringNotContainsString('sync_error_keyword=', $basHtml);
$this->assertStringContainsString('原因过长,请复制到列表页筛选框', $basHtml);
$this->assertStringNotContainsString('data-role="batch-top-reason-link"', $basHtml);
$this->assertStringNotContainsString('bmpa_error_keyword=', $bmpaHtml);
$this->assertStringContainsString('原因过长,请复制到列表页筛选框', $bmpaHtml);
$this->assertStringNotContainsString('data-role="batch-top-reason-link"', $bmpaHtml);
}
}