presseportale/tests/Feature/CompanyNewsroomLinkTest.php
Kevin Adametz 33fcde5558 portal: Firmenseiten verlinken den öffentlichen Newsroom
Im Backend heißt der Datensatz weiter „Firma“, öffentlich ist er der
Newsroom. Kunden- und Admin-Firmenseite heißen „Firma & Newsroom“ und zeigen
unter dem Namen die Newsroom-Links je Portal oder den Hinweis, dass der
Newsroom erst mit der ersten Meldung erscheint (Company::publicNewsroomLinks).

Changelog: Verbessert
Public: Die Firmenseite im Kundenbereich verlinkt jetzt direkt auf den öffentlichen Newsroom.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-13 15:26:08 +00:00

104 lines
4.4 KiB
PHP

<?php
use App\Enums\Portal;
use App\Models\Company;
use App\Models\PressRelease;
use App\Models\User;
use Database\Seeders\RolesAndPermissionsSeeder;
use Livewire\Livewire;
use Tests\TestCase;
/**
* Firma ↔ Newsroom (Roadmap 6.17): Im Backend heißt der Datensatz „Firma“,
* öffentlich ist er der Newsroom. Beide Firmenseiten verlinken ihn, und die
* Newsroom-Seite zeigt den Verwaltungszugang als Kasten statt als Textzeile.
*/
test('a company has no public newsroom before its first visible release', function () {
/** @var TestCase $this */
$company = Company::factory()->presseecho()->create(['slug' => 'alpha-gmbh', 'is_active' => true]);
expect($company->publicNewsroomLinks())->toBe([]);
PressRelease::factory()->published()->forPortal(Portal::Presseecho)->create([
'company_id' => $company->id, 'published_at' => now()->subDay(), 'language' => 'de',
]);
$links = $company->publicNewsroomLinks();
expect($links)->toHaveCount(1)
->and($links[0]['portal'])->toBe(Portal::Presseecho)
->and($links[0]['url'])->toEndWith('/de/newsroom/alpha-gmbh');
});
test('a company on both portals links each portal where it already appears, english only without german releases', function () {
/** @var TestCase $this */
$company = Company::factory()->create(['portal' => Portal::Both, 'slug' => 'beta-ag', 'is_active' => true]);
PressRelease::factory()->published()->forPortal(Portal::Businessportal24)->create([
'company_id' => $company->id, 'published_at' => now()->subDay(), 'language' => 'en',
]);
$links = $company->publicNewsroomLinks();
expect($links)->toHaveCount(1)
->and($links[0]['portal'])->toBe(Portal::Businessportal24)
->and($links[0]['url'])->toEndWith('/en/newsroom/beta-ag');
});
test('the customer company page links the public newsroom or says why there is none', function () {
/** @var TestCase $this */
$this->seed(RolesAndPermissionsSeeder::class);
$customer = User::factory()->create(['is_active' => true]);
$customer->assignRole('customer');
$company = Company::factory()->presseecho()->create(['name' => 'Alpha GmbH', 'slug' => 'alpha-gmbh', 'is_active' => true]);
$customer->companies()->attach($company->id, ['role' => 'responsible']);
$this->actingAs($customer);
Livewire::test('customer.press-kits.show', ['id' => $company->id])
->assertSee('Firma & Newsroom')
->assertSee('Newsroom noch nicht öffentlich');
PressRelease::factory()->published()->forPortal(Portal::Presseecho)->create([
'company_id' => $company->id, 'published_at' => now()->subDay(), 'language' => 'de',
]);
Livewire::test('customer.press-kits.show', ['id' => $company->id])
->assertSee('Öffentlicher Newsroom:')
->assertSee('/de/newsroom/alpha-gmbh');
});
test('the admin company page links the public newsroom', function () {
/** @var TestCase $this */
$this->seed(RolesAndPermissionsSeeder::class);
$admin = User::factory()->create(['is_active' => true]);
$admin->assignRole('admin');
$company = Company::factory()->businessportal24()->create(['slug' => 'gamma-kg', 'is_active' => true]);
PressRelease::factory()->published()->forPortal(Portal::Businessportal24)->create([
'company_id' => $company->id, 'published_at' => now()->subDay(), 'language' => 'de',
]);
$this->actingAs($admin);
Livewire::test('admin.companies.show', ['id' => $company->id])
->assertSee('Öffentlicher Newsroom:')
->assertSee('/de/newsroom/gamma-kg');
});
test('the newsroom page shows the manage box with the masked address instead of a text line', function () {
/** @var TestCase $this */
$company = Company::factory()->businessportal24()->create([
'name' => 'Muster GmbH', 'slug' => 'muster-gmbh', 'email' => 'info@muster.de', 'is_active' => true,
]);
PressRelease::factory()->published()->forPortal(Portal::Businessportal24)->create([
'company_id' => $company->id, 'published_at' => now()->subDay(), 'language' => 'de',
]);
$this->get('https://businessportal24.test/de/newsroom/muster-gmbh')
->assertOk()
->assertSee('data-manage-newsroom', false)
->assertSeeText('Sie vertreten Muster GmbH?')
->assertSeeText('i***@muster.de')
->assertSeeText('Anmeldelink anfordern')
->assertDontSeeText('info@muster.de')
->assertDontSeeText('Eigenen Newsroom starten');
});