<?php

namespace Tests\Feature;

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

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

        // 给 dashboard 带一个安全 back，模拟从其它页面回到 dashboard 后再点治理入口
        // 注意：dashboard 链接的 back 口径已统一为 selfWithoutBack（即返回 /admin），不沿用 incoming back。
        $res = $this->get('/admin?back=' . urlencode('/admin/plans'));
        $res->assertOk();

        // 期望：链接里带 back=%2Fadmin（返回仪表盘）且 & 不被 escape 成 &amp;
        $res->assertSee('href="/admin/platform-orders?bmpa_processable_only=1&back=%2Fadmin"', false);
        $res->assertSee('href="/admin/platform-orders?payment_status=paid&status=pending&sync_status=unsynced&back=%2Fadmin"', false);
        $res->assertSee('href="/admin/platform-orders?syncable_only=1&sync_status=unsynced&back=%2Fadmin"', false);
        $res->assertSee('href="/admin/platform-orders?sync_status=failed&back=%2Fadmin"', false);

        $res->assertDontSee('&amp;back=', false);
    }
}
