@@ -36,13 +36,13 @@ public function it_looks_for_a_locale_in_the_url_first()
36
36
$ this ->setSessionLocale ('fr ' );
37
37
$ this ->setBrowserLocales ('it ' );
38
38
$ this ->setAppLocale ('en ' );
39
- $ cookie = [ $ this -> cookieName => Crypt:: encrypt ( 'de ' , false )] ;
39
+ $ cookie = 'de ' ;
40
40
41
41
Route::get ('nl/some/route ' , function () {
42
42
return App::getLocale ();
43
43
})->middleware (['web ' , SetLocale::class]);
44
44
45
- $ response = $ this ->call ( ' GET ' , ' nl/some/route ', [] , $ cookie );
45
+ $ response = $ this ->getWithCookie ( ' nl/some/route ' , $ cookie );
46
46
47
47
$ response ->assertSessionHas ($ this ->sessionKey , 'nl ' );
48
48
$ response ->assertCookie ($ this ->cookieName , 'nl ' );
@@ -56,15 +56,15 @@ public function you_can_configure_which_segment_to_use_as_locale()
56
56
$ this ->setSessionLocale ('fr ' );
57
57
$ this ->setBrowserLocales ('it ' );
58
58
$ this ->setAppLocale ('en ' );
59
- $ cookie = [ $ this -> cookieName => Crypt:: encrypt ( 'de ' , false )] ;
59
+ $ cookie = 'de ' ;
60
60
61
61
Config::set ('localizer.url-segment ' , 2 );
62
62
63
63
Route::get ('some/nl/route ' , function () {
64
64
return App::getLocale ();
65
65
})->middleware (['web ' , SetLocale::class]);
66
66
67
- $ response = $ this ->call ( ' GET ' , ' some/nl/route ', [] , $ cookie );
67
+ $ response = $ this ->getWithCookie ( ' some/nl/route ' , $ cookie );
68
68
69
69
$ response ->assertSessionHas ($ this ->sessionKey , 'nl ' );
70
70
$ response ->assertCookie ($ this ->cookieName , 'nl ' );
@@ -78,13 +78,13 @@ public function it_looks_for_a_locale_in_the_session_if_not_found_in_the_url()
78
78
$ this ->setSessionLocale ('fr ' );
79
79
$ this ->setBrowserLocales ('it ' );
80
80
$ this ->setAppLocale ('en ' );
81
- $ cookie = [ $ this -> cookieName => Crypt:: encrypt ( 'de ' , false )] ;
81
+ $ cookie = 'de ' ;
82
82
83
83
Route::get ('some/route ' , function () {
84
84
return App::getLocale ();
85
85
})->middleware (['web ' , SetLocale::class]);
86
86
87
- $ response = $ this ->call ( ' GET ' , ' some/route ', [] , $ cookie );
87
+ $ response = $ this ->getWithCookie ( ' some/route ' , $ cookie );
88
88
89
89
$ response ->assertSessionHas ($ this ->sessionKey , 'fr ' );
90
90
$ response ->assertCookie ($ this ->cookieName , 'fr ' );
@@ -98,13 +98,13 @@ public function it_looks_for_a_locale_in_a_cookie_if_not_found_in_the_url_or_ses
98
98
$ this ->setSessionLocale (null );
99
99
$ this ->setBrowserLocales ('it ' );
100
100
$ this ->setAppLocale ('en ' );
101
- $ cookie = [ $ this -> cookieName => Crypt:: encrypt ( 'de ' , false )] ;
101
+ $ cookie = 'de ' ;
102
102
103
103
Route::get ('some/route ' , function () {
104
104
return App::getLocale ();
105
105
})->middleware (['web ' , SetLocale::class]);
106
106
107
- $ response = $ this ->call ( ' GET ' , ' some/route ', [] , $ cookie );
107
+ $ response = $ this ->getWithCookie ( ' some/route ' , $ cookie );
108
108
109
109
$ response ->assertSessionHas ($ this ->sessionKey , 'de ' );
110
110
$ response ->assertCookie ($ this ->cookieName , 'de ' );
@@ -118,13 +118,12 @@ public function it_looks_for_a_locale_in_the_browser_if_not_found_in_the_url_or_
118
118
$ this ->setSessionLocale (null );
119
119
$ this ->setBrowserLocales ('it ' );
120
120
$ this ->setAppLocale ('en ' );
121
- $ cookie = [];
122
121
123
122
Route::get ('some/route ' , function () {
124
123
return App::getLocale ();
125
124
})->middleware (['web ' , SetLocale::class]);
126
125
127
- $ response = $ this ->call ( ' GET ' , ' some/route ', [], $ cookie );
126
+ $ response = $ this ->get ( ' some/route ' );
128
127
129
128
$ response ->assertSessionHas ($ this ->sessionKey , 'it ' );
130
129
$ response ->assertCookie ($ this ->cookieName , 'it ' );
@@ -138,13 +137,12 @@ public function it_returns_the_best_match_when_a_browser_locale_is_used()
138
137
$ this ->setSessionLocale (null );
139
138
$ this ->setBrowserLocales ('cs,it-IT;q=0.4,es;q=0.8 ' );
140
139
$ this ->setAppLocale ('en ' );
141
- $ cookie = [];
142
140
143
141
Route::get ('some/route ' , function () {
144
142
return App::getLocale ();
145
143
})->middleware (['web ' , SetLocale::class]);
146
144
147
- $ response = $ this ->call ( ' GET ' , ' some/route ', [], $ cookie );
145
+ $ response = $ this ->get ( ' some/route ' );
148
146
149
147
$ response ->assertSessionHas ($ this ->sessionKey , 'es ' );
150
148
$ response ->assertCookie ($ this ->cookieName , 'es ' );
@@ -158,13 +156,12 @@ public function it_defaults_to_the_current_app_locale()
158
156
$ this ->setSessionLocale (null );
159
157
$ this ->setBrowserLocales (null );
160
158
$ this ->setAppLocale ('en ' );
161
- $ cookie = [];
162
159
163
160
Route::get ('some/route ' , function () {
164
161
return App::getLocale ();
165
162
})->middleware (['web ' , SetLocale::class]);
166
163
167
- $ response = $ this ->call ( ' GET ' , ' some/route ', [], $ cookie );
164
+ $ response = $ this ->get ( ' some/route ' );
168
165
169
166
$ response ->assertSessionHas ($ this ->sessionKey , 'en ' );
170
167
$ response ->assertCookie ($ this ->cookieName , 'en ' );
@@ -228,4 +225,19 @@ protected function setBrowserLocales($locales)
228
225
229
226
return $ this ;
230
227
}
228
+
229
+ /**
230
+ * Perform a GET request when the given cookie was previously set.
231
+ *
232
+ * @param string $url
233
+ * @param string $cookie
234
+ *
235
+ * @return \Illuminate\Testing\TestResponse
236
+ */
237
+ protected function getWithCookie ($ url , $ cookie )
238
+ {
239
+ return App::version () < 6
240
+ ? $ this ->call ('GET ' , $ url , [], [$ this ->cookieName => Crypt::encrypt ($ cookie , false )])
241
+ : $ this ->withCookie ($ this ->cookieName , $ cookie )->get ($ url );
242
+ }
231
243
}
0 commit comments