Files
aritmija/tests/Feature/BlockMainTableTranslationsTest.php
2026-05-13 17:11:09 +02:00

34 lines
1.2 KiB
PHP

<?php
use Illuminate\Support\Facades\Blade;
it('renders translated block names per language with an n-a fallback', function () {
$html = Blade::render(<<<'BLADE'
@php
$translations = is_array($row->attributes ?? null) ? $row->attributes : [];
@endphp
@foreach($languages as $lang)
@php
$translation = $translations[$lang->iso] ?? [];
$translatedName = trim((string) data_get($translation, 'name', ''));
@endphp
<span class="headlines lang-{{ $lang->iso }}">
{{ $translatedName !== '' ? $translatedName : 'N/A' }}
</span>
@endforeach
BLADE, [
'languages' => collect([
(object) ['iso' => 'en', 'name' => 'English'],
(object) ['iso' => 'sl', 'name' => 'Slovenian'],
]),
'row' => (object) [
'attributes' => [
'en' => ['name' => 'Hero title', 'content' => '<p>Hello</p>'],
'sl' => ['content' => '<p>Zivjo</p>'],
],
],
]);
expect($html)->toContain('Hero title');
expect($html)->toContain('N/A');
});