81 lines
2.8 KiB
PHP
81 lines
2.8 KiB
PHP
<?php
|
|
|
|
use App\Enums\PressReleaseStatus;
|
|
use App\Mail\PressReleasePublished;
|
|
use App\Mail\PressReleaseRejected;
|
|
use App\Models\PressRelease;
|
|
use App\Services\PressRelease\BlacklistService;
|
|
use App\Services\PressRelease\BlacklistViolationException;
|
|
use App\Services\PressRelease\PressReleaseService;
|
|
use Illuminate\Support\Facades\Mail;
|
|
use Tests\TestCase;
|
|
|
|
beforeEach(function (): void {
|
|
config()->set('blacklist.words', ['penis', 'casino royale']);
|
|
app()->forgetInstance(BlacklistService::class);
|
|
});
|
|
|
|
test('blacklist service finds banned word case insensitive and across word boundaries', function () {
|
|
$service = app(BlacklistService::class);
|
|
|
|
expect($service->matches('Hier kommt PENIS vor.'))->toBeTrue();
|
|
expect($service->matches('Wir spielen "Casino Royale" heute Abend.'))->toBeTrue();
|
|
expect($service->matches('Ein langer Begriff wie penistier ist erlaubt.'))->toBeFalse();
|
|
expect($service->matches('Eine ganz normale Pressemitteilung.'))->toBeFalse();
|
|
});
|
|
|
|
test('submitting a press release with banned word auto-rejects and notifies author', function () {
|
|
/** @var TestCase $this */
|
|
Mail::fake();
|
|
|
|
$pr = PressRelease::factory()->create([
|
|
'status' => PressReleaseStatus::Draft->value,
|
|
'title' => 'Tolle Neuigkeiten',
|
|
'text' => 'In diesem Text kommt das Wort penis prominent vor und das geht nicht.',
|
|
]);
|
|
|
|
expect(fn () => app(PressReleaseService::class)->submitForReview($pr))
|
|
->toThrow(BlacklistViolationException::class);
|
|
|
|
$pr->refresh();
|
|
|
|
expect($pr->status)->toBe(PressReleaseStatus::Rejected);
|
|
Mail::assertQueued(PressReleaseRejected::class);
|
|
});
|
|
|
|
test('publishing a clean press release succeeds when blacklist has no matches', function () {
|
|
/** @var TestCase $this */
|
|
Mail::fake();
|
|
|
|
$pr = PressRelease::factory()->create([
|
|
'status' => PressReleaseStatus::Review->value,
|
|
'title' => 'Saubere Mitteilung',
|
|
'text' => 'Dieser Inhalt ist völlig in Ordnung und enthält keine verbotenen Wörter.',
|
|
]);
|
|
|
|
app(PressReleaseService::class)->publish($pr);
|
|
|
|
$pr->refresh();
|
|
|
|
expect($pr->status)->toBe(PressReleaseStatus::Published);
|
|
Mail::assertQueued(PressReleasePublished::class);
|
|
});
|
|
|
|
test('publishing a press release with banned phrase auto-rejects', function () {
|
|
/** @var TestCase $this */
|
|
Mail::fake();
|
|
|
|
$pr = PressRelease::factory()->create([
|
|
'status' => PressReleaseStatus::Review->value,
|
|
'title' => 'Casino Royale Tour',
|
|
'text' => 'Erleben Sie die magische Atmosphäre von Casino Royale live.',
|
|
]);
|
|
|
|
expect(fn () => app(PressReleaseService::class)->publish($pr))
|
|
->toThrow(BlacklistViolationException::class);
|
|
|
|
$pr->refresh();
|
|
|
|
expect($pr->status)->toBe(PressReleaseStatus::Rejected);
|
|
Mail::assertQueued(PressReleaseRejected::class);
|
|
});
|