From b89f5e4c40b811fd2dc49242428deefe16791dfc Mon Sep 17 00:00:00 2001 From: Ivan Vermeyen Date: Fri, 31 Mar 2023 21:04:03 +0200 Subject: [PATCH] Generate URs via URL facade instead of route() helper This makes it easier to to test without overriding Laravel's helpers. --- src/LocalizedUrlGenerator.php | 3 +- tests/Unit/HelpersFileTest.php | 15 +- .../Macros/Route/LocalizedUrlMacroTest.php | 189 +++++++++--------- tests/Unit/UrlGeneratorTest.php | 58 +++--- 4 files changed, 134 insertions(+), 131 deletions(-) diff --git a/src/LocalizedUrlGenerator.php b/src/LocalizedUrlGenerator.php index b88e3ae..0ae6302 100644 --- a/src/LocalizedUrlGenerator.php +++ b/src/LocalizedUrlGenerator.php @@ -4,6 +4,7 @@ use CodeZero\LocalizedRoutes\Facades\LocaleConfig; use CodeZero\UrlBuilder\UrlBuilder; +use Illuminate\Support\Facades\URL; use InvalidArgumentException; use Illuminate\Support\Collection; use Illuminate\Support\Facades\App; @@ -116,7 +117,7 @@ public function generateFromRequest(string $locale = null, $parameters = null, b protected function generateNamedRouteURL(string $locale, array $parameters = [], bool $absolute = true): string { try { - return route($this->route->getName(), $parameters, $absolute, $locale); + return URL::route($this->route->getName(), $parameters, $absolute, $locale); } catch (InvalidArgumentException $e) { return ''; } diff --git a/tests/Unit/HelpersFileTest.php b/tests/Unit/HelpersFileTest.php index 03d0f41..919afe2 100644 --- a/tests/Unit/HelpersFileTest.php +++ b/tests/Unit/HelpersFileTest.php @@ -4,6 +4,7 @@ use CodeZero\LocalizedRoutes\Tests\TestCase; use Illuminate\Support\Facades\Route; +use Illuminate\Support\Facades\URL; use Symfony\Component\Routing\Exception\RouteNotFoundException; class HelpersFileTest extends TestCase @@ -18,9 +19,9 @@ function it_returns_localized_routes_with_locale_argument(): void Route::get('route')->name('route'); }); - $this->assertEquals(url('en/route'), route('route', [], true, null)); - $this->assertEquals(url('en/route'), route('route', [], true, 'en')); - $this->assertEquals(url('nl/route'), route('route', [], true, 'nl')); + $this->assertEquals(URL::to('en/route'), URL::route('route', [], true, null)); + $this->assertEquals(URL::to('en/route'), URL::route('route', [], true, 'en')); + $this->assertEquals(URL::to('nl/route'), URL::route('route', [], true, 'nl')); } /** @test */ @@ -35,7 +36,7 @@ function it_throws_when_route_helper_locale_is_unsupported(): void $this->expectException(RouteNotFoundException::class); - route('route', [], true, 'wk'); + URL::route('route', [], true, 'wk'); } /** @test */ @@ -49,8 +50,8 @@ function it_uses_fallback_locale_when_route_helper_locale_is_unsupported(): void Route::get('route')->name('route'); }); - $this->assertEquals(url('en/route'), route('route', [], true, 'en')); - $this->assertEquals(url('nl/route'), route('route', [], true, 'nl')); - $this->assertEquals(url('en/route'), route('route', [], true, 'wk')); + $this->assertEquals(URL::to('en/route'), URL::route('route', [], true, 'en')); + $this->assertEquals(URL::to('nl/route'), URL::route('route', [], true, 'nl')); + $this->assertEquals(URL::to('en/route'), URL::route('route', [], true, 'wk')); } } diff --git a/tests/Unit/Macros/Route/LocalizedUrlMacroTest.php b/tests/Unit/Macros/Route/LocalizedUrlMacroTest.php index 1195d96..3a3869c 100644 --- a/tests/Unit/Macros/Route/LocalizedUrlMacroTest.php +++ b/tests/Unit/Macros/Route/LocalizedUrlMacroTest.php @@ -13,6 +13,7 @@ use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Lang; use Illuminate\Support\Facades\Route; +use Illuminate\Support\Facades\URL; use Illuminate\Support\Facades\View; class LocalizedUrlMacroTest extends TestCase @@ -45,9 +46,9 @@ public function it_generates_urls_with_default_localized_route_keys_for_the_curr $response = $this->call('GET', '/en/route/en-slug/en-slug'); $response->assertOk(); $this->assertEquals([ - 'current' => url('/en/route/en-slug/en-slug'), - 'en' => url('/en/route/en-slug/en-slug'), - 'nl' => url('/nl/route/nl-slug/nl-slug'), + 'current' => URL::to('/en/route/en-slug/en-slug'), + 'en' => URL::to('/en/route/en-slug/en-slug'), + 'nl' => URL::to('/nl/route/nl-slug/nl-slug'), ], $response->original); } @@ -87,9 +88,9 @@ public function it_generates_urls_for_the_current_route_with_different_models_us $response = $this->call('GET', '/en/route/en-slug-foo/en-slug-bar'); $response->assertOk(); $this->assertEquals([ - 'current' => url('/en/route/en-slug-foo/en-slug-bar'), - 'en' => url('/en/route/en-slug-foo/en-slug-bar'), - 'nl' => url('/nl/route/nl-slug-foo/nl-slug-bar'), + 'current' => URL::to('/en/route/en-slug-foo/en-slug-bar'), + 'en' => URL::to('/en/route/en-slug-foo/en-slug-bar'), + 'nl' => URL::to('/nl/route/nl-slug-foo/nl-slug-bar'), ], $response->original); } @@ -121,9 +122,9 @@ public function it_generates_urls_with_custom_localized_route_keys_for_the_curre $response = $this->call('GET', '/en/route/en-slug'); $response->assertOk(); $this->assertEquals([ - 'current' => url('/en/route/en-slug'), - 'en' => url('/en/route/en-slug'), - 'nl' => url('/nl/route/nl-slug'), + 'current' => URL::to('/en/route/en-slug'), + 'en' => URL::to('/en/route/en-slug'), + 'nl' => URL::to('/nl/route/nl-slug'), ], $response->original); } @@ -156,9 +157,9 @@ public function you_can_implement_an_interface_and_let_your_model_return_custom_ $response = $this->call('GET', '/en/route/1/en-slug'); $response->assertOk(); $this->assertEquals([ - 'current' => url('/en/route/1/en-slug'), - 'en' => url('/en/route/1/en-slug'), - 'nl' => url('/nl/route/1/nl-slug'), + 'current' => URL::to('/en/route/1/en-slug'), + 'en' => URL::to('/en/route/1/en-slug'), + 'nl' => URL::to('/nl/route/1/nl-slug'), ], $response->original); } @@ -190,9 +191,9 @@ public function it_cannot_guess_a_localized_route_key_without_route_model_bindin $response = $this->call('GET', '/en/route/en-slug'); $response->assertOk(); $this->assertEquals([ - 'current' => url('/en/route/en-slug'), - 'en' => url('/en/route/en-slug'), - 'nl' => url('/nl/route/en-slug'), // Wrong slug! + 'current' => URL::to('/en/route/en-slug'), + 'en' => URL::to('/en/route/en-slug'), + 'nl' => URL::to('/nl/route/en-slug'), // Wrong slug! ], $response->original); } @@ -224,9 +225,9 @@ public function you_can_pass_it_a_model_with_a_localized_route_key_without_route $response = $this->call('GET', '/en/route/en-slug'); $response->assertOk(); $this->assertEquals([ - 'current' => url('/en/route/en-slug'), - 'en' => url('/en/route/en-slug'), - 'nl' => url('/nl/route/nl-slug'), + 'current' => URL::to('/en/route/en-slug'), + 'en' => URL::to('/en/route/en-slug'), + 'nl' => URL::to('/nl/route/nl-slug'), ], $response->original); } @@ -263,9 +264,9 @@ public function you_can_pass_it_a_closure_that_returns_the_parameters_without_ro $response = $this->call('GET', '/en/route/1/en-slug'); $response->assertOk(); $this->assertEquals([ - 'current' => url('/en/route/1/en-slug'), - 'en' => url('/en/route/1/en-slug'), - 'nl' => url('/nl/route/1/nl-slug'), + 'current' => URL::to('/en/route/1/en-slug'), + 'en' => URL::to('/en/route/1/en-slug'), + 'nl' => URL::to('/nl/route/1/nl-slug'), ], $response->original); } @@ -293,17 +294,17 @@ public function it_handles_unnamed_non_localized_routes() $response = $this->call('GET', '/route/one'); $response->assertOk(); $this->assertEquals([ - 'current' => url('/route/one'), - 'en' => url('/route/one'), - 'nl' => url('/route/one'), + 'current' => URL::to('/route/one'), + 'en' => URL::to('/route/one'), + 'nl' => URL::to('/route/one'), ], $response->original); $response = $this->call('GET', '/route/two'); $response->assertOk(); $this->assertEquals([ - 'current' => url('/route/two'), - 'en' => url('/route/two'), - 'nl' => url('/route/two'), + 'current' => URL::to('/route/two'), + 'en' => URL::to('/route/two'), + 'nl' => URL::to('/route/two'), ], $response->original); } @@ -333,17 +334,17 @@ public function it_handles_unnamed_localized_routes() $response = $this->call('GET', '/en/route/one'); $response->assertOk(); $this->assertEquals([ - 'current' => url('/en/route/one'), - 'en' => url('/en/route/one'), - 'nl' => url('/nl/route/one'), + 'current' => URL::to('/en/route/one'), + 'en' => URL::to('/en/route/one'), + 'nl' => URL::to('/nl/route/one'), ], $response->original); $response = $this->call('GET', '/en/route/two'); $response->assertOk(); $this->assertEquals([ - 'current' => url('/en/route/two'), - 'en' => url('/en/route/two'), - 'nl' => url('/nl/route/two'), + 'current' => URL::to('/en/route/two'), + 'en' => URL::to('/en/route/two'), + 'nl' => URL::to('/nl/route/two'), ], $response->original); } @@ -364,9 +365,9 @@ public function it_returns_the_current_url_for_existing_non_localized_routes() $response = $this->call('GET', '/non/localized/route'); $response->assertOk(); $this->assertEquals([ - 'current' => url('/non/localized/route'), - 'en' => url('/non/localized/route'), - 'nl' => url('/non/localized/route'), + 'current' => URL::to('/non/localized/route'), + 'en' => URL::to('/non/localized/route'), + 'nl' => URL::to('/non/localized/route'), ], $response->original); } @@ -393,9 +394,9 @@ public function it_returns_the_url_for_existing_unnamed_localized_routes_using_c $response = $this->call('GET', '/english'); $response->assertOk(); $this->assertEquals([ - 'current' => url('/english'), - 'en' => url('/english'), - 'nl' => url('/dutch'), + 'current' => URL::to('/english'), + 'en' => URL::to('/english'), + 'nl' => URL::to('/dutch'), ], $response->original); } @@ -422,9 +423,9 @@ public function it_returns_the_url_for_existing_named_localized_routes_using_cus $response = $this->call('GET', '/english'); $response->assertOk(); $this->assertEquals([ - 'current' => url('/english'), - 'en' => url('/english'), - 'nl' => url('/dutch'), + 'current' => URL::to('/english'), + 'en' => URL::to('/english'), + 'nl' => URL::to('/dutch'), ], $response->original); } @@ -516,7 +517,7 @@ public function a_404_receives_the_correct_localized_url_from_a_view_composer() $response = $this->get('/nl/route/does/not/exist'); $response->assertNotFound(); $response->assertResponseHasNoView(); - $this->assertEquals(url('/nl/route/does/not/exist'), trim($response->original)); + $this->assertEquals(URL::to('/nl/route/does/not/exist'), trim($response->original)); } /** @test */ @@ -624,9 +625,9 @@ public function it_returns_a_localized_url_for_a_localized_fallback_route() $response = $this->call('GET', '/nl/non/existing/route'); $response->assertNotFound(); $this->assertEquals([ - 'current' => url('/nl/non/existing/route'), - 'en' => url('/en/non/existing/route'), - 'nl' => url('/nl/non/existing/route'), + 'current' => URL::to('/nl/non/existing/route'), + 'en' => URL::to('/en/non/existing/route'), + 'nl' => URL::to('/nl/non/existing/route'), ], $response->original); } @@ -648,9 +649,9 @@ public function it_returns_a_localized_url_for_a_non_localized_fallback_route_if $response = $this->call('GET', '/nl/non/existing/route'); $response->assertNotFound(); $this->assertEquals([ - 'current' => url('/nl/non/existing/route'), - 'en' => url('/en/non/existing/route'), - 'nl' => url('/nl/non/existing/route'), + 'current' => URL::to('/nl/non/existing/route'), + 'en' => URL::to('/en/non/existing/route'), + 'nl' => URL::to('/nl/non/existing/route'), ], $response->original); } @@ -672,9 +673,9 @@ public function it_returns_a_localized_url_for_a_non_localized_fallback_route_if $response = $this->call('GET', '/non/existing/route'); $response->assertNotFound(); $this->assertEquals([ - 'current' => url('/nl/non/existing/route'), - 'en' => url('/en/non/existing/route'), - 'nl' => url('/nl/non/existing/route'), + 'current' => URL::to('/nl/non/existing/route'), + 'en' => URL::to('/en/non/existing/route'), + 'nl' => URL::to('/nl/non/existing/route'), ], $response->original); } @@ -697,9 +698,9 @@ public function it_returns_a_localized_url_for_a_non_localized_fallback_route_wh $response = $this->call('GET', '/non/existing/route'); $response->assertNotFound(); $this->assertEquals([ - 'current' => url('/non/existing/route'), - 'en' => url('/en/non/existing/route'), - 'nl' => url('/non/existing/route'), + 'current' => URL::to('/non/existing/route'), + 'en' => URL::to('/en/non/existing/route'), + 'nl' => URL::to('/non/existing/route'), ], $response->original); } @@ -788,9 +789,9 @@ public function it_returns_a_url_with_query_string_for_existing_non_localized_un $response = $this->call('GET', '/route?another=one¶m=value'); $response->assertOk(); $this->assertEquals([ - 'current' => url('/route?another=one¶m=value'), - 'en' => url('/route?another=one¶m=value'), - 'nl' => url('/route?another=one¶m=value'), + 'current' => URL::to('/route?another=one¶m=value'), + 'en' => URL::to('/route?another=one¶m=value'), + 'nl' => URL::to('/route?another=one¶m=value'), ], $response->original); } @@ -814,9 +815,9 @@ public function it_returns_a_url_with_query_string_for_existing_localized_unname $response = $this->call('GET', '/nl/route?another=one¶m=value'); $response->assertOk(); $this->assertEquals([ - 'current' => url('/nl/route?another=one¶m=value'), - 'en' => url('/en/route?another=one¶m=value'), - 'nl' => url('/nl/route?another=one¶m=value'), + 'current' => URL::to('/nl/route?another=one¶m=value'), + 'en' => URL::to('/en/route?another=one¶m=value'), + 'nl' => URL::to('/nl/route?another=one¶m=value'), ], $response->original); } @@ -837,9 +838,9 @@ public function it_returns_a_url_with_query_string_for_existing_non_localized_na $response = $this->call('GET', '/route?another=one¶m=value'); $response->assertOk(); $this->assertEquals([ - 'current' => url('/route?another=one¶m=value'), - 'en' => url('/route?another=one¶m=value'), - 'nl' => url('/route?another=one¶m=value'), + 'current' => URL::to('/route?another=one¶m=value'), + 'en' => URL::to('/route?another=one¶m=value'), + 'nl' => URL::to('/route?another=one¶m=value'), ], $response->original); } @@ -863,9 +864,9 @@ public function it_returns_a_url_with_query_string_for_existing_localized_named_ $response = $this->call('GET', '/nl/route?another=one¶m=value'); $response->assertOk(); $this->assertEquals([ - 'current' => url('/nl/route?another=one¶m=value'), - 'en' => url('/en/route?another=one¶m=value'), - 'nl' => url('/nl/route?another=one¶m=value'), + 'current' => URL::to('/nl/route?another=one¶m=value'), + 'en' => URL::to('/en/route?another=one¶m=value'), + 'nl' => URL::to('/nl/route?another=one¶m=value'), ], $response->original); } @@ -889,9 +890,9 @@ public function it_returns_a_url_without_query_string_for_existing_localized_nam $response = $this->call('GET', '/nl/route?another=one¶m=value'); $response->assertOk(); $this->assertEquals([ - 'current' => url('/nl/route'), - 'en' => url('/en/route'), - 'nl' => url('/nl/route'), + 'current' => URL::to('/nl/route'), + 'en' => URL::to('/en/route'), + 'nl' => URL::to('/nl/route'), ], $response->original); } @@ -912,9 +913,9 @@ public function it_accepts_query_string_parameters_using_named_routes() $response = $this->call('GET', '/route/some-slug?param=value'); $response->assertOk(); $this->assertEquals([ - 'current' => url('/route/another-slug/optional-slug?new=value'), - 'en' => url('/route/another-slug/optional-slug?new=value'), - 'nl' => url('/route/another-slug/optional-slug?new=value'), + 'current' => URL::to('/route/another-slug/optional-slug?new=value'), + 'en' => URL::to('/route/another-slug/optional-slug?new=value'), + 'nl' => URL::to('/route/another-slug/optional-slug?new=value'), ], $response->original); } @@ -935,9 +936,9 @@ public function it_ignores_query_string_parameters_using_named_routes() $response = $this->call('GET', '/route/some-slug?param=value'); $response->assertOk(); $this->assertEquals([ - 'current' => url('/route/another-slug/optional-slug'), - 'en' => url('/route/another-slug/optional-slug'), - 'nl' => url('/route/another-slug/optional-slug'), + 'current' => URL::to('/route/another-slug/optional-slug'), + 'en' => URL::to('/route/another-slug/optional-slug'), + 'nl' => URL::to('/route/another-slug/optional-slug'), ], $response->original); } @@ -958,9 +959,9 @@ public function it_accepts_query_string_parameters_using_unnamed_routes() $response = $this->call('GET', '/route/some-slug?param=value'); $response->assertOk(); $this->assertEquals([ - 'current' => url('/route/another-slug/optional-slug?new=value'), - 'en' => url('/route/another-slug/optional-slug?new=value'), - 'nl' => url('/route/another-slug/optional-slug?new=value'), + 'current' => URL::to('/route/another-slug/optional-slug?new=value'), + 'en' => URL::to('/route/another-slug/optional-slug?new=value'), + 'nl' => URL::to('/route/another-slug/optional-slug?new=value'), ], $response->original); } @@ -981,9 +982,9 @@ public function it_ignores_query_string_parameters_using_unnamed_routes() $response = $this->call('GET', '/route/some-slug?param=value'); $response->assertOk(); $this->assertEquals([ - 'current' => url('/route/another-slug/optional-slug'), - 'en' => url('/route/another-slug/optional-slug'), - 'nl' => url('/route/another-slug/optional-slug'), + 'current' => URL::to('/route/another-slug/optional-slug'), + 'en' => URL::to('/route/another-slug/optional-slug'), + 'nl' => URL::to('/route/another-slug/optional-slug'), ], $response->original); } @@ -1004,9 +1005,9 @@ public function it_allows_optional_parameters_with_named_routes() $response = $this->call('GET', '/route/some-slug'); $response->assertOk(); $this->assertEquals([ - 'current' => url('/route/another-slug'), - 'en' => url('/route/another-slug'), - 'nl' => url('/route/another-slug'), + 'current' => URL::to('/route/another-slug'), + 'en' => URL::to('/route/another-slug'), + 'nl' => URL::to('/route/another-slug'), ], $response->original); } @@ -1027,9 +1028,9 @@ public function it_allows_optional_parameters_with_unnamed_routes() $response = $this->call('GET', '/route/some-slug'); $response->assertOk(); $this->assertEquals([ - 'current' => url('/route/another-slug'), - 'en' => url('/route/another-slug'), - 'nl' => url('/route/another-slug'), + 'current' => URL::to('/route/another-slug'), + 'en' => URL::to('/route/another-slug'), + 'nl' => URL::to('/route/another-slug'), ], $response->original); } @@ -1050,9 +1051,9 @@ public function it_handles_capitalized_parameter_names() $response = $this->call('GET', '/route/some-slug'); $response->assertOk(); $this->assertEquals([ - 'current' => url('/route/another-slug'), - 'en' => url('/route/another-slug'), - 'nl' => url('/route/another-slug'), + 'current' => URL::to('/route/another-slug'), + 'en' => URL::to('/route/another-slug'), + 'nl' => URL::to('/route/another-slug'), ], $response->original); } @@ -1085,9 +1086,9 @@ public function it_returns_a_url_with_translated_slugs_for_named_routes() $response = $this->call('GET', '/nl/route/nl-route'); $response->assertOk(); $this->assertEquals([ - 'current' => url('/nl/route/nl-route'), - 'en' => url('/en/route/en-route'), - 'nl' => url('/nl/route/nl-route'), + 'current' => URL::to('/nl/route/nl-route'), + 'en' => URL::to('/en/route/en-route'), + 'nl' => URL::to('/nl/route/nl-route'), ], $response->original); } diff --git a/tests/Unit/UrlGeneratorTest.php b/tests/Unit/UrlGeneratorTest.php index 41f1285..8af41f8 100644 --- a/tests/Unit/UrlGeneratorTest.php +++ b/tests/Unit/UrlGeneratorTest.php @@ -35,13 +35,13 @@ public function it_gets_the_url_of_a_named_route_as_usual() $this->registerRoute('en/route/name', 'en.route.name'); $this->registerRoute('nl/route/name', 'nl.route.name'); - $this->assertEquals(url('weirdly-named-route'), route('en')); - $this->assertEquals(url('route'), route('route')); - $this->assertEquals(url('en/route'), route('en.route')); - $this->assertEquals(url('nl/route'), route('nl.route')); - $this->assertEquals(url('route/name'), route('route.name')); - $this->assertEquals(url('en/route/name'), route('en.route.name')); - $this->assertEquals(url('nl/route/name'), route('nl.route.name')); + $this->assertEquals(URL::to('weirdly-named-route'), URL::route('en')); + $this->assertEquals(URL::to('route'), URL::route('route')); + $this->assertEquals(URL::to('en/route'), URL::route('en.route')); + $this->assertEquals(URL::to('nl/route'), URL::route('nl.route')); + $this->assertEquals(URL::to('route/name'), URL::route('route.name')); + $this->assertEquals(URL::to('en/route/name'), URL::route('en.route.name')); + $this->assertEquals(URL::to('nl/route/name'), URL::route('nl.route.name')); } /** @test */ @@ -52,7 +52,7 @@ public function it_gets_the_url_of_a_route_in_the_current_locale_if_the_given_ro $this->registerRoute('en/route', 'en.route.name'); - $this->assertEquals(url('en/route'), route('route.name')); + $this->assertEquals(URL::to('en/route'), URL::route('route.name')); } /** @test */ @@ -65,7 +65,7 @@ public function it_throws_if_no_valid_route_can_be_found() $this->expectException(InvalidArgumentException::class); - route('route'); + URL::route('route'); } /** @test */ @@ -78,7 +78,7 @@ public function it_throws_if_no_valid_localized_route_can_be_found() $this->expectException(InvalidArgumentException::class); - route('route.name'); + URL::route('route.name'); } /** @test */ @@ -90,9 +90,9 @@ public function it_gets_the_url_of_a_route_in_the_given_locale() $this->registerRoute('en/route', 'en.route.name'); $this->registerRoute('nl/route', 'nl.route.name'); - $this->assertEquals(url('nl/route'), route('route.name', [], true, 'nl')); - $this->assertEquals(url('nl/route'), route('en.route.name', [], true, 'nl')); - $this->assertEquals(url('nl/route'), route('nl.route.name', [], true, 'nl')); + $this->assertEquals(URL::to('nl/route'), URL::route('route.name', [], true, 'nl')); + $this->assertEquals(URL::to('nl/route'), URL::route('en.route.name', [], true, 'nl')); + $this->assertEquals(URL::to('nl/route'), URL::route('nl.route.name', [], true, 'nl')); } /** @test */ @@ -107,9 +107,9 @@ public function it_gets_the_url_of_a_route_in_the_given_locale_when_using_custom $this->registerRoute('route', 'en.route.name')->domain('en.domain.test'); $this->registerRoute('route', 'nl.route.name')->domain('nl.domain.test'); - $this->assertEquals('http://nl.domain.test/route', route('route.name', [], true, 'nl')); - $this->assertEquals('http://nl.domain.test/route', route('en.route.name', [], true, 'nl')); - $this->assertEquals('http://nl.domain.test/route', route('nl.route.name', [], true, 'nl')); + $this->assertEquals('http://nl.domain.test/route', URL::route('route.name', [], true, 'nl')); + $this->assertEquals('http://nl.domain.test/route', URL::route('en.route.name', [], true, 'nl')); + $this->assertEquals('http://nl.domain.test/route', URL::route('nl.route.name', [], true, 'nl')); } /** @test */ @@ -123,9 +123,9 @@ public function it_gets_the_url_of_a_route_in_the_given_locale_when_using_custom $this->registerRoute('english/route', 'en.route.name'); $this->registerRoute('dutch/route', 'nl.route.name'); - $this->assertEquals(url('dutch/route'), route('route.name', [], true, 'nl')); - $this->assertEquals(url('dutch/route'), route('en.route.name', [], true, 'nl')); - $this->assertEquals(url('dutch/route'), route('nl.route.name', [], true, 'nl')); + $this->assertEquals(URL::to('dutch/route'), URL::route('route.name', [], true, 'nl')); + $this->assertEquals(URL::to('dutch/route'), URL::route('en.route.name', [], true, 'nl')); + $this->assertEquals(URL::to('dutch/route'), URL::route('nl.route.name', [], true, 'nl')); } /** @test */ @@ -137,7 +137,7 @@ public function it_always_gets_the_url_of_a_localized_route_if_a_locale_is_speci $this->registerRoute('route', 'route.name'); $this->registerRoute('nl/route', 'nl.route.name'); - $this->assertEquals(url('nl/route'), route('route.name', [], true, 'nl')); + $this->assertEquals(URL::to('nl/route'), URL::route('route.name', [], true, 'nl')); } /** @test */ @@ -149,7 +149,7 @@ public function it_returns_a_registered_non_localized_url_if_a_localized_version $this->registerRoute('route', 'route.name'); $this->registerRoute('nl/route', 'nl.route.name'); - $this->assertEquals(url('route'), route('route.name', [], true, 'en')); + $this->assertEquals(URL::to('route'), URL::route('route.name', [], true, 'en')); } /** @test */ @@ -162,7 +162,7 @@ public function it_throws_if_no_valid_route_can_be_found_for_the_given_locale() $this->expectException(InvalidArgumentException::class); - route('en.route.name', [], true, 'nl'); + URL::route('en.route.name', [], true, 'nl'); } /** @test */ @@ -175,7 +175,7 @@ public function it_throws_if_you_do_not_specify_a_name_for_a_localized_route() $this->expectException(InvalidArgumentException::class); - route('en.', [], true, 'en'); + URL::route('en.', [], true, 'en'); } /** @test */ @@ -196,9 +196,9 @@ public function it_generates_a_url_for_a_route_with_a_default_localized_route_ke $this->registerRoute('en/route/{slug}', 'en.route.name'); $this->registerRoute('nl/route/{slug}', 'nl.route.name'); - $this->assertEquals(url('en/route/en-slug'), route('route.name', [$model])); - $this->assertEquals(url('en/route/en-slug'), route('route.name', [$model], true, 'en')); - $this->assertEquals(url('nl/route/nl-slug'), route('route.name', [$model], true, 'nl')); + $this->assertEquals(URL::to('en/route/en-slug'), URL::route('route.name', [$model])); + $this->assertEquals(URL::to('en/route/en-slug'), URL::route('route.name', [$model], true, 'en')); + $this->assertEquals(URL::to('nl/route/nl-slug'), URL::route('route.name', [$model], true, 'nl')); } /** @test */ @@ -219,9 +219,9 @@ public function it_generates_a_url_for_a_route_with_a_custom_localized_route_key $this->registerRoute('en/route/{model:slug}', 'en.route.name'); $this->registerRoute('nl/route/{model:slug}', 'nl.route.name'); - $this->assertEquals(url('en/route/en-slug'), route('route.name', [$model])); - $this->assertEquals(url('en/route/en-slug'), route('route.name', [$model], true, 'en')); - $this->assertEquals(url('nl/route/nl-slug'), route('route.name', [$model], true, 'nl')); + $this->assertEquals(URL::to('en/route/en-slug'), URL::route('route.name', [$model])); + $this->assertEquals(URL::to('en/route/en-slug'), URL::route('route.name', [$model], true, 'en')); + $this->assertEquals(URL::to('nl/route/nl-slug'), URL::route('route.name', [$model], true, 'nl')); } /** @test */