TenantAtlas/apps/platform/tests/Feature/Localization/LocalePreferenceFlowTest.php
ahmido 7613e339c4
Some checks failed
Main Confidence / confidence (push) Failing after 56s
feat: implement platform localization v1 (#293)
## Summary
- add the localization v1 foundation with request-time locale resolution and workspace or user preference handling
- localize the first-wave platform surfaces for auth, shell, dashboards, findings, baseline compare, and review workspace chrome
- add Pest coverage for locale resolution, preference flows, fallback behavior, notifications, and governance surface localization

## Scope
- active spec: specs/252-platform-localization-v1
- target branch: dev

## Notes
- machine-readable artifacts remain invariant and are not localized in this slice
- the branch includes the related spec kit artifacts for the feature

Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de>
Reviewed-on: #293
2026-04-28 19:45:03 +00:00

88 lines
3.2 KiB
PHP

<?php
declare(strict_types=1);
use App\Services\Localization\LocaleResolver;
use App\Services\Settings\SettingsWriter;
use App\Support\Workspaces\WorkspaceContext;
it('allows users to save and clear a personal locale preference over workspace default', function (): void {
[$workspace, $user] = localizationWorkspaceMember();
app(SettingsWriter::class)->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();
});