@@ -36,13 +36,13 @@ public function it_looks_for_a_locale_in_the_url_first()
3636 $ this ->setSessionLocale ('fr ' );
3737 $ this ->setBrowserLocales ('it ' );
3838 $ this ->setAppLocale ('en ' );
39- $ cookie = [ $ this -> cookieName => Crypt:: encrypt ( 'de ' , false )] ;
39+ $ cookie = 'de ' ;
4040
4141 Route::get ('nl/some/route ' , function () {
4242 return App::getLocale ();
4343 })->middleware (['web ' , SetLocale::class]);
4444
45- $ response = $ this ->call ( ' GET ' , ' nl/some/route ', [] , $ cookie );
45+ $ response = $ this ->getWithCookie ( ' nl/some/route ' , $ cookie );
4646
4747 $ response ->assertSessionHas ($ this ->sessionKey , 'nl ' );
4848 $ response ->assertCookie ($ this ->cookieName , 'nl ' );
@@ -56,15 +56,15 @@ public function you_can_configure_which_segment_to_use_as_locale()
5656 $ this ->setSessionLocale ('fr ' );
5757 $ this ->setBrowserLocales ('it ' );
5858 $ this ->setAppLocale ('en ' );
59- $ cookie = [ $ this -> cookieName => Crypt:: encrypt ( 'de ' , false )] ;
59+ $ cookie = 'de ' ;
6060
6161 Config::set ('localizer.url-segment ' , 2 );
6262
6363 Route::get ('some/nl/route ' , function () {
6464 return App::getLocale ();
6565 })->middleware (['web ' , SetLocale::class]);
6666
67- $ response = $ this ->call ( ' GET ' , ' some/nl/route ', [] , $ cookie );
67+ $ response = $ this ->getWithCookie ( ' some/nl/route ' , $ cookie );
6868
6969 $ response ->assertSessionHas ($ this ->sessionKey , 'nl ' );
7070 $ 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()
7878 $ this ->setSessionLocale ('fr ' );
7979 $ this ->setBrowserLocales ('it ' );
8080 $ this ->setAppLocale ('en ' );
81- $ cookie = [ $ this -> cookieName => Crypt:: encrypt ( 'de ' , false )] ;
81+ $ cookie = 'de ' ;
8282
8383 Route::get ('some/route ' , function () {
8484 return App::getLocale ();
8585 })->middleware (['web ' , SetLocale::class]);
8686
87- $ response = $ this ->call ( ' GET ' , ' some/route ', [] , $ cookie );
87+ $ response = $ this ->getWithCookie ( ' some/route ' , $ cookie );
8888
8989 $ response ->assertSessionHas ($ this ->sessionKey , 'fr ' );
9090 $ 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
9898 $ this ->setSessionLocale (null );
9999 $ this ->setBrowserLocales ('it ' );
100100 $ this ->setAppLocale ('en ' );
101- $ cookie = [ $ this -> cookieName => Crypt:: encrypt ( 'de ' , false )] ;
101+ $ cookie = 'de ' ;
102102
103103 Route::get ('some/route ' , function () {
104104 return App::getLocale ();
105105 })->middleware (['web ' , SetLocale::class]);
106106
107- $ response = $ this ->call ( ' GET ' , ' some/route ', [] , $ cookie );
107+ $ response = $ this ->getWithCookie ( ' some/route ' , $ cookie );
108108
109109 $ response ->assertSessionHas ($ this ->sessionKey , 'de ' );
110110 $ 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_
118118 $ this ->setSessionLocale (null );
119119 $ this ->setBrowserLocales ('it ' );
120120 $ this ->setAppLocale ('en ' );
121- $ cookie = [];
122121
123122 Route::get ('some/route ' , function () {
124123 return App::getLocale ();
125124 })->middleware (['web ' , SetLocale::class]);
126125
127- $ response = $ this ->call ( ' GET ' , ' some/route ', [], $ cookie );
126+ $ response = $ this ->get ( ' some/route ' );
128127
129128 $ response ->assertSessionHas ($ this ->sessionKey , 'it ' );
130129 $ response ->assertCookie ($ this ->cookieName , 'it ' );
@@ -138,13 +137,12 @@ public function it_returns_the_best_match_when_a_browser_locale_is_used()
138137 $ this ->setSessionLocale (null );
139138 $ this ->setBrowserLocales ('cs,it-IT;q=0.4,es;q=0.8 ' );
140139 $ this ->setAppLocale ('en ' );
141- $ cookie = [];
142140
143141 Route::get ('some/route ' , function () {
144142 return App::getLocale ();
145143 })->middleware (['web ' , SetLocale::class]);
146144
147- $ response = $ this ->call ( ' GET ' , ' some/route ', [], $ cookie );
145+ $ response = $ this ->get ( ' some/route ' );
148146
149147 $ response ->assertSessionHas ($ this ->sessionKey , 'es ' );
150148 $ response ->assertCookie ($ this ->cookieName , 'es ' );
@@ -158,13 +156,12 @@ public function it_defaults_to_the_current_app_locale()
158156 $ this ->setSessionLocale (null );
159157 $ this ->setBrowserLocales (null );
160158 $ this ->setAppLocale ('en ' );
161- $ cookie = [];
162159
163160 Route::get ('some/route ' , function () {
164161 return App::getLocale ();
165162 })->middleware (['web ' , SetLocale::class]);
166163
167- $ response = $ this ->call ( ' GET ' , ' some/route ', [], $ cookie );
164+ $ response = $ this ->get ( ' some/route ' );
168165
169166 $ response ->assertSessionHas ($ this ->sessionKey , 'en ' );
170167 $ response ->assertCookie ($ this ->cookieName , 'en ' );
@@ -228,4 +225,19 @@ protected function setBrowserLocales($locales)
228225
229226 return $ this ;
230227 }
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+ }
231243}
0 commit comments