feat(backurl): preserve existing fragment when appending back

This commit is contained in:
萝卜
2026-03-14 21:20:26 +00:00
parent 84e860e403
commit e854d94578
2 changed files with 56 additions and 5 deletions

View File

@@ -0,0 +1,40 @@
<?php
namespace Tests\Unit;
use App\Support\BackUrl;
use Illuminate\Support\Arr;
use Tests\TestCase;
class BackUrlWithBackFragmentTest extends TestCase
{
public function test_with_back_should_preserve_existing_fragment_when_safe(): void
{
$back = '/admin/platform-orders/2';
$backQuery = Arr::query(['back' => $back]);
$url = BackUrl::withBack('/admin/site-subscriptions/2#syncable-batch', $back);
$this->assertSame('/admin/site-subscriptions/2?' . $backQuery . '#syncable-batch', $url);
}
public function test_with_back_should_drop_existing_fragment_when_not_whitelisted(): void
{
$back = '/admin/platform-orders/2';
$backQuery = Arr::query(['back' => $back]);
$url = BackUrl::withBack('/admin/site-subscriptions/2#bad#frag', $back);
$this->assertSame('/admin/site-subscriptions/2?' . $backQuery, $url);
}
public function test_with_back_first_should_preserve_existing_fragment_when_safe(): void
{
$back = '/admin/platform-orders/2';
$backQuery = Arr::query(['back' => $back]);
$url = BackUrl::withBackFirst('/admin/site-subscriptions/2?order_sync_status=syncable#syncable-batch', $back);
$this->assertSame('/admin/site-subscriptions/2?' . $backQuery . '&order_sync_status=syncable#syncable-batch', $url);
}
}