<?php

namespace Tests\Unit;

use App\Support\BackUrl;
use Illuminate\Support\Arr;
use Tests\TestCase;

class BackUrlWithBackNoDuplicateTest extends TestCase
{
    public function test_with_back_should_not_duplicate_when_path_already_has_back_query(): void
    {
        $back = '/admin/platform-orders/2';

        $path = '/admin/site-subscriptions/2?' . Arr::query([
            'back' => $back,
            'order_sync_status' => 'syncable',
        ]);

        $url = BackUrl::withBack($path, $back);

        $this->assertSame($path, $url);

        // 防止重复 back= 出现两次
        $this->assertSame(1, substr_count($url, 'back='));
    }
}
