feat(settings): add default translation language setting
This commit is contained in:
parent
73b7afcc2f
commit
85608f774d
|
|
@ -9,6 +9,7 @@
|
||||||
use App\Models\Setting;
|
use App\Models\Setting;
|
||||||
use Illuminate\Http\JsonResponse;
|
use Illuminate\Http\JsonResponse;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Validation\Rule;
|
||||||
use Inertia\Inertia;
|
use Inertia\Inertia;
|
||||||
use Inertia\Response;
|
use Inertia\Response;
|
||||||
|
|
||||||
|
|
@ -19,6 +20,7 @@ class SettingsController extends Controller
|
||||||
'agenda_end_title',
|
'agenda_end_title',
|
||||||
'agenda_announcement_position',
|
'agenda_announcement_position',
|
||||||
'agenda_sermon_matching',
|
'agenda_sermon_matching',
|
||||||
|
'default_translation_language',
|
||||||
];
|
];
|
||||||
|
|
||||||
public function index(): Response
|
public function index(): Response
|
||||||
|
|
@ -48,10 +50,16 @@ public function index(): Response
|
||||||
public function update(Request $request): JsonResponse
|
public function update(Request $request): JsonResponse
|
||||||
{
|
{
|
||||||
$validated = $request->validate([
|
$validated = $request->validate([
|
||||||
'key' => ['required', 'string', 'in:'.implode(',', self::AGENDA_KEYS)],
|
'key' => ['required', 'string', Rule::in(self::AGENDA_KEYS)],
|
||||||
'value' => ['nullable', 'string', 'max:500'],
|
'value' => ['nullable', 'string', 'max:500'],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
if ($validated['key'] === 'default_translation_language') {
|
||||||
|
validator($validated, [
|
||||||
|
'value' => ['nullable', Rule::in(['DE', 'EN', 'FR', 'ES', 'NL', 'IT'])],
|
||||||
|
])->validate();
|
||||||
|
}
|
||||||
|
|
||||||
Setting::set($validated['key'], $validated['value']);
|
Setting::set($validated['key'], $validated['value']);
|
||||||
|
|
||||||
return response()->json(['success' => true]);
|
return response()->json(['success' => true]);
|
||||||
|
|
|
||||||
17
database/seeders/CcliSettingsSeeder.php
Normal file
17
database/seeders/CcliSettingsSeeder.php
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Database\Seeders;
|
||||||
|
|
||||||
|
use App\Models\Setting;
|
||||||
|
use Illuminate\Database\Seeder;
|
||||||
|
|
||||||
|
class CcliSettingsSeeder extends Seeder
|
||||||
|
{
|
||||||
|
public function run(): void
|
||||||
|
{
|
||||||
|
Setting::firstOrCreate(
|
||||||
|
['key' => 'default_translation_language'],
|
||||||
|
['value' => 'DE'],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -21,5 +21,7 @@ public function run(): void
|
||||||
'name' => 'Test User',
|
'name' => 'Test User',
|
||||||
'email' => 'test@example.com',
|
'email' => 'test@example.com',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
$this->call(CcliSettingsSeeder::class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
87
tests/Feature/SettingsDefaultLanguageTest.php
Normal file
87
tests/Feature/SettingsDefaultLanguageTest.php
Normal file
|
|
@ -0,0 +1,87 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature;
|
||||||
|
|
||||||
|
use App\Models\Setting;
|
||||||
|
use App\Models\User;
|
||||||
|
use Database\Seeders\CcliSettingsSeeder;
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use PHPUnit\Framework\Attributes\DataProvider;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @mixin \Illuminate\Foundation\Testing\Concerns\InteractsWithAuthentication
|
||||||
|
* @mixin \Illuminate\Foundation\Testing\Concerns\InteractsWithDatabase
|
||||||
|
*/
|
||||||
|
final class SettingsDefaultLanguageTest extends TestCase
|
||||||
|
{
|
||||||
|
use RefreshDatabase;
|
||||||
|
|
||||||
|
public function test_default_translation_language_is_seeded_with_de(): void
|
||||||
|
{
|
||||||
|
$this->seed(CcliSettingsSeeder::class);
|
||||||
|
|
||||||
|
$setting = Setting::where('key', 'default_translation_language')->first();
|
||||||
|
|
||||||
|
$this->assertNotNull($setting);
|
||||||
|
$this->assertSame('DE', $setting?->value);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[DataProvider('validLanguages')]
|
||||||
|
public function test_accepts_valid_default_translation_language_via_patch(string $language): void
|
||||||
|
{
|
||||||
|
$user = User::factory()->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->patchJson(route('settings.update'), [
|
||||||
|
'key' => 'default_translation_language',
|
||||||
|
'value' => $language,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response->assertOk()->assertJson(['success' => true]);
|
||||||
|
|
||||||
|
$this->assertSame($language, Setting::get('default_translation_language'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function validLanguages(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
['DE'],
|
||||||
|
['EN'],
|
||||||
|
['FR'],
|
||||||
|
['ES'],
|
||||||
|
['NL'],
|
||||||
|
['IT'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_rejects_invalid_default_translation_language_via_patch(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->patchJson(route('settings.update'), [
|
||||||
|
'key' => 'default_translation_language',
|
||||||
|
'value' => 'ZZ',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response->assertUnprocessable();
|
||||||
|
$response->assertJsonValidationErrors('value');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_exposes_default_translation_language_in_settings_props(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()->create();
|
||||||
|
|
||||||
|
$this->seed(CcliSettingsSeeder::class);
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)
|
||||||
|
->withoutVite()
|
||||||
|
->get(route('settings.index'));
|
||||||
|
|
||||||
|
$response->assertInertia(
|
||||||
|
fn ($page) => $page
|
||||||
|
->component('Settings')
|
||||||
|
->has('settings.default_translation_language')
|
||||||
|
->where('settings.default_translation_language', 'DE')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue