Skip to content

Commit 093bffe

Browse files
committed
Fix broken test
1 parent eb6a381 commit 093bffe

File tree

3 files changed

+6
-36
lines changed

3 files changed

+6
-36
lines changed

spec/LaravelLocale/LocaleUrlGeneratorSpec.php

-33
Original file line numberDiff line numberDiff line change
@@ -54,37 +54,4 @@ function it_passes_prefixed_named_route_to_url_when_locale_is_not_default(Config
5454

5555
$this->route('home');
5656
}
57-
58-
function it_can_change_url_to_same_locale(Config $config, Request $request)
59-
{
60-
$config->get('app.locale')->willReturn('ja');
61-
$request->fullUrl()->willReturn('http://example.com/?query=value');
62-
63-
$this->change('ja')->shouldReturn('http://example.com/?query=value');
64-
}
65-
66-
function it_can_change_url_to_other_locale_from_default(Config $config, Request $request)
67-
{
68-
$config->get('app.locale')->willReturn('ja');
69-
$request->root()->willReturn('http://example.com');
70-
$request->fullUrl()->willReturn('http://example.com/?query=value');
71-
72-
$this->change('en')->shouldReturn('http://example.com/en/?query=value');
73-
}
74-
75-
function it_can_change_url_to_default_locale_from_non_default_locale(Config $config, Request $request)
76-
{
77-
$config->get('app.locale')->willReturn('en');
78-
$request->fullUrl()->willReturn('http://example.com/en/?query=value');
79-
80-
$this->change('ja')->shouldReturn('http://example.com/?query=value');
81-
}
82-
83-
function it_can_change_url_to_other_locale_from_non_default_locale(Config $config, Request $request)
84-
{
85-
$config->get('app.locale')->willReturn('en');
86-
$request->fullUrl()->willReturn('http://example.com/en/?query=value');
87-
88-
$this->change('fr')->shouldReturn('http://example.com/fr/?query=value');
89-
}
9057
}

src/LaravelLocale/LocaleRouter.php

+5-2
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@ protected function generateRoutes($method, $uri, $action)
107107
$default = $this->config->get('app.fallback_locale');
108108

109109
foreach ($availables as $locale) {
110+
if ($locale == $default) {
111+
$this->router->{$method}($uri, $action);
112+
continue;
113+
}
114+
110115
$localedUri = $locale . '/' . $uri;
111116

112117
if ( ! isset($action['as'])) {
@@ -120,7 +125,5 @@ protected function generateRoutes($method, $uri, $action)
120125

121126
$this->router->{$method}($localedUri, $localedAction);
122127
}
123-
124-
$this->router->{$method}($uri, $action);
125128
}
126129
}

src/LaravelLocale/LocaleUrlGenerator.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public function urlFor($locale)
120120
*/
121121
protected function replaceLocaleString($replace = '/')
122122
{
123-
$uri = $this->getFullUri($this->request->fullUrl());
123+
$uri = $this->getFullUri();
124124
$firstSegment = $this->request->segment(1);
125125

126126
if ( ! in_array($firstSegment, $this->config->get('locale.available_locales'))) {

0 commit comments

Comments
 (0)