Web: Boost-Platzierung auf Start- und Branchenseite ausspielen

Geboostete PMs besetzen Lead- und Top-Slots vor der Chronologie
(HomePageData/CategoryPageData ueber boosted()-Scope) und tragen das
Badge "Top-Platzierung". Abgelaufene Boosts wirken nicht.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Kevin Adametz 2026-07-10 17:05:10 +00:00
parent 0665553c88
commit df6b24518c
10 changed files with 183 additions and 19 deletions

View file

@ -0,0 +1,100 @@
<?php
use App\Enums\Portal;
use App\Models\Boost;
use App\Models\Category;
use App\Models\Company;
use App\Models\PressRelease;
use App\Services\Web\HomePageData;
use Tests\TestCase;
/**
* Boost-Platzierung (Decision-Update §2.2): geboostete PMs besetzen die
* Top-Positionen auf Start- und Branchenseite vor der Chronologie und werden
* als „Top-Platzierung" markiert.
*/
function boostPlacementFixture(): array
{
$category = Category::factory()->create(['portal' => Portal::Presseecho]);
$category->translations()->create([
'locale' => 'de',
'name' => 'Energie & Klima',
'slug' => 'energie-klima',
]);
$company = Company::factory()->presseecho()->create(['name' => 'Boost Energie GmbH']);
$newest = PressRelease::factory()
->published()
->forPortal(Portal::Presseecho)
->for($category)
->for($company)
->create([
'title' => 'Neueste unbezahlte Meldung',
'slug' => 'neueste-unbezahlte-meldung',
'published_at' => now()->subHour(),
]);
$boosted = PressRelease::factory()
->published()
->forPortal(Portal::Presseecho)
->for($category)
->for($company)
->create([
'title' => 'Geboostete aeltere Meldung',
'slug' => 'geboostete-aeltere-meldung',
'published_at' => now()->subDays(5),
]);
return compact('category', 'company', 'newest', 'boosted');
}
test('a boosted release takes the homepage lead ahead of newer releases and is labelled', function () {
/** @var TestCase $this */
['boosted' => $boosted, 'newest' => $newest] = boostPlacementFixture();
Boost::factory()->for($boosted)->create();
$data = app(HomePageData::class)->build(Portal::Presseecho);
expect($data['leadRelease']->id)->toBe($boosted->id)
->and($data['boostedIds'])->toBe([$boosted->id])
// Die verdrängte neueste Meldung rückt in die Seitenleiste nach.
->and($data['sideReleases']->modelKeys())->toContain($newest->id);
// Badge „Top-Platzierung" hängt am Hero-Lead (nach dem Ticker-Vorkommen).
$this->get('https://presseecho.test/de')
->assertSuccessful()
->assertSeeTextInOrder(['Top-Platzierung', 'Geboostete aeltere Meldung']);
});
test('an expired boost does not influence the homepage placement', function () {
/** @var TestCase $this */
['boosted' => $boosted, 'newest' => $newest] = boostPlacementFixture();
Boost::factory()->for($boosted)->expired()->create();
$data = app(HomePageData::class)->build(Portal::Presseecho);
expect($data['leadRelease']->id)->toBe($newest->id)
->and($data['boostedIds'])->toBe([]);
$this->get('https://presseecho.test/de')
->assertSuccessful()
->assertDontSeeText('Top-Platzierung');
});
test('a boosted release leads its category page and is labelled', function () {
/** @var TestCase $this */
['boosted' => $boosted] = boostPlacementFixture();
Boost::factory()->for($boosted)->create();
// Lead-Slot der Branchenseite: Badge und geboosteter Titel im Hero,
// die neuere unbezahlte Meldung folgt dahinter in den Top-Meldungen.
$this->get('https://presseecho.test/de/category/energie-klima')
->assertSuccessful()
->assertSeeTextInOrder([
'Top-Platzierung',
'Geboostete aeltere Meldung',
'Neueste unbezahlte Meldung',
]);
});