trypost/tests/Feature/Middleware/SetLocaleTest.php
Paulo Castellano c7be1af124 Detect all 15 content languages on autofill, harden RTL/i18n, and cover the gaps with tests
- Brand-analyzer prompt now lists every supported language instead of only
  en/pt-BR/es, so onboarding autofill can detect the 12 added languages. The
  backtick-formatted list is built in BrandAnalyzer::instructions(), keeping the
  Blade clean and the enum free of prompt presentation.
- Translate the delete-confirmation keyword for el/ja/zh/ar (the four locales
  that still shipped the English "delete").
- Make the language and font comboboxes RTL-correct (logical ms-* instead of
  physical ml-*), and let the language combobox be searched by English name via
  a visually-hidden label (ContentLanguage::options() now exposes englishName).
- Correct the ContentLanguage class docblock: the enum is also the source of
  truth for the UI locales' text direction.

Tests: SetLocale middleware dir/RTL, isRtl and the full 15-language
englishName/label match arms, LLM language detection beyond en/es/pt-BR, and
store-path persistence of a non-default content language plus rejection of an
unsupported one.
2026-07-03 18:52:45 -03:00

44 lines
1.3 KiB
PHP

<?php
declare(strict_types=1);
use App\Http\Middleware\App\SetLocale;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\View;
/**
* Run the middleware with the given `locale` cookie (null = no cookie) and
* return the shared `htmlDir` the Blade root view renders into `<html dir>`.
*/
function runSetLocale(?string $locale): string
{
$request = Request::create('/', 'GET');
if ($locale !== null) {
$request->cookies->set('locale', $locale);
}
(new SetLocale)->handle($request, fn () => response('ok'));
return View::shared('htmlDir');
}
test('shares rtl direction and sets the locale for Arabic', function () {
expect(runSetLocale('ar'))->toBe('rtl');
expect(app()->getLocale())->toBe('ar');
});
test('shares ltr direction for a left-to-right locale', function (string $locale) {
expect(runSetLocale($locale))->toBe('ltr');
expect(app()->getLocale())->toBe($locale);
})->with(['en', 'ja', 'pt-BR', 'de']);
test('falls back to the default locale and ltr for an unknown cookie', function () {
expect(runSetLocale('sv'))->toBe('ltr');
expect(app()->getLocale())->toBe(config('languages.default'));
});
test('falls back to the default locale and ltr when no cookie is set', function () {
expect(runSetLocale(null))->toBe('ltr');
expect(app()->getLocale())->toBe(config('languages.default'));
});