Update
This commit is contained in:
34
tests/Feature/BlockMainTableTranslationsTest.php
Normal file
34
tests/Feature/BlockMainTableTranslationsTest.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?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');
|
||||
});
|
||||
Reference in New Issue
Block a user