pp-planer/tests/Feature/ServiceControllerTest.php
Thorsten Bus b2d230e991 feat: Wave 3 (partial) - Service Edit page + 4 blocks (T14-T18)
T14: Service Edit Page Layout + Routing
- ServiceController::edit() with eager-loaded relationships
- Services/Edit.vue with 4 collapsible accordion blocks
- Route: GET /services/{service}/edit
- Information slides query: global + service-specific with expire_date filtering
- Tests: 2 new (edit page render + auth guard)

T15: Information Block (Slides + Expire Dates)
- InformationBlock.vue with dynamic expire_date filtering
- Shows slides where type='information' AND expire_date >= service.date
- Global visibility across services (not service-specific)
- SlideUploader with showExpireDate=true
- SlideGrid with prominent expire date + inline editing
- Badge showing slide count + 'expiring soon' warning (within 3 days)
- Tests: 7 new (105 assertions)

T16: Moderation Block (Service-Specific)
- ModerationBlock.vue (service-specific slides)
- Filters: type='moderation' AND service_id = current_service
- No expire date field (unlike Information block)
- Service isolation (slides from Service A don't appear in Service B)
- Tests: 5 new (14 assertions)

T17: Sermon Block (Service-Specific)
- SermonBlock.vue (identical to Moderation but type='sermon')
- Service-specific slides, no expire date
- Tests: 5 new (14 assertions)

T18: Songs Block (Matching + Arrangement + Translation)
- SongsBlock.vue with conditional UI (unmatched vs matched states)
- Unmatched: 'Erstellung anfragen' button + searchable select for manual assign
- Matched: ArrangementConfigurator + translation checkbox + preview/download buttons
- ServiceSongController::update() for use_translation and song_arrangement_id
- ArrangementConfigurator emits 'arrangement-selected' for auto-save
- ServiceController::edit() provides songsCatalog for matching search
- Tests: 2 new (45 assertions)

T19: Song PDF (INCOMPLETE - timeout)
- SongPdfController.php created (partial)
- resources/views/pdf/song.blade.php created (partial)
- SongPreviewModal.vue MISSING
- Tests MISSING
- Will be completed in next commit

All tests passing: 124/124 (703 assertions)
Build: ✓ Vite production build successful
German UI: All user-facing text in German with 'Du' form
Dependencies: barryvdh/laravel-dompdf added for PDF generation
2026-03-01 20:09:47 +01:00

272 lines
8.7 KiB
PHP

<?php
namespace Tests\Feature;
use App\Models\Service;
use App\Models\ServiceSong;
use App\Models\Slide;
use App\Models\Song;
use App\Models\SongArrangement;
use App\Models\User;
use Carbon\Carbon;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
final class ServiceControllerTest extends TestCase
{
use RefreshDatabase;
public function test_services_index_zeigt_nur_heutige_und_kuenftige_services_mit_statusdaten(): void
{
Carbon::setTestNow('2026-03-01 10:00:00');
$this->withoutVite();
$user = User::factory()->create();
Service::factory()->create([
'date' => Carbon::today()->subDay(),
'finalized_at' => null,
]);
$todayService = Service::factory()->create([
'title' => 'Gottesdienst Heute',
'date' => Carbon::today(),
'finalized_at' => null,
]);
$futureService = Service::factory()->create([
'title' => 'Gottesdienst Zukunft',
'date' => Carbon::today()->addDays(3),
'finalized_at' => null,
]);
$song = Song::factory()->create();
$arrangement = SongArrangement::factory()->create([
'song_id' => $song->id,
]);
ServiceSong::create([
'service_id' => $todayService->id,
'song_id' => $song->id,
'song_arrangement_id' => $arrangement->id,
'use_translation' => false,
'order' => 1,
'cts_song_name' => 'Song 1',
'cts_ccli_id' => '100001',
]);
ServiceSong::create([
'service_id' => $todayService->id,
'song_id' => $song->id,
'song_arrangement_id' => null,
'use_translation' => false,
'order' => 2,
'cts_song_name' => 'Song 2',
'cts_ccli_id' => '100002',
]);
ServiceSong::create([
'service_id' => $todayService->id,
'song_id' => null,
'song_arrangement_id' => null,
'use_translation' => false,
'order' => 3,
'cts_song_name' => 'Song 3',
'cts_ccli_id' => '100003',
]);
ServiceSong::create([
'service_id' => $futureService->id,
'song_id' => $song->id,
'song_arrangement_id' => $arrangement->id,
'use_translation' => false,
'order' => 1,
'cts_song_name' => 'Song 4',
'cts_ccli_id' => '100004',
]);
ServiceSong::create([
'service_id' => $futureService->id,
'song_id' => null,
'song_arrangement_id' => null,
'use_translation' => false,
'order' => 2,
'cts_song_name' => 'Song 5',
'cts_ccli_id' => '100005',
]);
Slide::factory()->create([
'service_id' => $todayService->id,
'type' => 'sermon',
'expire_date' => null,
]);
Slide::factory()->create([
'service_id' => null,
'type' => 'information',
'expire_date' => Carbon::today()->addDay(),
]);
Slide::factory()->create([
'service_id' => null,
'type' => 'information',
'expire_date' => Carbon::today()->addDays(5),
]);
Slide::factory()->create([
'service_id' => $todayService->id,
'type' => 'information',
'expire_date' => Carbon::today()->addDays(10),
]);
Slide::factory()->create([
'service_id' => null,
'type' => 'information',
'expire_date' => Carbon::today()->subDay(),
]);
$response = $this->actingAs($user)->get(route('services.index'));
$response->assertOk();
$response->assertInertia(
fn ($page) => $page
->component('Services/Index')
->has('services', 2)
->where('services.0.id', $todayService->id)
->where('services.0.title', 'Gottesdienst Heute')
->where('services.0.songs_total_count', 3)
->where('services.0.songs_mapped_count', 2)
->where('services.0.songs_arranged_count', 1)
->where('services.0.has_sermon_slides', true)
->where('services.0.info_slides_count', 3)
->where('services.1.id', $futureService->id)
->where('services.1.title', 'Gottesdienst Zukunft')
->where('services.1.songs_total_count', 2)
->where('services.1.songs_mapped_count', 1)
->where('services.1.songs_arranged_count', 1)
->where('services.1.has_sermon_slides', false)
->where('services.1.info_slides_count', 1)
);
}
public function test_service_kann_abgeschlossen_werden(): void
{
Carbon::setTestNow('2026-03-01 10:00:00');
$user = User::factory()->create();
$service = Service::factory()->create([
'finalized_at' => null,
]);
$response = $this->actingAs($user)->post(route('services.finalize', $service));
$response->assertRedirect(route('services.index'));
$this->assertSame(now()->toDateTimeString(), $service->fresh()->finalized_at?->toDateTimeString());
}
public function test_service_kann_wieder_geoeffnet_werden(): void
{
$user = User::factory()->create();
$service = Service::factory()->create([
'finalized_at' => now(),
]);
$response = $this->actingAs($user)->post(route('services.reopen', $service));
$response->assertRedirect(route('services.index'));
$this->assertNull($service->fresh()->finalized_at);
}
public function test_service_edit_seite_zeigt_service_mit_songs_und_slides(): void
{
Carbon::setTestNow('2026-03-01 10:00:00');
$this->withoutVite();
$user = User::factory()->create();
$service = Service::factory()->create([
'title' => 'Gottesdienst',
'date' => Carbon::today()->addDays(7),
'preacher_name' => 'Pastor Mueller',
'finalized_at' => null,
]);
$song = Song::factory()->create([
'title' => 'Amazing Grace',
'ccli_id' => '4321',
'has_translation' => true,
]);
$arrangement = SongArrangement::factory()->create([
'song_id' => $song->id,
'name' => 'Normal',
]);
ServiceSong::create([
'service_id' => $service->id,
'song_id' => $song->id,
'song_arrangement_id' => $arrangement->id,
'use_translation' => true,
'order' => 1,
'cts_song_name' => 'Amazing Grace',
'cts_ccli_id' => '4321',
]);
ServiceSong::create([
'service_id' => $service->id,
'song_id' => null,
'song_arrangement_id' => null,
'use_translation' => false,
'order' => 2,
'cts_song_name' => 'Unbekannter Song',
'cts_ccli_id' => '9999',
]);
Slide::factory()->create([
'service_id' => $service->id,
'type' => 'sermon',
]);
Slide::factory()->create([
'service_id' => $service->id,
'type' => 'moderation',
]);
Slide::factory()->create([
'service_id' => null,
'type' => 'information',
'expire_date' => Carbon::today()->addDays(14),
]);
$response = $this->actingAs($user)->get(route('services.edit', $service));
$response->assertOk();
$response->assertInertia(
fn ($page) => $page
->component('Services/Edit')
->has('service')
->where('service.title', 'Gottesdienst')
->where('service.preacher_name', 'Pastor Mueller')
->has('serviceSongs', 2)
->where('serviceSongs.0.cts_song_name', 'Amazing Grace')
->where('serviceSongs.0.song.title', 'Amazing Grace')
->where('serviceSongs.0.song.has_translation', true)
->where('serviceSongs.0.arrangement.name', 'Normal')
->where('serviceSongs.1.cts_song_name', 'Unbekannter Song')
->where('serviceSongs.1.song', null)
->has('informationSlides', 1)
->has('moderationSlides', 1)
->has('sermonSlides', 1)
);
}
public function test_service_edit_erfordert_authentifizierung(): void
{
$service = Service::factory()->create();
$response = $this->get(route('services.edit', $service));
$response->assertRedirect(route('login'));
}
}