updateWorkspaceSetting( actor: $user, workspace: $workspace, domain: LocaleResolver::SETTING_DOMAIN, key: LocaleResolver::SETTING_DEFAULT_LOCALE, value: 'de', ); $this->actingAs($user) ->withSession([WorkspaceContext::SESSION_KEY => (int) $workspace->getKey()]) ->getJson('/localization/context') ->assertSuccessful() ->assertJsonPath('locale', 'de') ->assertJsonPath('source', LocaleResolver::SOURCE_WORKSPACE_DEFAULT); $this->actingAs($user) ->withSession([WorkspaceContext::SESSION_KEY => (int) $workspace->getKey()]) ->post(route('localization.preference.update'), ['preferred_locale' => 'en']) ->assertRedirect(); expect($user->refresh()->preferred_locale)->toBe('en'); $this->actingAs($user) ->withSession([WorkspaceContext::SESSION_KEY => (int) $workspace->getKey()]) ->getJson('/localization/context') ->assertSuccessful() ->assertJsonPath('locale', 'en') ->assertJsonPath('source', LocaleResolver::SOURCE_USER_PREFERENCE); $this->actingAs($user) ->withSession([WorkspaceContext::SESSION_KEY => (int) $workspace->getKey()]) ->post(route('localization.preference.update'), ['preferred_locale' => '']) ->assertRedirect(); expect($user->refresh()->preferred_locale)->toBeNull(); $this->actingAs($user) ->withSession([WorkspaceContext::SESSION_KEY => (int) $workspace->getKey()]) ->getJson('/localization/context') ->assertSuccessful() ->assertJsonPath('locale', 'de') ->assertJsonPath('source', LocaleResolver::SOURCE_WORKSPACE_DEFAULT); }); it('allows temporary overrides to win until cleared', function (): void { [$workspace, $user] = localizationWorkspaceMember(); $user->forceFill(['preferred_locale' => 'en'])->save(); $this->actingAs($user) ->withSession([WorkspaceContext::SESSION_KEY => (int) $workspace->getKey()]) ->post(route('localization.override.update'), ['locale' => 'de']) ->assertRedirect(); expect(session(LocaleResolver::SESSION_OVERRIDE_KEY))->toBe('de'); $this->actingAs($user) ->withSession([ WorkspaceContext::SESSION_KEY => (int) $workspace->getKey(), LocaleResolver::SESSION_OVERRIDE_KEY => 'de', ]) ->getJson('/localization/context') ->assertSuccessful() ->assertJsonPath('locale', 'de') ->assertJsonPath('source', LocaleResolver::SOURCE_EXPLICIT_OVERRIDE); $this->actingAs($user) ->withSession([ WorkspaceContext::SESSION_KEY => (int) $workspace->getKey(), LocaleResolver::SESSION_OVERRIDE_KEY => 'de', ]) ->delete(route('localization.override.clear')) ->assertRedirect(); expect(session(LocaleResolver::SESSION_OVERRIDE_KEY))->toBeNull(); }); it('returns to the customer review workspace filter when the locale override changes', function (): void { $tenant = Tenant::factory()->create(); [$user, $tenant] = createUserWithTenant(tenant: $tenant, role: 'readonly'); $workspaceUrl = CustomerReviewWorkspace::tenantPrefilterUrl($tenant); $this->actingAs($user) ->withSession([WorkspaceContext::SESSION_KEY => (int) $tenant->workspace_id]) ->from($workspaceUrl) ->post(route('localization.override.update'), ['locale' => 'de']) ->assertRedirect($workspaceUrl); });