canBeUsed(); // THEN expect($canBeUsed)->toBeTrue(); }); it('returns localized url for existing route with locale parameter', function () { // GIVEN Route::name('about')->get('/{locale}/about', fn () => 'about'); $localizer = new DefaultRouteLocalizer(); // WHEN $url = $localizer->getLocalizedUrl('fr', 'about'); // THEN expect($url)->not->toBeNull() ->and((string) $url)->toBe('http://localhost/fr/about'); }); it('returns null when route does not exist', function () { // GIVEN $localizer = new DefaultRouteLocalizer(); // WHEN $url = $localizer->getLocalizedUrl('fr', 'non-existing-route'); // THEN expect($url)->toBeNull(); }); it('does not append a locale query string when the route has no locale parameter', function () { // GIVEN Route::name('contact')->get('/contact', fn () => 'contact'); $localizer = new DefaultRouteLocalizer(); // WHEN $url = $localizer->getLocalizedUrl('fr', 'contact'); // THEN expect($url)->not->toBeNull() ->and((string) $url)->toBe('http://localhost/contact'); }); it('uses the given locale in the path for each locale when the route has a locale parameter', function () { // GIVEN Route::name('about')->get('/{locale}/about', fn () => 'about'); $localizer = new DefaultRouteLocalizer(); // WHEN $fr = $localizer->getLocalizedUrl('fr', 'about'); $en = $localizer->getLocalizedUrl('en', 'about'); // THEN expect((string) $fr)->toBe('http://localhost/fr/about') ->and((string) $en)->toBe('http://localhost/en/about'); }); });