48 lines
1.7 KiB
PHP
48 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use Illuminate\Support\Facades\Validator;
|
|
use Inertia\Testing\AssertableInertia as Assert;
|
|
use Symfony\Component\Process\Process;
|
|
use Tests\TestCase;
|
|
|
|
class LocalizationTest extends TestCase
|
|
{
|
|
public function test_frontend_localization_behaviour(): void
|
|
{
|
|
$process = new Process(['node', 'tests/Fixtures/localization.mjs'], base_path());
|
|
$process->setTimeout(60);
|
|
$process->run();
|
|
|
|
$this->assertTrue($process->isSuccessful(), $process->getOutput().$process->getErrorOutput());
|
|
$this->assertStringContainsString('Localization behavior checks passed.', $process->getOutput());
|
|
}
|
|
|
|
public function test_initial_page_shares_the_application_locale_and_time_zone(): void
|
|
{
|
|
config(['app.timezone' => 'Europe/Berlin']);
|
|
|
|
$this->withHeader('Accept-Language', 'de-DE')->get(route('home'))
|
|
->assertOk()
|
|
->assertSee('lang="en"', false)
|
|
->assertInertia(fn (Assert $page) => $page
|
|
->where('localization.locale', 'en')
|
|
->where('localization.timeZone', 'Europe/Berlin'));
|
|
}
|
|
|
|
public function test_server_validation_remains_english(): void
|
|
{
|
|
$this->assertSame('en', config('app.locale'));
|
|
$this->assertSame('en', config('app.fallback_locale'));
|
|
|
|
$validator = Validator::make(['email' => 'invalid'], [
|
|
'title' => ['required'],
|
|
'email' => ['email'],
|
|
]);
|
|
|
|
$this->assertSame('The title field is required.', $validator->errors()->first('title'));
|
|
$this->assertSame('The email field must be a valid email address.', $validator->errors()->first('email'));
|
|
}
|
|
}
|