Optimierung 4.2: Published-Release-Query ueber PressRelease-Scopes zentralisiert
Vier komponierbare Scopes auf PressRelease:
- published() Status freigegeben + published_at gesetzt (ohne Zeitschranke,
damit Statistik-Fenster frei einschraenken koennen)
- visibleInArchive() published() + published_at <= jetzt (oeffentlich sichtbar)
- forPortalValues() whereIn portal
- forLanguage() where language
~19 duplizierte Query-Bloecke in routes/web.php (Home, Kategorie, Detail,
Veroeffentlichen, Suche, Newsrooms, Newsroom-Detail, Legacy-Redirect) nutzen
jetzt diese Scopes. Jedes withoutGlobalScope(PortalScope) bleibt an seiner
Stelle erhalten; die Klausel-Reihenfolge ist fuers Ergebnis irrelevant (reine
AND-Verknuepfung), daher verhaltensgleich.
Test: Web/PublishedReleaseScopeTest; die 89 bestehenden Web/-Tests bleiben gruen.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
4c80b934ab
commit
987a5a2c42
4 changed files with 137 additions and 83 deletions
45
tests/Feature/Web/PublishedReleaseScopeTest.php
Normal file
45
tests/Feature/Web/PublishedReleaseScopeTest.php
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
|
||||
use App\Enums\Portal;
|
||||
use App\Enums\PressReleaseStatus;
|
||||
use App\Models\PressRelease;
|
||||
|
||||
test('published includes published releases with a date but excludes drafts, reviews and dateless', function () {
|
||||
$live = PressRelease::factory()->published()->create(['portal' => Portal::Presseecho->value]);
|
||||
$future = PressRelease::factory()->published()->create(['portal' => Portal::Presseecho->value, 'published_at' => now()->addDays(3)]);
|
||||
$draft = PressRelease::factory()->create(['status' => PressReleaseStatus::Draft->value, 'portal' => Portal::Presseecho->value]);
|
||||
$review = PressRelease::factory()->inReview()->create(['portal' => Portal::Presseecho->value]);
|
||||
$dateless = PressRelease::factory()->create(['status' => PressReleaseStatus::Published->value, 'published_at' => null, 'portal' => Portal::Presseecho->value]);
|
||||
|
||||
$ids = PressRelease::withoutGlobalScopes()->published()->pluck('id');
|
||||
|
||||
expect($ids)->toContain($live->id)
|
||||
->toContain($future->id)
|
||||
->not->toContain($draft->id)
|
||||
->not->toContain($review->id)
|
||||
->not->toContain($dateless->id);
|
||||
});
|
||||
|
||||
test('visibleInArchive excludes future-dated releases', function () {
|
||||
$live = PressRelease::factory()->published()->create(['portal' => Portal::Presseecho->value]);
|
||||
$future = PressRelease::factory()->published()->create(['portal' => Portal::Presseecho->value, 'published_at' => now()->addDay()]);
|
||||
|
||||
$ids = PressRelease::withoutGlobalScopes()->visibleInArchive()->pluck('id');
|
||||
|
||||
expect($ids)->toContain($live->id)->not->toContain($future->id);
|
||||
});
|
||||
|
||||
test('forPortalValues and forLanguage filter as expected', function () {
|
||||
$match = PressRelease::factory()->published()->create(['portal' => Portal::Presseecho->value, 'language' => 'de']);
|
||||
$otherPortal = PressRelease::factory()->published()->create(['portal' => Portal::Businessportal24->value, 'language' => 'de']);
|
||||
$otherLang = PressRelease::factory()->published()->create(['portal' => Portal::Presseecho->value, 'language' => 'en']);
|
||||
|
||||
$ids = PressRelease::withoutGlobalScopes()
|
||||
->forPortalValues([Portal::Presseecho->value, Portal::Both->value])
|
||||
->forLanguage('de')
|
||||
->pluck('id');
|
||||
|
||||
expect($ids)->toContain($match->id)
|
||||
->not->toContain($otherPortal->id)
|
||||
->not->toContain($otherLang->id);
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue