fix(backurl): avoid duplicating back query when already present
This commit is contained in:
27
tests/Unit/BackUrlWithBackNoDuplicateTest.php
Normal file
27
tests/Unit/BackUrlWithBackNoDuplicateTest.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?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='));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user