@@ -27,28 +27,28 @@ protected function setUp(): void
2727 {
2828 parent ::setUp ();
2929
30+ // Remove any default browser locales
31+ $ this ->setBrowserLocales (null );
32+
3033 $ this ->sessionKey = Config::get ('localizer.session-key ' );
3134 $ this ->cookieName = Config::get ('localizer.cookie-name ' );
3235 }
3336
3437 /** @test */
3538 public function it_looks_for_a_locale_in_a_custom_route_action ()
3639 {
37- $ this ->setSupportedLocales (['en ' , 'nl ' , 'fr ' , 'de ' , 'es ' , 'it ' ]);
38- $ this ->setSessionLocale ('fr ' );
39- $ this ->setBrowserLocales ('it ' );
40+ $ this ->setSupportedLocales (['en ' , 'nl ' ]);
4041 $ this ->setAppLocale ('en ' );
41- $ cookie = 'de ' ;
4242
43- Route:: group ([
44- ' locale ' => ' nl ' ,
45- ] , function () {
43+ $ routeAction = [ ' locale ' => ' nl ' ];
44+
45+ Route:: group ( $ routeAction , function () {
4646 Route::get ('some/route ' , function () {
4747 return App::getLocale ();
4848 })->middleware (['web ' , SetLocale::class]);
4949 });
5050
51- $ response = $ this ->getWithCookie ('some/route ' , $ cookie );
51+ $ response = $ this ->get ('some/route ' );
5252
5353 $ response ->assertSessionHas ($ this ->sessionKey , 'nl ' );
5454 $ response ->assertCookie ($ this ->cookieName , 'nl ' );
@@ -58,17 +58,14 @@ public function it_looks_for_a_locale_in_a_custom_route_action()
5858 /** @test */
5959 public function it_looks_for_a_locale_in_the_url ()
6060 {
61- $ this ->setSupportedLocales (['en ' , 'nl ' , 'fr ' , 'de ' , 'es ' , 'it ' ]);
62- $ this ->setSessionLocale ('fr ' );
63- $ this ->setBrowserLocales ('it ' );
61+ $ this ->setSupportedLocales (['en ' , 'nl ' ]);
6462 $ this ->setAppLocale ('en ' );
65- $ cookie = 'de ' ;
6663
6764 Route::get ('nl/some/route ' , function () {
6865 return App::getLocale ();
6966 })->middleware (['web ' , SetLocale::class]);
7067
71- $ response = $ this ->getWithCookie ('nl/some/route ' , $ cookie );
68+ $ response = $ this ->get ('nl/some/route ' );
7269
7370 $ response ->assertSessionHas ($ this ->sessionKey , 'nl ' );
7471 $ response ->assertCookie ($ this ->cookieName , 'nl ' );
@@ -78,19 +75,16 @@ public function it_looks_for_a_locale_in_the_url()
7875 /** @test */
7976 public function you_can_configure_which_segment_to_use_as_locale ()
8077 {
81- $ this ->setSupportedLocales (['en ' , 'nl ' , 'fr ' , 'de ' , 'es ' , 'it ' ]);
82- $ this ->setSessionLocale ('fr ' );
83- $ this ->setBrowserLocales ('it ' );
78+ $ this ->setSupportedLocales (['en ' , 'nl ' ]);
8479 $ this ->setAppLocale ('en ' );
85- $ cookie = 'de ' ;
8680
8781 Config::set ('localizer.url-segment ' , 2 );
8882
8983 Route::get ('some/nl/route ' , function () {
9084 return App::getLocale ();
9185 })->middleware (['web ' , SetLocale::class]);
9286
93- $ response = $ this ->getWithCookie ('some/nl/route ' , $ cookie );
87+ $ response = $ this ->get ('some/nl/route ' );
9488
9589 $ response ->assertSessionHas ($ this ->sessionKey , 'nl ' );
9690 $ response ->assertCookie ($ this ->cookieName , 'nl ' );
@@ -103,7 +97,6 @@ public function it_looks_for_custom_slugs()
10397 $ this ->setSupportedLocales ([
10498 'en ' => 'english ' ,
10599 'nl ' => 'dutch ' ,
106- 'fr ' => 'french ' ,
107100 ]);
108101 $ this ->setAppLocale ('en ' );
109102
@@ -124,7 +117,6 @@ public function you_can_use_multiple_slugs_for_a_locale()
124117 $ this ->setSupportedLocales ([
125118 'en ' => 'english ' ,
126119 'nl ' => ['dutch ' , 'nederlands ' ],
127- 'fr ' => 'french ' ,
128120 ]);
129121 $ this ->setAppLocale ('en ' );
130122
@@ -155,13 +147,10 @@ public function it_looks_for_custom_domains()
155147 $ this ->setSupportedLocales ([
156148 'en ' => 'english.test ' ,
157149 'nl ' => 'dutch.test ' ,
158- 'fr ' => 'french.test ' ,
159150 ]);
160151 $ this ->setAppLocale ('en ' );
161152
162- Route::group ([
163- 'domain ' => 'dutch.test ' ,
164- ], function () {
153+ Route::group (['domain ' => 'dutch.test ' ], function () {
165154 Route::get ('some/route ' , function () {
166155 return App::getLocale ();
167156 })->middleware (['web ' , SetLocale::class]);
@@ -180,21 +169,16 @@ public function you_can_use_multiple_domains_for_a_locale()
180169 $ this ->setSupportedLocales ([
181170 'en ' => 'english.test ' ,
182171 'nl ' => ['dutch.test ' , 'nederlands.test ' ],
183- 'fr ' => 'french.test ' ,
184172 ]);
185173 $ this ->setAppLocale ('en ' );
186174
187- Route::group ([
188- 'domain ' => 'dutch.test ' ,
189- ], function () {
175+ Route::group (['domain ' => 'dutch.test ' ], function () {
190176 Route::get ('some/route ' , function () {
191177 return App::getLocale ();
192178 })->middleware (['web ' , SetLocale::class]);
193179 });
194180
195- Route::group ([
196- 'domain ' => 'nederlands.test ' ,
197- ], function () {
181+ Route::group (['domain ' => 'nederlands.test ' ], function () {
198182 Route::get ('some/route ' , function () {
199183 return App::getLocale ();
200184 })->middleware (['web ' , SetLocale::class]);
@@ -216,32 +200,27 @@ public function you_can_use_multiple_domains_for_a_locale()
216200 /** @test */
217201 public function it_checks_for_a_configured_omitted_locale ()
218202 {
219- $ this ->setSupportedLocales (['en ' , 'nl ' , 'fr ' , 'de ' , 'es ' , 'it ' ]);
220- $ this ->setOmittedLocale ('nl ' );
221- $ this ->setSessionLocale ('fr ' );
222- $ this ->setBrowserLocales ('it ' );
203+ $ this ->setSupportedLocales (['en ' , 'nl ' ]);
223204 $ this ->setAppLocale ('en ' );
224- $ cookie = 'de ' ;
205+
206+ $ this ->setOmittedLocale ('nl ' );
225207
226208 Route::get ('some/route ' , function () {
227209 return App::getLocale ();
228210 })->middleware (['web ' , SetLocale::class]);
229211
230- $ response = $ this ->getWithCookie ('some/route ' , $ cookie );
212+ $ response = $ this ->get ('some/route ' );
231213
232214 $ response ->assertSessionHas ($ this ->sessionKey , 'nl ' );
233215 $ response ->assertCookie ($ this ->cookieName , 'nl ' );
234216 $ this ->assertEquals ('nl ' , $ response ->original );
235217 }
236218
237219 /** @test */
238- public function it_looks_for_a_locale_on_the_authenticated_user_if_not_found_in_the_url ()
220+ public function it_looks_for_a_locale_on_the_authenticated_user ()
239221 {
240- $ this ->setSupportedLocales (['en ' , 'nl ' , 'fr ' , 'de ' , 'es ' , 'it ' ]);
241- $ this ->setSessionLocale ('fr ' );
242- $ this ->setBrowserLocales ('it ' );
222+ $ this ->setSupportedLocales (['en ' , 'nl ' ]);
243223 $ this ->setAppLocale ('en ' );
244- $ cookie = 'de ' ;
245224
246225 $ attribute = Config::get ('localizer.user-attribute ' );
247226 $ user = new User ();
@@ -251,7 +230,7 @@ public function it_looks_for_a_locale_on_the_authenticated_user_if_not_found_in_
251230 return App::getLocale ();
252231 })->middleware (['web ' , SetLocale::class]);
253232
254- $ response = $ this ->actingAs ($ user )->getWithCookie ('some/route ' , $ cookie );
233+ $ response = $ this ->actingAs ($ user )->get ('some/route ' );
255234
256235 $ response ->assertSessionHas ($ this ->sessionKey , 'nl ' );
257236 $ response ->assertCookie ($ this ->cookieName , 'nl ' );
@@ -262,125 +241,118 @@ public function it_looks_for_a_locale_on_the_authenticated_user_if_not_found_in_
262241 public function it_will_bypass_missing_attribute_exception_if_the_locale_attribute_is_missing_on_the_user_model ()
263242 {
264243 if (version_compare (App::version (), '9.35.0 ' ) === -1 ) {
265- $ this ->markTestSkipped ('This test only applies to Laravel 9 and higher. ' );
244+ $ this ->markTestSkipped ('This test only applies to Laravel 9.35.0 and higher. ' );
266245 }
267246
268- $ this ->setSupportedLocales (['en ' , 'nl ' , 'fr ' , 'de ' , 'es ' , 'it ' ]);
269- $ this ->setSessionLocale ('fr ' );
270- $ this ->setBrowserLocales ('it ' );
247+ $ this ->setSupportedLocales (['en ' , 'nl ' ]);
271248 $ this ->setAppLocale ('en ' );
272- $ cookie = 'de ' ;
273249
274250 $ user = new User ();
275- $ user ->exists = true ;
251+ $ user ->exists = true ; // exception is only thrown if user "exists"
276252 Model::preventAccessingMissingAttributes ();
277253
278254 Route::get ('some/route ' , function () {
279255 return App::getLocale ();
280256 })->middleware (['web ' , SetLocale::class]);
281257
282- $ response = $ this ->actingAs ($ user )->getWithCookie ('some/route ' , $ cookie );
258+ $ response = $ this ->actingAs ($ user )->get ('some/route ' );
283259
284- $ response ->assertSessionHas ($ this ->sessionKey , 'fr ' );
285- $ response ->assertCookie ($ this ->cookieName , 'fr ' );
286- $ this ->assertEquals ('fr ' , $ response ->original );
260+ $ response ->assertSessionHas ($ this ->sessionKey , 'en ' );
261+ $ response ->assertCookie ($ this ->cookieName , 'en ' );
262+ $ this ->assertEquals ('en ' , $ response ->original );
287263 }
288264
289265 /** @test */
290- public function it_looks_for_a_locale_in_the_session_if_not_found_in_the_url ()
266+ public function it_looks_for_a_locale_in_the_session ()
291267 {
292- $ this ->setSupportedLocales (['en ' , 'nl ' , 'fr ' , 'de ' , 'es ' , 'it ' ]);
293- $ this ->setSessionLocale ('fr ' );
294- $ this ->setBrowserLocales ('it ' );
268+ $ this ->setSupportedLocales (['en ' , 'nl ' ]);
295269 $ this ->setAppLocale ('en ' );
296- $ cookie = 'de ' ;
270+
271+ $ this ->setSessionLocale ('nl ' );
297272
298273 Route::get ('some/route ' , function () {
299274 return App::getLocale ();
300275 })->middleware (['web ' , SetLocale::class]);
301276
302- $ response = $ this ->getWithCookie ('some/route ' , $ cookie );
277+ $ response = $ this ->get ('some/route ' );
303278
304- $ response ->assertSessionHas ($ this ->sessionKey , 'fr ' );
305- $ response ->assertCookie ($ this ->cookieName , 'fr ' );
306- $ this ->assertEquals ('fr ' , $ response ->original );
279+ $ response ->assertSessionHas ($ this ->sessionKey , 'nl ' );
280+ $ response ->assertCookie ($ this ->cookieName , 'nl ' );
281+ $ this ->assertEquals ('nl ' , $ response ->original );
307282 }
308283
309284 /** @test */
310- public function it_looks_for_a_locale_in_a_cookie_if_not_found_in_the_url_or_session ()
285+ public function it_looks_for_a_locale_in_a_cookie ()
311286 {
312- $ this ->setSupportedLocales (['en ' , 'nl ' , 'fr ' , 'de ' , 'es ' , 'it ' ]);
313- $ this ->setSessionLocale (null );
314- $ this ->setBrowserLocales ('it ' );
287+ $ this ->setSupportedLocales (['en ' , 'nl ' ]);
315288 $ this ->setAppLocale ('en ' );
316- $ cookie = 'de ' ;
289+
290+ $ cookie = 'nl ' ;
317291
318292 Route::get ('some/route ' , function () {
319293 return App::getLocale ();
320294 })->middleware (['web ' , SetLocale::class]);
321295
322296 $ response = $ this ->getWithCookie ('some/route ' , $ cookie );
323297
324- $ response ->assertSessionHas ($ this ->sessionKey , 'de ' );
325- $ response ->assertCookie ($ this ->cookieName , 'de ' );
326- $ this ->assertEquals ('de ' , $ response ->original );
298+ $ response ->assertSessionHas ($ this ->sessionKey , 'nl ' );
299+ $ response ->assertCookie ($ this ->cookieName , 'nl ' );
300+ $ this ->assertEquals ('nl ' , $ response ->original );
327301 }
328302
329303 /** @test */
330- public function it_looks_for_a_locale_in_the_browser_if_not_found_in_the_url_or_session_or_cookie ()
304+ public function it_looks_for_a_locale_in_the_browser ()
331305 {
332- $ this ->setSupportedLocales (['en ' , 'nl ' , 'fr ' , 'de ' , 'es ' , 'it ' ]);
333- $ this ->setSessionLocale (null );
334- $ this ->setBrowserLocales ('it ' );
306+ $ this ->setSupportedLocales (['en ' , 'nl ' ]);
335307 $ this ->setAppLocale ('en ' );
336308
309+ $ this ->setBrowserLocales ('nl ' );
310+
337311 Route::get ('some/route ' , function () {
338312 return App::getLocale ();
339313 })->middleware (['web ' , SetLocale::class]);
340314
341315 $ response = $ this ->get ('some/route ' );
342316
343- $ response ->assertSessionHas ($ this ->sessionKey , 'it ' );
344- $ response ->assertCookie ($ this ->cookieName , 'it ' );
345- $ this ->assertEquals ('it ' , $ response ->original );
317+ $ response ->assertSessionHas ($ this ->sessionKey , 'nl ' );
318+ $ response ->assertCookie ($ this ->cookieName , 'nl ' );
319+ $ this ->assertEquals ('nl ' , $ response ->original );
346320 }
347321
348322 /** @test */
349323 public function it_returns_the_best_match_when_a_browser_locale_is_used ()
350324 {
351- $ this ->setSupportedLocales (['en ' , 'nl ' , 'fr ' , 'de ' , 'es ' , 'it ' ]);
352- $ this ->setSessionLocale (null );
353- $ this ->setBrowserLocales ('cs,it-IT;q=0.4,es;q=0.8 ' );
325+ $ this ->setSupportedLocales (['en ' , 'nl ' , 'fr ' ]);
354326 $ this ->setAppLocale ('en ' );
355327
328+ $ this ->setBrowserLocales ('de,fr;q=0.4,nl-BE;q=0.8 ' );
329+
356330 Route::get ('some/route ' , function () {
357331 return App::getLocale ();
358332 })->middleware (['web ' , SetLocale::class]);
359333
360334 $ response = $ this ->get ('some/route ' );
361335
362- $ response ->assertSessionHas ($ this ->sessionKey , 'es ' );
363- $ response ->assertCookie ($ this ->cookieName , 'es ' );
364- $ this ->assertEquals ('es ' , $ response ->original );
336+ $ response ->assertSessionHas ($ this ->sessionKey , 'nl ' );
337+ $ response ->assertCookie ($ this ->cookieName , 'nl ' );
338+ $ this ->assertEquals ('nl ' , $ response ->original );
365339 }
366340
367341 /** @test */
368- public function it_defaults_to_the_current_app_locale ()
342+ public function it_looks_for_the_current_app_locale ()
369343 {
370- $ this ->setSupportedLocales (['en ' , 'nl ' , 'fr ' , 'de ' , 'es ' , 'it ' ]);
371- $ this ->setSessionLocale (null );
372- $ this ->setBrowserLocales (null );
373- $ this ->setAppLocale ('en ' );
344+ $ this ->setSupportedLocales (['en ' , 'nl ' ]);
345+ $ this ->setAppLocale ('nl ' );
374346
375347 Route::get ('some/route ' , function () {
376348 return App::getLocale ();
377349 })->middleware (['web ' , SetLocale::class]);
378350
379351 $ response = $ this ->get ('some/route ' );
380352
381- $ response ->assertSessionHas ($ this ->sessionKey , 'en ' );
382- $ response ->assertCookie ($ this ->cookieName , 'en ' );
383- $ this ->assertEquals ('en ' , $ response ->original );
353+ $ response ->assertSessionHas ($ this ->sessionKey , 'nl ' );
354+ $ response ->assertCookie ($ this ->cookieName , 'nl ' );
355+ $ this ->assertEquals ('nl ' , $ response ->original );
384356 }
385357
386358 /** @test */
0 commit comments