Name aus der locale-gefiltert geladenen Uebersetzung mit #id-Fallback als Model-Methode. Ersetzt die identische Inline-Logik an 4 Stellen (Footer-Codes und Kategorien jeweils create/edit). Test: CategoryLocalizedNameTest. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
18 lines
583 B
PHP
18 lines
583 B
PHP
<?php
|
|
|
|
use App\Models\Category;
|
|
|
|
test('localizedName returns the loaded translation name', function () {
|
|
$category = Category::factory()->withTranslations()->create();
|
|
$category->load(['translations' => fn ($query) => $query->where('locale', 'de')]);
|
|
|
|
$expected = $category->translations->first()->name;
|
|
|
|
expect($category->localizedName())->toBe($expected);
|
|
});
|
|
|
|
test('localizedName falls back to the id when no translation is loaded', function () {
|
|
$category = Category::factory()->create();
|
|
|
|
expect($category->localizedName())->toBe('#'.$category->id);
|
|
});
|