@@ -27,28 +27,28 @@ protected function setUp(): void
27
27
{
28
28
parent ::setUp ();
29
29
30
+ // Remove any default browser locales
31
+ $ this ->setBrowserLocales (null );
32
+
30
33
$ this ->sessionKey = Config::get ('localizer.session-key ' );
31
34
$ this ->cookieName = Config::get ('localizer.cookie-name ' );
32
35
}
33
36
34
37
/** @test */
35
38
public function it_looks_for_a_locale_in_a_custom_route_action ()
36
39
{
37
- $ this ->setSupportedLocales (['en ' , 'nl ' , 'fr ' , 'de ' , 'es ' , 'it ' ]);
38
- $ this ->setSessionLocale ('fr ' );
39
- $ this ->setBrowserLocales ('it ' );
40
+ $ this ->setSupportedLocales (['en ' , 'nl ' ]);
40
41
$ this ->setAppLocale ('en ' );
41
- $ cookie = 'de ' ;
42
42
43
- Route:: group ([
44
- ' locale ' => ' nl ' ,
45
- ] , function () {
43
+ $ routeAction = [ ' locale ' => ' nl ' ];
44
+
45
+ Route:: group ( $ routeAction , function () {
46
46
Route::get ('some/route ' , function () {
47
47
return App::getLocale ();
48
48
})->middleware (['web ' , SetLocale::class]);
49
49
});
50
50
51
- $ response = $ this ->getWithCookie ('some/route ' , $ cookie );
51
+ $ response = $ this ->get ('some/route ' );
52
52
53
53
$ response ->assertSessionHas ($ this ->sessionKey , 'nl ' );
54
54
$ response ->assertCookie ($ this ->cookieName , 'nl ' );
@@ -58,17 +58,14 @@ public function it_looks_for_a_locale_in_a_custom_route_action()
58
58
/** @test */
59
59
public function it_looks_for_a_locale_in_the_url ()
60
60
{
61
- $ this ->setSupportedLocales (['en ' , 'nl ' , 'fr ' , 'de ' , 'es ' , 'it ' ]);
62
- $ this ->setSessionLocale ('fr ' );
63
- $ this ->setBrowserLocales ('it ' );
61
+ $ this ->setSupportedLocales (['en ' , 'nl ' ]);
64
62
$ this ->setAppLocale ('en ' );
65
- $ cookie = 'de ' ;
66
63
67
64
Route::get ('nl/some/route ' , function () {
68
65
return App::getLocale ();
69
66
})->middleware (['web ' , SetLocale::class]);
70
67
71
- $ response = $ this ->getWithCookie ('nl/some/route ' , $ cookie );
68
+ $ response = $ this ->get ('nl/some/route ' );
72
69
73
70
$ response ->assertSessionHas ($ this ->sessionKey , 'nl ' );
74
71
$ response ->assertCookie ($ this ->cookieName , 'nl ' );
@@ -78,19 +75,16 @@ public function it_looks_for_a_locale_in_the_url()
78
75
/** @test */
79
76
public function you_can_configure_which_segment_to_use_as_locale ()
80
77
{
81
- $ this ->setSupportedLocales (['en ' , 'nl ' , 'fr ' , 'de ' , 'es ' , 'it ' ]);
82
- $ this ->setSessionLocale ('fr ' );
83
- $ this ->setBrowserLocales ('it ' );
78
+ $ this ->setSupportedLocales (['en ' , 'nl ' ]);
84
79
$ this ->setAppLocale ('en ' );
85
- $ cookie = 'de ' ;
86
80
87
81
Config::set ('localizer.url-segment ' , 2 );
88
82
89
83
Route::get ('some/nl/route ' , function () {
90
84
return App::getLocale ();
91
85
})->middleware (['web ' , SetLocale::class]);
92
86
93
- $ response = $ this ->getWithCookie ('some/nl/route ' , $ cookie );
87
+ $ response = $ this ->get ('some/nl/route ' );
94
88
95
89
$ response ->assertSessionHas ($ this ->sessionKey , 'nl ' );
96
90
$ response ->assertCookie ($ this ->cookieName , 'nl ' );
@@ -103,7 +97,6 @@ public function it_looks_for_custom_slugs()
103
97
$ this ->setSupportedLocales ([
104
98
'en ' => 'english ' ,
105
99
'nl ' => 'dutch ' ,
106
- 'fr ' => 'french ' ,
107
100
]);
108
101
$ this ->setAppLocale ('en ' );
109
102
@@ -124,7 +117,6 @@ public function you_can_use_multiple_slugs_for_a_locale()
124
117
$ this ->setSupportedLocales ([
125
118
'en ' => 'english ' ,
126
119
'nl ' => ['dutch ' , 'nederlands ' ],
127
- 'fr ' => 'french ' ,
128
120
]);
129
121
$ this ->setAppLocale ('en ' );
130
122
@@ -155,13 +147,10 @@ public function it_looks_for_custom_domains()
155
147
$ this ->setSupportedLocales ([
156
148
'en ' => 'english.test ' ,
157
149
'nl ' => 'dutch.test ' ,
158
- 'fr ' => 'french.test ' ,
159
150
]);
160
151
$ this ->setAppLocale ('en ' );
161
152
162
- Route::group ([
163
- 'domain ' => 'dutch.test ' ,
164
- ], function () {
153
+ Route::group (['domain ' => 'dutch.test ' ], function () {
165
154
Route::get ('some/route ' , function () {
166
155
return App::getLocale ();
167
156
})->middleware (['web ' , SetLocale::class]);
@@ -180,21 +169,16 @@ public function you_can_use_multiple_domains_for_a_locale()
180
169
$ this ->setSupportedLocales ([
181
170
'en ' => 'english.test ' ,
182
171
'nl ' => ['dutch.test ' , 'nederlands.test ' ],
183
- 'fr ' => 'french.test ' ,
184
172
]);
185
173
$ this ->setAppLocale ('en ' );
186
174
187
- Route::group ([
188
- 'domain ' => 'dutch.test ' ,
189
- ], function () {
175
+ Route::group (['domain ' => 'dutch.test ' ], function () {
190
176
Route::get ('some/route ' , function () {
191
177
return App::getLocale ();
192
178
})->middleware (['web ' , SetLocale::class]);
193
179
});
194
180
195
- Route::group ([
196
- 'domain ' => 'nederlands.test ' ,
197
- ], function () {
181
+ Route::group (['domain ' => 'nederlands.test ' ], function () {
198
182
Route::get ('some/route ' , function () {
199
183
return App::getLocale ();
200
184
})->middleware (['web ' , SetLocale::class]);
@@ -216,32 +200,27 @@ public function you_can_use_multiple_domains_for_a_locale()
216
200
/** @test */
217
201
public function it_checks_for_a_configured_omitted_locale ()
218
202
{
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 ' ]);
223
204
$ this ->setAppLocale ('en ' );
224
- $ cookie = 'de ' ;
205
+
206
+ $ this ->setOmittedLocale ('nl ' );
225
207
226
208
Route::get ('some/route ' , function () {
227
209
return App::getLocale ();
228
210
})->middleware (['web ' , SetLocale::class]);
229
211
230
- $ response = $ this ->getWithCookie ('some/route ' , $ cookie );
212
+ $ response = $ this ->get ('some/route ' );
231
213
232
214
$ response ->assertSessionHas ($ this ->sessionKey , 'nl ' );
233
215
$ response ->assertCookie ($ this ->cookieName , 'nl ' );
234
216
$ this ->assertEquals ('nl ' , $ response ->original );
235
217
}
236
218
237
219
/** @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 ()
239
221
{
240
- $ this ->setSupportedLocales (['en ' , 'nl ' , 'fr ' , 'de ' , 'es ' , 'it ' ]);
241
- $ this ->setSessionLocale ('fr ' );
242
- $ this ->setBrowserLocales ('it ' );
222
+ $ this ->setSupportedLocales (['en ' , 'nl ' ]);
243
223
$ this ->setAppLocale ('en ' );
244
- $ cookie = 'de ' ;
245
224
246
225
$ attribute = Config::get ('localizer.user-attribute ' );
247
226
$ user = new User ();
@@ -251,7 +230,7 @@ public function it_looks_for_a_locale_on_the_authenticated_user_if_not_found_in_
251
230
return App::getLocale ();
252
231
})->middleware (['web ' , SetLocale::class]);
253
232
254
- $ response = $ this ->actingAs ($ user )->getWithCookie ('some/route ' , $ cookie );
233
+ $ response = $ this ->actingAs ($ user )->get ('some/route ' );
255
234
256
235
$ response ->assertSessionHas ($ this ->sessionKey , 'nl ' );
257
236
$ response ->assertCookie ($ this ->cookieName , 'nl ' );
@@ -262,125 +241,118 @@ public function it_looks_for_a_locale_on_the_authenticated_user_if_not_found_in_
262
241
public function it_will_bypass_missing_attribute_exception_if_the_locale_attribute_is_missing_on_the_user_model ()
263
242
{
264
243
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. ' );
266
245
}
267
246
268
- $ this ->setSupportedLocales (['en ' , 'nl ' , 'fr ' , 'de ' , 'es ' , 'it ' ]);
269
- $ this ->setSessionLocale ('fr ' );
270
- $ this ->setBrowserLocales ('it ' );
247
+ $ this ->setSupportedLocales (['en ' , 'nl ' ]);
271
248
$ this ->setAppLocale ('en ' );
272
- $ cookie = 'de ' ;
273
249
274
250
$ user = new User ();
275
- $ user ->exists = true ;
251
+ $ user ->exists = true ; // exception is only thrown if user "exists"
276
252
Model::preventAccessingMissingAttributes ();
277
253
278
254
Route::get ('some/route ' , function () {
279
255
return App::getLocale ();
280
256
})->middleware (['web ' , SetLocale::class]);
281
257
282
- $ response = $ this ->actingAs ($ user )->getWithCookie ('some/route ' , $ cookie );
258
+ $ response = $ this ->actingAs ($ user )->get ('some/route ' );
283
259
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 );
287
263
}
288
264
289
265
/** @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 ()
291
267
{
292
- $ this ->setSupportedLocales (['en ' , 'nl ' , 'fr ' , 'de ' , 'es ' , 'it ' ]);
293
- $ this ->setSessionLocale ('fr ' );
294
- $ this ->setBrowserLocales ('it ' );
268
+ $ this ->setSupportedLocales (['en ' , 'nl ' ]);
295
269
$ this ->setAppLocale ('en ' );
296
- $ cookie = 'de ' ;
270
+
271
+ $ this ->setSessionLocale ('nl ' );
297
272
298
273
Route::get ('some/route ' , function () {
299
274
return App::getLocale ();
300
275
})->middleware (['web ' , SetLocale::class]);
301
276
302
- $ response = $ this ->getWithCookie ('some/route ' , $ cookie );
277
+ $ response = $ this ->get ('some/route ' );
303
278
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 );
307
282
}
308
283
309
284
/** @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 ()
311
286
{
312
- $ this ->setSupportedLocales (['en ' , 'nl ' , 'fr ' , 'de ' , 'es ' , 'it ' ]);
313
- $ this ->setSessionLocale (null );
314
- $ this ->setBrowserLocales ('it ' );
287
+ $ this ->setSupportedLocales (['en ' , 'nl ' ]);
315
288
$ this ->setAppLocale ('en ' );
316
- $ cookie = 'de ' ;
289
+
290
+ $ cookie = 'nl ' ;
317
291
318
292
Route::get ('some/route ' , function () {
319
293
return App::getLocale ();
320
294
})->middleware (['web ' , SetLocale::class]);
321
295
322
296
$ response = $ this ->getWithCookie ('some/route ' , $ cookie );
323
297
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 );
327
301
}
328
302
329
303
/** @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 ()
331
305
{
332
- $ this ->setSupportedLocales (['en ' , 'nl ' , 'fr ' , 'de ' , 'es ' , 'it ' ]);
333
- $ this ->setSessionLocale (null );
334
- $ this ->setBrowserLocales ('it ' );
306
+ $ this ->setSupportedLocales (['en ' , 'nl ' ]);
335
307
$ this ->setAppLocale ('en ' );
336
308
309
+ $ this ->setBrowserLocales ('nl ' );
310
+
337
311
Route::get ('some/route ' , function () {
338
312
return App::getLocale ();
339
313
})->middleware (['web ' , SetLocale::class]);
340
314
341
315
$ response = $ this ->get ('some/route ' );
342
316
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 );
346
320
}
347
321
348
322
/** @test */
349
323
public function it_returns_the_best_match_when_a_browser_locale_is_used ()
350
324
{
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 ' ]);
354
326
$ this ->setAppLocale ('en ' );
355
327
328
+ $ this ->setBrowserLocales ('de,fr;q=0.4,nl-BE;q=0.8 ' );
329
+
356
330
Route::get ('some/route ' , function () {
357
331
return App::getLocale ();
358
332
})->middleware (['web ' , SetLocale::class]);
359
333
360
334
$ response = $ this ->get ('some/route ' );
361
335
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 );
365
339
}
366
340
367
341
/** @test */
368
- public function it_defaults_to_the_current_app_locale ()
342
+ public function it_looks_for_the_current_app_locale ()
369
343
{
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 ' );
374
346
375
347
Route::get ('some/route ' , function () {
376
348
return App::getLocale ();
377
349
})->middleware (['web ' , SetLocale::class]);
378
350
379
351
$ response = $ this ->get ('some/route ' );
380
352
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 );
384
356
}
385
357
386
358
/** @test */
0 commit comments