Keep the chosen language across sign-in and forced sign-out
A language picked on a signed-out page is now stored on the account when the user signs in (StoreLocaleChosenBeforeLogin), so the app does not switch back to the account default. EnsureAccountIsUsable keeps the user's language for the login page when it ends a disabled account's session. ChangePreferredLocale runs in a transaction like the other use cases, the language names come from layout.languages instead of the Locale enum, and the translation test also compares fi.json with en.json and rejects English files without a Finnish counterpart. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -5,6 +5,7 @@ use App\Modules\Users\Domain\Enums\Locale;
|
||||
use Illuminate\Auth\Notifications\ResetPassword;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
use Livewire\Livewire;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
@@ -53,6 +54,45 @@ it('keeps the language on the login page after logging out', function () {
|
||||
$this->actingAs($user)->post(route('logout'))->assertSessionHas('locale', 'en');
|
||||
});
|
||||
|
||||
it('stores the language chosen on the login page on the account when signing in', function () {
|
||||
$user = User::factory()->create(['email' => '[email protected]', 'locale' => 'fi']);
|
||||
|
||||
$this->post(route('locale.update'), ['locale' => 'en'])->assertSessionHas('locale_chosen', true);
|
||||
|
||||
Livewire::test('users::login')
|
||||
->set('email', '[email protected]')
|
||||
->set('password', 'password')
|
||||
->call('login')
|
||||
->assertHasNoErrors();
|
||||
|
||||
expect($user->fresh()->locale)->toBe(Locale::English);
|
||||
});
|
||||
|
||||
it('keeps the account language when the language was not chosen before signing in', function () {
|
||||
$user = User::factory()->create(['email' => '[email protected]', 'locale' => 'en']);
|
||||
|
||||
// The login page after logging out of a Finnish account, without a choice of its own.
|
||||
$this->withSession(['locale' => 'fi']);
|
||||
|
||||
Livewire::test('users::login')
|
||||
->set('email', '[email protected]')
|
||||
->set('password', 'password')
|
||||
->call('login')
|
||||
->assertHasNoErrors();
|
||||
|
||||
expect($user->fresh()->locale)->toBe(Locale::English);
|
||||
});
|
||||
|
||||
it('keeps the language on the login page when a disabled account is signed out', function () {
|
||||
$user = User::factory()->create(['locale' => 'en']);
|
||||
$this->actingAs($user);
|
||||
$user->update(['is_active' => false]);
|
||||
|
||||
$this->get(route('home'))
|
||||
->assertRedirect(route('login', ['access' => 'ended']))
|
||||
->assertSessionHas('locale', 'en');
|
||||
});
|
||||
|
||||
it('rejects an unknown language', function () {
|
||||
$user = User::factory()->create();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user