presseportale/tests/Feature/Web/ReleaseDetailTest.php
Kevin Adametz 253141c6dc Frontend: Editorial-Relaunch der öffentlichen Strecke + Ausgaben-Routing
Öffentliche Seiten auf gemeinsames Editorial-Design (x-web.site-header/-footer,
Design-Tokens) und Ausgaben-Präfix /{edition}/ (de|en) umgestellt.

- Routing: neue Middleware SetEdition (Locale + URL::defaults), /{edition}-Gruppe
  in routes/web.php, Root-Redirect auf /de, 301 für Legacy-.html-URLs,
  Baseline-Default in AppServiceProvider.
- Neue URL-Schemata: /{edition}/press-release/{slug}, /{edition}/category/{slug}.
- Ausgabe = Sprache: DE/EN-Umschalter (Region/CH/AT entfernt); EditorialClock
  und Livewire-Komponenten sprachdynamisch.
- Detail-, Kategorie- und Veröffentlichen-Seite mit echten Daten neu aufgebaut.
- Suche aktiviert: Volt-Komponente livewire/web/search (Titel/Text/Keywords +
  Firma + Rubrik, Filter, Sortierung, Pagination, URL-Parameter q/category/sort).
- Rubriken-Navigation statt Übersichtsseite: Helper CategoryNavigation;
  web/kategorien.blade.php + Route entfernt (Legacy-301).
- Tests: Edition-Routing, Kategorie-Seite/-Navigation, Detail, Veröffentlichen,
  Suche, EditorialClock. Doku in "Echte öffentliche Unterseiten.md" aktualisiert.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-16 16:39:28 +00:00

169 lines
6.2 KiB
PHP

<?php
use App\Enums\Portal;
use App\Enums\PressReleaseStatus;
use App\Models\Category;
use App\Models\Company;
use App\Models\Contact;
use App\Models\PressRelease;
use Tests\TestCase;
/**
* @return array{0: Category, 1: Company}
*/
function detailCategoryAndCompany(Portal $portal): array
{
$category = Category::factory()->create(['portal' => $portal]);
$category->translations()->create([
'locale' => 'de',
'name' => 'Energie & Klima',
'slug' => 'energie-klima',
]);
$company = Company::factory()->create([
'portal' => $portal,
'name' => 'Muster Energie GmbH',
'is_active' => true,
'website' => 'https://muster-energie.de',
'boilerplate' => 'Die Muster Energie GmbH ist ein Spezialist für Industrie-Dekarbonisierung.',
]);
return [$category, $company];
}
test('businessportal24 release detail renders the editorial shell with real data', function () {
/** @var TestCase $this */
[$category, $company] = detailCategoryAndCompany(Portal::Businessportal24);
$release = PressRelease::factory()
->published()
->forPortal(Portal::Businessportal24)
->for($category)
->for($company)
->create([
'title' => 'Energiewende 2030: 12-Milliarden-Programm angekündigt',
'subtitle' => 'Erste Tranche fließt ab dem dritten Quartal 2026.',
'slug' => 'energiewende-2030-programm',
'text' => '<p>Berlin. Das Programm beschleunigt die Dekarbonisierung der Schwerindustrie.</p>',
'keywords' => 'Energiewende, Dekarbonisierung, Wasserstoff',
'published_at' => now()->subDay(),
]);
$contact = Contact::factory()->create([
'portal' => Portal::Businessportal24,
'company_id' => $company->id,
'first_name' => 'Annika',
'last_name' => 'Werthmann',
'email' => 'presse@muster-energie.de',
]);
$release->contacts()->attach($contact);
$this->get('https://businessportal24.test/de/press-release/'.$release->slug)
->assertSuccessful()
->assertSee('businessportal', false)
->assertSeeText('Energiewende 2030: 12-Milliarden-Programm angekündigt')
->assertSeeText('Erste Tranche fließt ab dem dritten Quartal 2026.')
->assertSeeText('Muster Energie GmbH')
->assertSeeText('Energie & Klima')
->assertSeeText('Pressekontakt')
->assertSeeText('Annika Werthmann')
->assertSeeText('Dekarbonisierung der Schwerindustrie')
->assertSeeText('Über das Unternehmen')
->assertSeeText('Wasserstoff');
});
test('release detail counts a hit', function () {
/** @var TestCase $this */
[$category, $company] = detailCategoryAndCompany(Portal::Businessportal24);
$release = PressRelease::factory()
->published()
->forPortal(Portal::Businessportal24)
->for($category)
->for($company)
->create(['slug' => 'hit-zaehler', 'hits' => 4, 'published_at' => now()->subDay()]);
$this->get('https://businessportal24.test/de/press-release/'.$release->slug)->assertSuccessful();
expect(PressRelease::withoutGlobalScopes()->find($release->id)->hits)->toBe(5);
});
test('release detail returns 404 for drafts and unknown slugs', function () {
/** @var TestCase $this */
[$category, $company] = detailCategoryAndCompany(Portal::Businessportal24);
$draft = PressRelease::factory()
->forPortal(Portal::Businessportal24)
->for($category)
->for($company)
->create([
'status' => PressReleaseStatus::Draft,
'slug' => 'noch-ein-entwurf',
'published_at' => now()->subDay(),
]);
$this->get('https://businessportal24.test/de/press-release/'.$draft->slug)->assertNotFound();
$this->get('https://businessportal24.test/de/press-release/gibt-es-nicht')->assertNotFound();
});
test('release detail does not expose releases from another portal', function () {
/** @var TestCase $this */
[$category, $company] = detailCategoryAndCompany(Portal::Presseecho);
$release = PressRelease::factory()
->published()
->forPortal(Portal::Presseecho)
->for($category)
->for($company)
->create([
'title' => 'Nur für presseecho sichtbar',
'slug' => 'nur-presseecho',
'published_at' => now()->subDay(),
]);
$this->get('https://businessportal24.test/de/press-release/'.$release->slug)->assertNotFound();
$this->get('https://presseecho.test/de/press-release/'.$release->slug)
->assertSuccessful()
->assertSee('presse', false)
->assertSeeText('Nur für presseecho sichtbar');
});
test('release detail shows more from newsroom and related releases', function () {
/** @var TestCase $this */
[$category, $company] = detailCategoryAndCompany(Portal::Businessportal24);
$main = PressRelease::factory()
->published()
->forPortal(Portal::Businessportal24)
->for($category)
->for($company)
->create(['title' => 'Hauptmeldung Energie', 'slug' => 'hauptmeldung-energie', 'published_at' => now()->subDay()]);
PressRelease::factory()
->published()
->forPortal(Portal::Businessportal24)
->for($category)
->for($company)
->create(['title' => 'Weitere Meldung desselben Newsrooms', 'slug' => 'weitere-newsroom-meldung', 'published_at' => now()->subDays(2)]);
$otherCompany = Company::factory()->create([
'portal' => Portal::Businessportal24,
'name' => 'Andere Industrie AG',
'is_active' => true,
]);
PressRelease::factory()
->published()
->forPortal(Portal::Businessportal24)
->for($category)
->for($otherCompany)
->create(['title' => 'Verwandte Branchenmeldung', 'slug' => 'verwandte-branchenmeldung', 'published_at' => now()->subDays(3)]);
$this->get('https://businessportal24.test/de/press-release/'.$main->slug)
->assertSuccessful()
->assertSeeText('Mehr von Muster Energie GmbH')
->assertSeeText('Weitere Meldung desselben Newsrooms')
->assertSeeText('Verwandte Meldungen')
->assertSeeText('Verwandte Branchenmeldung');
});