presseportale/tests/Feature/CustomerPressReleaseSchedulingFormTest.php
Kevin Adametz a000238ca8 User Panel: Phase-8-Abschluss, Titelbild/Lizenzen/Zeitzonen und KI-Pruef-Pipeline
Phase 8 (Rest) + Umbauten vom 10./11.06.:
- Ein Titelbild pro PM (Cover 1280x580), SVG-Platzhalter-Set + Picker,
  PressReleaseCoverImage-Resolver
- Lizenz-/Rechteformular nach "Lizenztyp Bildupload" (7 Lizenztypen,
  Personen-/Sachrechte-Status, bedingte Pflichtfelder, Risikohinweise)
- Veroeffentlichungs-Box vereinfacht (Embargo aus der Form-UI entfernt),
  geplante Termine in Europe/Berlin (Speicherung UTC, DISPLAY_TIMEZONE)
- Quota-Stub (users.press_release_quota) + monatlicher Reset-Command
- Einreichungs-Modal einheitlich in Show/Create/Edit; Ghost-Buttons auf
  filled; PM-Editor-Layout responsive entkoppelt (.pr-editor-layout)

KI-Pruef-Pipeline (Phasen 1-5 des Entwicklungsplans):
- API-Haertung: status nicht mehr per API setzbar, eigene Submit-Route
  durch denselben Funnel (Blacklist, Quota, Status-Log)
- Klassifikation Rot/Gelb/Gruen asynchron (Queue classification,
  OpenAI-Treiber + deterministischer Fallback), ki_audits-Audit-Log
- Routing: Rot -> rejected + Mail, Gelb -> Review-Queue, Gruen ->
  Auto-Publish; Scheduler publiziert nur gruene faellige PMs
- Content-Score 0-100 -> Stufe (Standard/Geprueft/Hochwertig) inkl.
  Editor-Panel und Badges; Re-Klassifikation/-Score bei Aenderung
- Admin: KI-Badge + Filter, On-Demand-Pruefung mit Anbieter-Override

Suite: 442 passed, 4 skipped.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-12 08:30:13 +00:00

141 lines
5 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
use App\Models\Category;
use App\Models\Company;
use App\Models\Contact;
use App\Models\PressRelease;
use App\Models\User;
use Database\Seeders\RolesAndPermissionsSeeder;
use Illuminate\Support\Carbon;
use Livewire\Volt\Volt as LivewireVolt;
use Tests\TestCase;
beforeEach(function (): void {
/** @var TestCase $this */
$this->seed(RolesAndPermissionsSeeder::class);
});
function makeSchedulingCustomer(): array
{
$customer = User::factory()->create(['is_active' => true]);
$customer->assignRole('customer');
$company = Company::factory()->presseecho()->create();
$customer->companies()->attach($company->id, ['role' => 'owner']);
$contact = Contact::factory()->for($company)->create([
'portal' => $company->portal->value,
]);
$category = Category::factory()->create();
return compact('customer', 'company', 'contact', 'category');
}
test('create form persistiert scheduled_at aus datum und uhrzeit ohne embargo', function () {
/** @var TestCase $this */
Carbon::setTestNow('2026-06-01 10:00:00');
['customer' => $customer, 'category' => $category] = makeSchedulingCustomer();
$this->actingAs($customer);
LivewireVolt::test('customer.press-releases.create')
->set('title', 'Phase 7F Scheduling Demo')
->set('text', str_repeat('Inhalt eines Tests. ', 5))
->set('categoryId', $category->id)
->set('publishMode', 'scheduled')
->set('scheduledDate', '2026-06-05')
->set('scheduledTime', '14:30')
->set('useEmbargo', true)
->set('embargoAt', '2026-06-10T08:00')
->call('save')
->assertHasNoErrors();
$pr = PressRelease::query()->latest('id')->firstOrFail();
// Eingabe 14:30 erfolgt in Europe/Berlin (CEST, +02:00) und wird als
// 12:30 UTC gespeichert.
expect($pr->scheduled_at?->toDateTimeString())->toBe('2026-06-05 12:30:00');
expect($pr->scheduled_at?->copy()->setTimezone('Europe/Berlin')->format('Y-m-d H:i'))->toBe('2026-06-05 14:30');
expect($pr->embargo_at)->toBeNull();
});
test('create form lehnt scheduled_at in der Vergangenheit ab', function () {
/** @var TestCase $this */
Carbon::setTestNow('2026-06-01 10:00:00');
['customer' => $customer, 'category' => $category] = makeSchedulingCustomer();
$this->actingAs($customer);
LivewireVolt::test('customer.press-releases.create')
->set('title', 'Vergangene Veröffentlichung')
->set('text', str_repeat('Inhalt eines Tests. ', 5))
->set('categoryId', $category->id)
->set('publishMode', 'scheduled')
->set('scheduledAt', '2026-05-30T10:00')
->call('save')
->assertHasErrors(['scheduledAt']);
});
test('create form lehnt geplanten termin aus datum und uhrzeit in der vergangenheit ab', function () {
/** @var TestCase $this */
Carbon::setTestNow('2026-06-01 10:00:00');
['customer' => $customer, 'category' => $category] = makeSchedulingCustomer();
$this->actingAs($customer);
LivewireVolt::test('customer.press-releases.create')
->set('publishMode', 'scheduled')
->set('scheduledDate', '2026-05-30')
->set('scheduledTime', '10:00')
->call('save')
->assertHasErrors(['scheduledAt']);
});
test('publishMode now setzt scheduled_at auf null beim Save', function () {
/** @var TestCase $this */
['customer' => $customer, 'category' => $category] = makeSchedulingCustomer();
$this->actingAs($customer);
LivewireVolt::test('customer.press-releases.create')
->set('title', 'Sofort veröffentlichen')
->set('text', str_repeat('Inhalt eines Tests. ', 5))
->set('categoryId', $category->id)
->set('publishMode', 'now')
->set('scheduledAt', '2026-12-31T12:00')
->call('save')
->assertHasNoErrors();
$pr = PressRelease::query()->latest('id')->firstOrFail();
expect($pr->scheduled_at)->toBeNull();
});
test('edit form hydriert scheduled_at in datum und uhrzeit ohne embargo', function () {
/** @var TestCase $this */
Carbon::setTestNow('2026-06-01 10:00:00');
['customer' => $customer, 'company' => $company, 'contact' => $contact, 'category' => $category] = makeSchedulingCustomer();
$pr = PressRelease::factory()->create([
'user_id' => $customer->id,
'company_id' => $company->id,
'category_id' => $category->id,
'portal' => $company->portal->value,
'status' => 'draft',
// 12:30 UTC entspricht 14:30 in Europe/Berlin (CEST) so wird der
// Termin in den Eingabefeldern angezeigt.
'scheduled_at' => '2026-06-05 12:30:00',
'embargo_at' => '2026-06-10 08:00:00',
]);
$pr->contacts()->sync([$contact->id]);
$this->actingAs($customer);
LivewireVolt::test('customer.press-releases.edit', ['id' => $pr->id])
->assertSet('publishMode', 'scheduled')
->assertSet('scheduledAt', '2026-06-05T14:30')
->assertSet('scheduledDate', '2026-06-05')
->assertSet('scheduledTime', '14:30')
->assertSet('useEmbargo', false)
->assertSet('embargoAt', null);
});