Files
myep/tests/ContentFeed/DocumentBodyBuilderTest.php
T

75 lines
2.8 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Tests\ContentFeed;
use App\ContentFeed\DocumentBodyBuilder;
use App\ContentFeed\HtmlToMarkdownConverter;
use PHPUnit\Framework\TestCase;
class DocumentBodyBuilderTest extends TestCase
{
private DocumentBodyBuilder $builder;
protected function setUp(): void
{
$this->builder = new DocumentBodyBuilder(new HtmlToMarkdownConverter());
}
public function testProductSectionsInFixedOrderWithFaqs(): void
{
$body = $this->builder->build('product', [
'url' => 'https://www.ep-reisen.de/val-thorens/',
'name' => 'Val Thorens Apartments',
'subline' => 'Apartments',
'headline' => 'Skiurlaub in Val Thorens',
'text' => [
'skiPassDescription' => '<p>6 Tage 3 Vallées</p>',
'teaser' => '<p>Ski in, ski out</p>',
'includedServices' => '<ul><li>Unterkunft</li></ul>',
'feature' => null,
],
'faqs' => [
['question' => 'Ist der Skipass inklusive?', 'answer' => '<p>Ja.</p>', 'category' => null],
['question' => 'Ohne Antwort', 'answer' => null],
],
]);
self::assertSame(
"# Val Thorens Apartments\n\nApartments\n\nSkiurlaub in Val Thorens\n\nSki in, ski out\n\n## Leistungen\n\n- Unterkunft\n\n## Skipass\n\n6 Tage 3 Vallées\n\n## Häufige Fragen\n\n### Ist der Skipass inklusive?\n\nJa.",
$body,
);
}
public function testHotelFactsAreSearchableText(): void
{
$body = $this->builder->build('hotel', [
'name' => 'Chalets de Rosael',
'facts' => ['bedsCount' => 120, 'altitude' => null, 'sauna' => true, 'wifi' => false],
'text' => ['description' => '<p>Ruhige Lage</p>'],
]);
self::assertSame("# Chalets de Rosael\n\n## Beschreibung\n\nRuhige Lage\n\n## Fakten\n\n- Betten: 120\n- Sauna: ja\n- WLAN: nein", $body);
}
public function testNewsUsesTitleDateBodyAndTags(): void
{
$record = [
'title' => 'Packlisten',
'teaser' => 'Was muss mit?',
'bodytext' => '<p>Helm &amp; Brille</p>',
'datetime' => '2026-07-23T14:00:00+02:00',
'tags' => ['Urlaubsvorbereitung', ['title' => 'Anfänger:in']],
];
self::assertSame('Packlisten', $this->builder->title('news', $record));
self::assertSame("# Packlisten\n\nVeröffentlicht am 23.07.2026\n\nWas muss mit?\n\nHelm & Brille\n\nThemen: Urlaubsvorbereitung, Anfänger:in", $this->builder->build('news', $record));
}
public function testRecordWithoutTextIsJustItsTitle(): void
{
self::assertSame('# Frankreich', $this->builder->build('country', ['name' => 'Frankreich', 'text' => []]));
}
}