<?php

namespace Tests\Feature;

use Tests\TestCase;

class AdminDashboardRecentPlatformOrdersShouldNotUseDuplicateBackUrlWithBackAndFragmentCallsTest extends TestCase
{
    public function test_dashboard_recent_platform_orders_should_not_use_duplicate_back_url_with_back_and_fragment_calls(): void
    {
        $blade = (string) file_get_contents(resource_path('views/admin/dashboard.blade.php'));

        // 回归保护：recent orders 相关的锚点 URL 构建应收敛到上方统一变量定义，
        // 避免在下方提示块/扫描行里重复手写 withBackAndFragment（易回退/易漏改）。
        // 允许出现 1 次（用于变量定义处）。
        $this->assertSame(1, substr_count(
            $blade,
            "BackUrl::withBackAndFragment('/admin/platform-orders/' . \$po->id, \$selfWithoutBack, 'sync-failed')"
        ));

        $this->assertSame(1, substr_count(
            $blade,
            "BackUrl::withBackAndFragment('/admin/platform-orders/' . \$po->id, \$selfWithoutBack, 'bmpa-failed')"
        ));

        $this->assertSame(2, substr_count(
            $blade,
            "BackUrl::withBackAndFragment('/admin/platform-orders/' . \$po->id, \$selfWithoutBack, 'add-payment-receipt')"
        ));

        $this->assertSame(2, substr_count(
            $blade,
            "BackUrl::withBackAndFragment('/admin/platform-orders/' . \$po->id, \$selfWithoutBack, 'add-refund-receipt')"
        ));

        $this->assertSame(1, substr_count(
            $blade,
            "BackUrl::withBackAndFragment('/admin/platform-orders/' . \$po->id, \$selfWithoutBack, 'relation-subscription')"
        ));

        // 仍应存在变量引用（说明已收敛到统一变量）
        $this->assertStringContainsString('$scanGoSyncFailedUrl', $blade);
        $this->assertStringContainsString('$scanGoBmpaFailedUrl', $blade);
        $this->assertStringContainsString('$scanGoReconcileUrl', $blade);
        $this->assertStringContainsString('$scanGoRefundUrl', $blade);
        $this->assertStringContainsString('$scanGoRelationUrl', $blade);
        $this->assertStringContainsString('$fixRefundReceiptUrl', $blade);
    }
}
