presseportale/tests/Feature/Web/StructuredDataTest.php
Kevin Adametz b60a28dc9c web: Entitaeten im JSON-LD verknuepft, News-Sitemap und llms.txt (Roadmap 2.1, 2.2, 2.7)
- App\Support\StructuredData: Portal-Organization als Publisher mit @id
  und Logo (ImageObject), Newsroom-@id; NewsArticle.author auf der
  Meldung und Organization auf der Newsroom-Seite beschreiben jetzt
  dieselbe Entitaet. Startseiten nutzen denselben Publisher.
- /sitemap-news.xml je Spoke (NewsSitemapController): im Archiv
  sichtbare Meldungen der letzten 48 h, max. 1.000, news:publication
  mit Portalname und Sprache; 15 min gecacht, mit den anderen Sitemaps
  geleert; in robots.txt der Spokes. Hub liefert leere Liste.
- /llms.txt je Host (LlmsTxtController): sachliche Beschreibung,
  URL-Aufbau, aktive Kategorien, Seiten fuer Unternehmen, Rechtliches;
  Hub verweist auf beide Portale. Keine Aussagen ueber KI-Nennungen.
- Protokoll Teil 5 (Block 2) inkl. Betreiber-Schritten fuer das
  Publisher Center und Befund zu 2.5/E5; Roadmap 2.1/2.7 abgehakt.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-17 10:15:28 +00:00

124 lines
5.6 KiB
PHP

<?php
use App\Enums\Portal;
use App\Enums\PressReleaseStatus;
use App\Models\Category;
use App\Models\Company;
use App\Models\PressRelease;
use App\Models\User;
use App\Services\Auth\MagicLinkGenerator;
use Tests\TestCase;
function makeStructuredDataRelease(): PressRelease
{
$category = Category::factory()->create(['portal' => Portal::Businessportal24]);
$category->translations()->create(['locale' => 'de', 'name' => 'Technologie', 'slug' => 'technologie']);
$company = Company::factory()->businessportal24()->create(['name' => 'Muster GmbH']);
return PressRelease::factory()
->published()
->forPortal(Portal::Businessportal24)
->for($category)
->for($company)
->create([
'slug' => 'strukturierte-daten-pm',
'title' => 'Strukturierte Daten für Pressemitteilungen',
'published_at' => now()->subDay(),
]);
}
test('the release detail page emits NewsArticle and BreadcrumbList JSON-LD', function () {
/** @var TestCase $this */
makeStructuredDataRelease();
$this->get('https://businessportal24.test/de/press-release/strukturierte-daten-pm')
->assertSuccessful()
->assertSee('<script type="application/ld+json">', false)
->assertSee('"@type":"NewsArticle"', false)
->assertSee('"headline":"Strukturierte Daten für Pressemitteilungen"', false)
->assertSee('"datePublished"', false)
->assertSee('"publisher":{"@type":"Organization","@id":"https://businessportal24.test/#organization","name":"businessportal24"', false)
->assertSee('"logo":{"@type":"ImageObject","url":"https://businessportal24.test/images/businessportal-logo.svg"', false)
->assertSee('"author":{"@type":"Organization","@id":"https://businessportal24.test/de/newsroom/', false)
->assertSee('#organization","name":"Muster GmbH"', false)
->assertSee('"@type":"BreadcrumbList"', false)
->assertSee('"articleSection":"Technologie"', false);
});
test('the release detail page emits article meta tags and og locale', function () {
/** @var TestCase $this */
makeStructuredDataRelease();
$this->get('https://businessportal24.test/de/press-release/strukturierte-daten-pm')
->assertSuccessful()
->assertSee('<meta property="article:published_time" content="', false)
->assertSee('<meta property="article:section" content="Technologie">', false)
->assertSee('<meta property="og:locale" content="de_DE">', false);
});
test('the private preview emits neither JSON-LD nor article meta tags', function () {
/** @var TestCase $this */
$owner = User::factory()->create();
$release = PressRelease::factory()->forPortal(Portal::Businessportal24)->create([
'user_id' => $owner->id,
'status' => PressReleaseStatus::Draft->value,
]);
$share = app(MagicLinkGenerator::class)->createPressReleaseShareLink($release, $owner);
$this->get(route('press-releases.preview', ['token' => $share['plain_token']]))
->assertOk()
->assertDontSee('application/ld+json', false)
->assertDontSee('article:published_time', false);
});
test('a portal homepage emits WebSite JSON-LD with a SearchAction', function () {
/** @var TestCase $this */
$this->get('https://presseecho.test/de')
->assertSuccessful()
->assertSee('"@type":"WebSite"', false)
->assertSee('"@type":"SearchAction"', false)
->assertSee('https://presseecho.test/de/suche?q={search_term_string}', false)
->assertSee('"@id":"https://presseecho.test/#organization"', false)
->assertSee('"url":"https://presseecho.test/images/presseecho-logo.svg"', false);
});
test('the newsroom page emits Organization JSON-LD for the company', function () {
/** @var TestCase $this */
$category = Category::factory()->create(['portal' => Portal::Businessportal24]);
$category->translations()->create(['locale' => 'de', 'name' => 'Wirtschaft', 'slug' => 'wirtschaft']);
$company = Company::factory()->businessportal24()->create([
'name' => 'Newsroom AG',
'website' => 'https://newsroom-ag.example',
]);
PressRelease::factory()
->published()
->forPortal(Portal::Businessportal24)
->for($category)
->for($company)
->create(['published_at' => now()->subDay()]);
$this->get('https://businessportal24.test/de/newsroom/'.$company->slug)
->assertSuccessful()
->assertSee('"@type":"Organization"', false)
->assertSee('"@id":"https://businessportal24.test/de/newsroom/'.$company->slug.'#organization"', false)
->assertSee('"name":"Newsroom AG"', false)
->assertSee('"sameAs":["https://newsroom-ag.example"]', false);
});
test('the category page emits BreadcrumbList JSON-LD and localized hreflang links', function () {
/** @var TestCase $this */
$category = Category::factory()->create(['portal' => Portal::Businessportal24]);
$category->translations()->create(['locale' => 'de', 'name' => 'Technologie', 'slug' => 'technologie']);
$category->translations()->create(['locale' => 'en', 'name' => 'Technology', 'slug' => 'technology']);
$this->get('https://businessportal24.test/de/category/technologie')
->assertSuccessful()
->assertSee('"@type":"BreadcrumbList"', false)
->assertSee('"name":"Technologie"', false)
->assertSee('<link rel="alternate" hreflang="de" href="https://businessportal24.test/de/category/technologie">', false)
->assertSee('<link rel="alternate" hreflang="en" href="https://businessportal24.test/en/category/technology">', false);
});