Closed dizco closed 1 year ago
Describe the bug This line: https://github.com/mcamara/laravel-localization/blob/24af7ee06e48f45c884018f8ab33332bbb210c03/src/Mcamara/LaravelLocalization/LaravelLocalization.php#L575
When running a Dusk test, the value of PHP_SAPI is cli, therefore app->runningInConsole() is true. However, in reality we still want content negotiation to happen and not only use the default language.
PHP_SAPI
cli
app->runningInConsole()
To Reproduce Steps to reproduce the behavior:
Create a default Laravel app with Dusk
Add laravel-localization with a default route /
/
// config > laravellocalization.php 'supportedLocales' => [ 'en' => ['name' => 'English', 'script' => 'Latn', 'native' => 'English', 'regional' => 'en_CA'], 'fr' => ['name' => 'French', 'script' => 'Latn', 'native' => 'français', 'regional' => 'fr_CA'] ], 'hideDefaultLocaleInURL' => false, 'useAcceptLanguageHeader' => true, 'localesMapping' => [],
// web.php Route::group( [ 'prefix' => LaravelLocalization::setLocale(), 'middleware' => ['localize', 'localeCookieRedirect'], ], function () { Route::get(LaravelLocalization::transRoute('routes.index'), [WebController::class, 'getIndex']); } );
Override the Dusk driver
protected function driver(): RemoteWebDriver { $options = (new ChromeOptions)->addArguments(collect([ '--window-size=1920,1080', '--accept-lang=fr', ])->unless($this->hasHeadlessDisabled(), function ($items) { return $items->merge([ '--disable-gpu', '--headless', ]); })->all()); return RemoteWebDriver::create( $_ENV['DUSK_DRIVER_URL'] ?? 'http://localhost:9515', DesiredCapabilities::chrome()->setCapability( ChromeOptions::CAPABILITY, $options ) ); }
Run a dusk test
public function testHomePageRedirectUsesBrowserAcceptLanguage() { $this->browse(function (Browser $browser) { $browser->visit('/'); $browser->assertPathIs('/fr'); }); }
Expected behavior When running a dusk test, it should not change the content negotiation.
More info:
Route::groups
supportedLocales
useAcceptLanguageHeader
hideDefaultLocaleInURL
Additional context Add any other context about the problem here.
Closing this issue sorry, I believe I misunderstood the issue I am having.
Describe the bug This line: https://github.com/mcamara/laravel-localization/blob/24af7ee06e48f45c884018f8ab33332bbb210c03/src/Mcamara/LaravelLocalization/LaravelLocalization.php#L575
When running a Dusk test, the value of
PHP_SAPI
iscli
, thereforeapp->runningInConsole()
is true. However, in reality we still want content negotiation to happen and not only use the default language.To Reproduce Steps to reproduce the behavior:
Create a default Laravel app with Dusk
Add laravel-localization with a default route
/
Override the Dusk driver
Run a dusk test
Expected behavior When running a dusk test, it should not change the content negotiation.
More info:
Route::groups
supportedLocales
,useAcceptLanguageHeader
andhideDefaultLocaleInURL
).Additional context Add any other context about the problem here.