55 lines
1.8 KiB
PHP
55 lines
1.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Services\CmsFluxEditorHtmlTransformer;
|
|
|
|
test('toEditor wandelt span text-secondary in mark um', function () {
|
|
$html = '<p>Hallo <span class="text-secondary">Akzent</span>!</p>';
|
|
$out = CmsFluxEditorHtmlTransformer::toEditor($html);
|
|
|
|
expect($out)->toContain('<mark>');
|
|
expect($out)->toContain('Akzent');
|
|
expect($out)->not->toContain('text-secondary');
|
|
});
|
|
|
|
test('fromEditor wandelt mark in span text-secondary um', function () {
|
|
$html = '<p>Hallo <mark>Akzent</mark>!</p>';
|
|
$out = CmsFluxEditorHtmlTransformer::fromEditor($html);
|
|
|
|
expect($out)->toContain('class="text-secondary"');
|
|
expect($out)->toContain('Akzent');
|
|
expect($out)->not->toContain('<mark>');
|
|
});
|
|
|
|
test('Roundtrip erhält verschachtelte Formatierung', function () {
|
|
$original = '<p><span class="text-secondary"><strong>Fett</strong> und normal</span></p>';
|
|
$editor = CmsFluxEditorHtmlTransformer::toEditor($original);
|
|
$saved = CmsFluxEditorHtmlTransformer::fromEditor($editor);
|
|
|
|
expect($saved)->toContain('text-secondary');
|
|
expect($saved)->toContain('<strong>Fett</strong>');
|
|
});
|
|
|
|
test('JSON-Rich-Text-Felder werden für den Editor umgewandelt', function () {
|
|
$items = [
|
|
[
|
|
'title' => 'x',
|
|
'description' => '<p><span class="text-secondary">Hinweis</span></p>',
|
|
],
|
|
];
|
|
$out = CmsFluxEditorHtmlTransformer::toEditorJsonItems($items, false);
|
|
|
|
expect($out[0]['description'])->toContain('<mark>');
|
|
});
|
|
|
|
test('JSON-Rich-Text-Felder werden beim Speichern zurückgewandelt', function () {
|
|
$items = [
|
|
[
|
|
'description' => '<p><mark>Hinweis</mark></p>',
|
|
],
|
|
];
|
|
$out = CmsFluxEditorHtmlTransformer::fromEditorJsonItems($items, false);
|
|
|
|
expect($out[0]['description'])->toContain('text-secondary');
|
|
});
|