presseportale/tests/Feature/Web/NewsroomPageTest.php
Kevin Adametz abfcd774e0 newsroom: Seite verschwindet mit der letzten veröffentlichten Meldung (Roadmap 1b.1/1b.5)
Die Sichtbarkeitsregel bestand bereits (Detailseite 404, Verzeichnis und
Sitemap nur mit veröffentlichter Meldung). Neu: archive(),
changeStatusFromAdmin() weg von published und deleteFromAdmin() einer
veröffentlichten Meldung leeren den Seiten-Cache — vorher blieb die
Newsroom-Seite bis zu eine Stunde stehen, während die Depublikation längst
sofort griff.

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

181 lines
7 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\Services\PressRelease\PressReleaseService;
use Illuminate\Support\Str;
use Tests\TestCase;
function makeNewsroom(string $name, Portal $portal = Portal::Businessportal24, array $attributes = []): Company
{
return Company::factory()
->state(['portal' => $portal->value])
->create(array_merge([
'name' => $name,
'slug' => Str::slug($name).'-'.fake()->unique()->numberBetween(1000, 9999),
'is_active' => true,
], $attributes));
}
function publishForCompany(Company $company, string $title, array $attributes = [], ?Category $category = null): PressRelease
{
$category ??= Category::factory()->create(['portal' => Portal::Both]);
return PressRelease::factory()
->published()
->forPortal(Portal::Businessportal24)
->for($category)
->for($company)
->create(array_merge([
'title' => $title,
'slug' => Str::slug($title).'-'.fake()->unique()->numberBetween(1000, 9999),
'language' => 'de',
'published_at' => now()->subDay(),
], $attributes));
}
test('the newsrooms index renders the editorial shell and lists active newsrooms', function () {
/** @var TestCase $this */
$company = makeNewsroom('Nordwind Energie AG');
publishForCompany($company, 'Nordwind nimmt neuen Windpark in Betrieb');
$this->get('https://businessportal24.test/de/newsrooms')
->assertSuccessful()
->assertSee('businessportal', false)
->assertSeeText('Newsrooms')
->assertSeeText('Nordwind Energie AG');
});
test('the newsrooms index filters by company name', function () {
/** @var TestCase $this */
$match = makeNewsroom('Solartec Industries GmbH');
publishForCompany($match, 'Solartec meldet Rekordquartal');
$other = makeNewsroom('Hafenlogistik Bremen AG');
publishForCompany($other, 'Hafenlogistik baut Terminal aus');
$this->get('https://businessportal24.test/de/newsrooms?q=Solartec')
->assertSuccessful()
->assertSeeText('Solartec Industries GmbH')
->assertDontSeeText('Hafenlogistik Bremen AG');
});
test('the newsrooms index excludes companies without published releases', function () {
/** @var TestCase $this */
makeNewsroom('Stilles Unternehmen AG');
$this->get('https://businessportal24.test/de/newsrooms')
->assertSuccessful()
->assertDontSeeText('Stilles Unternehmen AG');
});
test('the newsroom detail page renders company data and its releases', function () {
/** @var TestCase $this */
$company = makeNewsroom('Bavaria Maschinenbau AG', attributes: [
'boilerplate' => 'Bavaria Maschinenbau ist ein führender Anbieter von Industrielösungen.',
]);
publishForCompany($company, 'Bavaria präsentiert neue Produktionslinie');
$this->get('https://businessportal24.test/de/newsroom/'.$company->slug)
->assertSuccessful()
->assertSeeText('Bavaria Maschinenbau AG')
->assertSeeText('Bavaria präsentiert neue Produktionslinie')
->assertSeeText('Alle Meldungen');
});
test('the newsroom detail page links the company website with an absolute url', function () {
/** @var TestCase $this */
// Bestandsdaten ohne Schema („www.akgsoftware.de“) — als roher href
// würde daraus der relative Link /de/newsroom/www.akgsoftware.de.
$company = makeNewsroom('AKG Software Consulting GmbH', attributes: [
'website' => 'www.akgsoftware.de',
]);
publishForCompany($company, 'AKG veröffentlicht neue Version');
$this->get('https://businessportal24.test/de/newsroom/'.$company->slug)
->assertSuccessful()
->assertSee('href="https://www.akgsoftware.de"', false)
->assertDontSee('newsroom/www.akgsoftware.de', false);
// Hinterlegte URLs mit Schema bleiben unverändert.
expect(Company::factory()->make(['website' => 'https://akgsoftware.de'])->websiteUrl())
->toBe('https://akgsoftware.de')
->and(Company::factory()->make(['website' => null])->websiteUrl())->toBeNull();
});
test('the newsroom detail page returns 404 for an unknown slug', function () {
/** @var TestCase $this */
$this->get('https://businessportal24.test/de/newsroom/gibt-es-nicht')
->assertNotFound();
});
test('the newsroom detail page returns 404 when the company has no published releases', function () {
/** @var TestCase $this */
$company = makeNewsroom('Leeres Newsroom AG');
$this->get('https://businessportal24.test/de/newsroom/'.$company->slug)
->assertNotFound();
});
test('the newsroom page disappears with its last published release, cache included', function () {
/** @var TestCase $this */
// Roadmap 1b.1/1b.5: öffentlich nur mit veröffentlichter Meldung — und
// der Rückbau greift sofort, nicht erst nach Ablauf des Seiten-Caches.
$company = makeNewsroom('Einmalig AG');
$release = publishForCompany($company, 'Die einzige Meldung');
$url = 'https://businessportal24.test/de/newsroom/'.$company->slug;
$this->get($url)->assertOk();
$this->get('https://businessportal24.test/de/newsrooms')->assertSeeText('Einmalig AG');
app(PressReleaseService::class)->archive($release);
$this->get($url)->assertNotFound();
$this->get('https://businessportal24.test/de/newsrooms')->assertDontSeeText('Einmalig AG');
});
test('an admin status change away from published takes the newsroom page down', function () {
/** @var TestCase $this */
$company = makeNewsroom('Rückzug GmbH');
$release = publishForCompany($company, 'Zurückgezogen');
$url = 'https://businessportal24.test/de/newsroom/'.$company->slug;
$this->get($url)->assertOk();
app(PressReleaseService::class)->changeStatusFromAdmin($release, PressReleaseStatus::Draft);
$this->get($url)->assertNotFound();
});
test('deleting the last published release from admin takes the newsroom page down', function () {
/** @var TestCase $this */
$company = makeNewsroom('Gelöscht KG');
$release = publishForCompany($company, 'Wird entfernt');
$url = 'https://businessportal24.test/de/newsroom/'.$company->slug;
$this->get($url)->assertOk();
app(PressReleaseService::class)->deleteFromAdmin($release);
$this->get($url)->assertNotFound();
});
test('the newsrooms pages are available per edition and portal', function () {
/** @var TestCase $this */
$this->get('https://businessportal24.test/en/newsrooms')->assertSuccessful();
$this->get('https://presseecho.test/de/newsrooms')
->assertSuccessful()
->assertSee('presse', false);
});
test('legacy newsroom html urls redirect to the clean edition path', function () {
/** @var TestCase $this */
$this->get('https://businessportal24.test/de/newsrooms.html')
->assertRedirect('https://businessportal24.test/de/newsrooms');
$this->get('https://businessportal24.test/de/newsroom/acme.html')
->assertRedirect('https://businessportal24.test/de/newsroom/acme');
});