Files
saasshop/tests/Feature/AdminPlatformBatchShowPageRefreshLinkShouldUseBatchShowSelfBackWhenOuterBackSafeTest.php
2026-03-20 12:55:16 +08:00

101 lines
3.3 KiB
PHP

<?php
namespace Tests\Feature;
use App\Models\Merchant;
use App\Models\Plan;
use App\Models\PlatformOrder;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Arr;
use Tests\TestCase;
class AdminPlatformBatchShowPageRefreshLinkShouldUseBatchShowSelfBackWhenOuterBackSafeTest 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_refresh_link_should_use_batch_show_self_back_when_outer_back_safe(): void
{
$this->loginAsPlatformAdmin();
$merchant = Merchant::query()->firstOrFail();
$plan = Plan::query()->create([
'code' => 'batch_show_refresh_safe_back_plan',
'name' => '批次详情刷新回链测试套餐',
'billing_cycle' => 'monthly',
'price' => 10,
'list_price' => 10,
'status' => 'active',
'sort' => 10,
'published_at' => now(),
]);
$runId = 'BAS_REFRESH_SAFE_BACK_0001';
PlatformOrder::query()->create([
'merchant_id' => $merchant->id,
'plan_id' => $plan->id,
'order_no' => 'PO_BATCH_REFRESH_SAFE_BACK_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' => $runId,
'last_result' => [
'run_id' => $runId,
'success' => 1,
'failed' => 0,
'matched' => 1,
'processed' => 1,
'top_reasons' => [],
'at' => now()->toDateTimeString(),
],
],
],
]);
$safeBack = '/admin/platform-orders?' . Arr::query([
'status' => 'pending',
'keyword' => '批次刷新',
]);
$res = $this->get('/admin/platform-batches/show?type=bas&run_id=' . $runId . '&back=' . urlencode($safeBack));
$res->assertOk();
$batchShowSelf = '/admin/platform-batches/show?' . Arr::query([
'type' => 'bas',
'run_id' => $runId,
]);
$expectedRefreshUrl = '/admin/platform-batches/show?' . Arr::query([
'type' => 'bas',
'run_id' => $runId,
'back' => $batchShowSelf,
]);
$res->assertSee(str_replace('&', '&amp;', $safeBack), false);
$res->assertSee('返回上一页');
$res->assertSee($expectedRefreshUrl, false);
$res->assertDontSee('run_id=' . $runId . '&back=' . $safeBack, false);
$res->assertDontSee('back%3D', false);
}
}