create(['name' => 'Eero Esimerkki']); $this->actingAs($user) ->from(route('home')) ->post(route('locale.update'), ['locale' => 'en']) ->assertRedirect(route('home')); expect($user->fresh()->locale)->toBe(Locale::English); // A new request loads the user again from the database. $this->actingAs($user->fresh()) ->get(route('home')) ->assertOk() ->assertSee('lang="en"', false) ->assertSee('Sign out'); }); it('keeps the language chosen on the signed-out pages in the session', function () { $this->from(route('login')) ->post(route('locale.update'), ['locale' => 'en']) ->assertRedirect(route('login')) ->assertSessionHas('locale', 'en'); $this->get(route('login')) ->assertOk() ->assertSee('lang="en"', false); }); it('uses the account language over the one in the session', function () { $user = User::factory()->create(['locale' => 'fi']); $this->actingAs($user) ->withSession(['locale' => 'en']) ->get(route('home')) ->assertSee('lang="fi"', false) ->assertSee('Kirjaudu ulos'); }); it('keeps the language on the login page after logging out', function () { $user = User::factory()->create(['locale' => 'en']); $this->actingAs($user)->post(route('logout'))->assertSessionHas('locale', 'en'); }); it('rejects an unknown language', function () { $user = User::factory()->create(); $this->actingAs($user) ->post(route('locale.update'), ['locale' => 'sv']) ->assertSessionHasErrors('locale'); expect($user->fresh()->locale)->toBe(Locale::Finnish); }); it('sends the set-password email in the language of the user', function () { Notification::fake(); $user = User::factory()->create(['locale' => 'en']); $user->notify(new ResetPassword('token')); Notification::assertSentTo($user, ResetPassword::class, function (ResetPassword $notification, array $channels, User $notifiable, ?string $locale) { return $locale === 'en'; }); });