@@ -101,6 +101,7 @@ public function it_allows_for_localized_route_model_binding()
101101 public function it_does_not_detect_the_preferred_locale_with_localizer_for_localized_routes ()
102102 {
103103 $ this ->setSupportedLocales (['en ' , 'nl ' ]);
104+ $ this ->setUseLocalizer (true );
104105
105106 $ localizer = Mockery::mock (Localizer::class);
106107 $ localizer ->shouldReceive ('setSupportedLocales ' )->with (['en ' , 'nl ' ]);
@@ -122,6 +123,7 @@ public function it_does_not_detect_the_preferred_locale_with_localizer_for_local
122123 public function it_detects_the_preferred_locale_with_localizer_for_non_localized_routes ()
123124 {
124125 $ this ->setSupportedLocales (['en ' , 'nl ' ]);
126+ $ this ->setUseLocalizer (true );
125127
126128 $ localizer = Mockery::mock (Localizer::class);
127129 $ localizer ->shouldReceive ('setSupportedLocales ' )->with (['en ' , 'nl ' ]);
@@ -136,4 +138,67 @@ public function it_detects_the_preferred_locale_with_localizer_for_non_localized
136138
137139 $ this ->call ('GET ' , '/non-localized-route ' )->assertOk ();
138140 }
141+
142+ /** @test */
143+ public function it_does_not_use_localizer_when_disabled ()
144+ {
145+ $ this ->setSupportedLocales (['en ' , 'nl ' ]);
146+ $ this ->setUseLocalizer (false );
147+
148+ $ localizer = Mockery::mock (Localizer::class);
149+ $ localizer ->shouldNotReceive ('setSupportedLocales ' );
150+ $ localizer ->shouldNotReceive ('detect ' );
151+ $ localizer ->shouldNotReceive ('store ' );
152+
153+ App::instance (Localizer::class, $ localizer );
154+
155+ Route::localized (function () {
156+ Route::get ('localized-route ' , function () {})
157+ ->name ('localized.route ' )
158+ ->middleware (['web ' , SetLocale::class]);
159+ });
160+
161+ Route::get ('/non-localized-route ' , function () {})
162+ ->name ('non-localized.route ' )
163+ ->middleware (['web ' , SetLocale::class]);
164+
165+ $ this ->call ('GET ' , '/non-localized-route ' )->assertOk ();
166+ $ this ->call ('GET ' , '/en/localized-route ' )->assertOk ();
167+ }
168+
169+ /** @test */
170+ public function it_still_sets_the_app_locale_for_localized_routes_if_localizer_is_disabled ()
171+ {
172+ $ this ->setSupportedLocales (['en ' ]);
173+ $ this ->setUseLocalizer (false );
174+
175+ App::setLocale ('fr ' );
176+
177+ Route::localized (function () {
178+ Route::get ('localized-route ' , function () {
179+ return App::getLocale ();
180+ })->name ('localized.route ' )->middleware (['web ' , SetLocale::class]);
181+ });
182+
183+ $ response = $ this ->call ('GET ' , '/en/localized-route ' );
184+
185+ $ this ->assertEquals ('en ' , $ response ->original );
186+ }
187+
188+ /** @test */
189+ public function it_does_not_set_the_app_locale_for_non_localized_routes_if_localizer_is_disabled ()
190+ {
191+ $ this ->setSupportedLocales (['en ' , 'nl ' ]);
192+ $ this ->setUseLocalizer (false );
193+
194+ App::setLocale ('fr ' );
195+
196+ Route::get ('/non-localized-route ' , function () {
197+ return App::getLocale ();
198+ })->name ('non-localized.route ' )->middleware (['web ' , SetLocale::class]);
199+
200+ $ response = $ this ->call ('GET ' , '/non-localized-route ' );
201+
202+ $ this ->assertEquals ('fr ' , $ response ->original );
203+ }
139204}
0 commit comments