Skip to content

Commit 4d1a814

Browse files
committed
Add more query string tests
1 parent 7237d87 commit 4d1a814

File tree

1 file changed

+75
-1
lines changed

1 file changed

+75
-1
lines changed

tests/Unit/Macros/LocalizedUrlMacroTest.php

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ public function it_generates_non_absolute_urls_for_non_existing_routes()
565565
}
566566

567567
/** @test */
568-
public function it_returns_a_url_with_query_string()
568+
public function it_returns_a_url_with_query_string_for_existing_non_localized_unnamed_routes()
569569
{
570570
$this->setSupportedLocales(['en', 'nl']);
571571

@@ -586,6 +586,80 @@ public function it_returns_a_url_with_query_string()
586586
], $response->original);
587587
}
588588

589+
/** @test */
590+
public function it_returns_a_url_with_query_string_for_existing_localized_unnamed_routes()
591+
{
592+
$this->setSupportedLocales(['en', 'nl']);
593+
$this->setUseLocaleMiddleware(true);
594+
$this->setAppLocale('en');
595+
596+
Route::localized(function () {
597+
Route::get('route', function () {
598+
return [
599+
'current' => Route::localizedUrl(),
600+
'en' => Route::localizedUrl('en'),
601+
'nl' => Route::localizedUrl('nl'),
602+
];
603+
});
604+
});
605+
606+
$response = $this->call('GET', '/nl/route?another=one&param=value');
607+
$response->assertOk();
608+
$this->assertEquals([
609+
'current' => url('/nl/route?another=one&param=value'),
610+
'en' => url('/en/route?another=one&param=value'),
611+
'nl' => url('/nl/route?another=one&param=value'),
612+
], $response->original);
613+
}
614+
615+
/** @test */
616+
public function it_returns_a_url_with_query_string_for_existing_non_localized_named_routes()
617+
{
618+
$this->setSupportedLocales(['en', 'nl']);
619+
620+
Route::get('route', function () {
621+
return [
622+
'current' => Route::localizedUrl(),
623+
'en' => Route::localizedUrl('en'),
624+
'nl' => Route::localizedUrl('nl'),
625+
];
626+
})->name('route');
627+
628+
$response = $this->call('GET', '/route?another=one&param=value');
629+
$response->assertOk();
630+
$this->assertEquals([
631+
'current' => url('/route?another=one&param=value'),
632+
'en' => url('/route?another=one&param=value'),
633+
'nl' => url('/route?another=one&param=value'),
634+
], $response->original);
635+
}
636+
637+
/** @test */
638+
public function it_returns_a_url_with_query_string_for_existing_localized_named_routes()
639+
{
640+
$this->setSupportedLocales(['en', 'nl']);
641+
$this->setUseLocaleMiddleware(true);
642+
$this->setAppLocale('en');
643+
644+
Route::localized(function () {
645+
Route::get('route', function () {
646+
return [
647+
'current' => Route::localizedUrl(),
648+
'en' => Route::localizedUrl('en'),
649+
'nl' => Route::localizedUrl('nl'),
650+
];
651+
})->name('route');
652+
});
653+
654+
$response = $this->call('GET', '/nl/route?another=one&param=value');
655+
$response->assertOk();
656+
$this->assertEquals([
657+
'current' => url('/nl/route?another=one&param=value'),
658+
'en' => url('/en/route?another=one&param=value'),
659+
'nl' => url('/nl/route?another=one&param=value'),
660+
], $response->original);
661+
}
662+
589663
/**
590664
* Set a custom view path so Laravel will find our custom 440 error view.
591665
*

0 commit comments

Comments
 (0)