Put opening hours, service area and FAQ into the structured data
CMS quality / php (8.2) (push) Canceled after 0s
CMS quality / php (8.4) (push) Canceled after 0s
CMS quality / browser (push) Canceled after 0s
CMS quality / mysql (push) Canceled after 0s

Settings gain opening hours per weekday and a list of places served;
LocalBusiness emits openingHoursSpecification (equal times grouped) and
areaServed. An accordion can be marked as FAQ (schema v23 property
`faq`), which turns its entries into a FAQPage built from the visible
title and text blocks. Elektro Bernhard gets the real office hours
(Mo–Fr 07:30–17:00), the service area from Karlsruhe to Offenburg and
two more questions. ADR 094.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
kantarciandClaude Fable 5.1 committed 2026-09-14 22:26:47 +02:00
1 parent 3cb5b03dd9
commit 5f7ea63b76
12 files changed
+244 -9

No files matched your search

+69
View File
@@ -3698,6 +3698,75 @@ final class CmsTest extends TestCase
$this->pages->saveDraft('page-1', $document, 0);
}
public function testOpeningHoursAndTheServiceAreaReachTheStructuredData(): void
{
$this->pages->publish('page-1', $this->pages->saveDraft('page-1', DemoContent::pages()['home'], 0), 1);
$hours = [];
foreach (['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'] as $day) {
$hours[$day] = ['opens' => '07:30', 'closes' => '17:00'];
}
$hours['Saturday'] = ['opens' => '09:00', 'closes' => '12:00'];
$hours['Sunday'] = ['opens' => '', 'closes' => ''];
$this->site->save(['country' => 'DE', 'homePath' => 'home', 'legalName' => 'Elektro Bernhard GmbH', 'street' => 'Ooser Hauptstr. 51', 'city' => 'Baden-Baden', 'localBusiness' => '1',
'hours' => $hours, 'areaServed' => "Baden-Baden\nRastatt\n\nKarlsruhe, Offenburg\nRastatt"]);
preg_match('#<script type="application/ld\+json">(.*?)</script>#s', $this->request('/')->getContent(), $match);
$data = json_decode(html_entity_decode($match[1], ENT_QUOTES), true);
// Gleiche Zeiten werden zu einer Angabe, der geschlossene Sonntag fehlt, Orte sind eindeutig.
self::assertSame([
['@type' => 'OpeningHoursSpecification', 'dayOfWeek' => ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'], 'opens' => '07:30', 'closes' => '17:00'],
['@type' => 'OpeningHoursSpecification', 'dayOfWeek' => ['Saturday'], 'opens' => '09:00', 'closes' => '12:00'],
], $data['openingHoursSpecification']);
self::assertSame(['Baden-Baden', 'Rastatt', 'Karlsruhe', 'Offenburg'], $data['areaServed']);
}
public function testReSavingLoadedSettingsKeepsHoursAndServiceArea(): void
{
$this->site->save(['country' => 'DE', 'homePath' => 'home', 'hours' => ['Monday' => ['opens' => '07:30', 'closes' => '17:00']], 'areaServed' => 'Bühl
Achern']);
// So gibt das Anlegen der Rechtsseiten die Einstellungen zurück: geladen, unverändert.
$loaded = $this->site->load();
$this->site->save([...$loaded, 'sameAs' => '', 'consentGroups' => $loaded['consentGroups']]);
self::assertSame([['day' => 'Monday', 'opens' => '07:30', 'closes' => '17:00']], $this->site->load()['openingHours']);
self::assertSame(['Bühl', 'Achern'], $this->site->load()['areaServed']);
}
/** @return iterable<string, array{array<string, mixed>}> */
public static function refusedOpeningHours(): iterable
{
yield 'closes before opens' => [['Monday' => ['opens' => '17:00', 'closes' => '07:30']]];
yield 'not a time' => [['Monday' => ['opens' => '7.30', 'closes' => '17:00']]];
yield 'only one half' => [['Monday' => ['opens' => '07:30', 'closes' => '']]];
}
#[DataProvider('refusedOpeningHours')]
public function testOpeningHoursMustBeAPairOfTimes(array $hours): void
{
$this->expectException(InvalidPage::class);
$this->site->save(['country' => 'DE', 'homePath' => 'home', 'hours' => $hours]);
}
public function testAnAccordionMarkedAsFaqBecomesAFaqPage(): void
{
$document = DemoContent::starter('Fragen');
$document['schemaVersion'] = 23;
$item = static fn (string $id, string $q, string $a): array => ['id' => $id, 'type' => 'accordionitem', 'props' => ['title' => $q, 'open' => false], 'children' => '' === $a ? [] : [['id' => $id.'-t', 'type' => 'text', 'props' => ['text' => $a]]]];
$document['blocks'][] = ['id' => 'faq', 'type' => 'accordion', 'props' => ['faq' => true], 'children' => [
$item('f1', 'Wo sind Sie im Einsatz?', 'In <strong>Baden-Baden</strong> &amp; Umgebung.'),
$item('f2', 'Ohne Antwort?', ''),
]];
$document['blocks'][] = ['id' => 'plain', 'type' => 'accordion', 'children' => [$item('p1', 'Kein FAQ', 'Nur ein Akkordeon.')]];
$this->pages->publish('page-1', $this->pages->saveDraft('page-1', $document, 0), 1);
preg_match_all('#<script type="application/ld\+json">(.*?)</script>#s', $this->request('/')->getContent(), $matches);
$faq = array_values(array_filter(array_map(static fn (string $json): array => json_decode(html_entity_decode($json, ENT_QUOTES), true), $matches[1]), static fn (array $d): bool => 'FAQPage' === $d['@type']));
self::assertCount(1, $faq);
// Nur das gekennzeichnete Akkordeon, nur Einträge mit Antwort, ohne Auszeichnungen im Text.
self::assertSame([['@type' => 'Question', 'name' => 'Wo sind Sie im Einsatz?', 'acceptedAnswer' => ['@type' => 'Answer', 'text' => 'In Baden-Baden & Umgebung.']]], $faq[0]['mainEntity']);
// Ohne Schema v23 wird die Kennzeichnung abgewiesen.
$document['schemaVersion'] = 22;
$this->expectException(InvalidDocument::class);
$this->pages->saveDraft('page-1', $document, 1);
}
public function testASocialProfileMustBeAnHttpsAddress(): void
{
$this->expectException(InvalidPage::class);