<?php

namespace Tests\Feature;

use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;

class AdminPlatformOrderCreateRequireSubscriptionFlagJumpBackShouldIncludeRequireSubscriptionTest 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_jump_to_subscriptions_link_should_carry_back_with_require_subscription_flag_when_no_query(): void
    {
        $this->loginAsPlatformAdmin();

        // 模拟“校验失败回填后”回到 create 页：URL 不带 require_subscription query，但 old input 仍有 require_subscription=1
        // 通过 withSession 注入 old input
        $res = $this->withSession([
            '_old_input' => [
                'require_subscription' => '1',
            ],
        ])->get('/admin/platform-orders/create');

        $res->assertOk();

        // 关键：跳转订阅管理的链接应带 back，且 back 中应包含 require_subscription=1
        // 这样用户从订阅管理选中订阅再回来，治理口径不会丢。
        $res->assertSee('去订阅管理选择订阅', false);
        $res->assertSee('back=%2Fadmin%2Fplatform-orders%2Fcreate%3Frequire_subscription%3D1', false);
    }
}
