pp-planer/tests/Feature/ArrangementControllerTest.php
Thorsten Bus d915f8cfc2 feat: Wave 2 - Service list, Song CRUD, Slide upload, Arrangements, Song matching, Translation
T8: Service List Page
- ServiceController with index, finalize, reopen actions
- Services/Index.vue with status indicators (songs mapped/arranged, slides uploaded)
- German UI with finalize/reopen toggle buttons
- Status aggregation via SQL subqueries for efficiency
- Tests: 3 passing (46 assertions)

T9: Song CRUD Backend
- SongController with full REST API (index, store, show, update, destroy)
- SongService for default groups/arrangements creation
- SongRequest validation (title required, ccli_id unique)
- Search by title and CCLI ID
- last_used_in_service accessor via service_songs join
- Tests: 20 passing (85 assertions)

T10: Slide Upload Component
- SlideController with store, destroy, updateExpireDate
- SlideUploader.vue with vue3-dropzone drag-and-drop
- SlideGrid.vue with thumbnail grid and inline expire date editing
- Multi-format support: images (sync), PPT (async job), ZIP (extract)
- Type validation: information (global), moderation/sermon (service-specific)
- Tests: 15 passing (37 assertions)

T11: Arrangement Configurator
- ArrangementController with store, clone, update, destroy
- ArrangementConfigurator.vue with vue-draggable-plus
- Drag-and-drop arrangement editor with colored group pills
- Clone from default or existing arrangement
- Color picker for group customization
- Prevent deletion of last arrangement
- Tests: 4 passing (17 assertions)

T12: Song Matching Service
- SongMatchingService with autoMatch, manualAssign, requestCreation, unassign
- ServiceSongController API endpoints for song assignment
- Auto-match by CCLI ID during CTS sync
- Manual assignment with searchable song select
- Email request for missing songs (MissingSongRequest mailable)
- Tests: 14 passing (33 assertions)

T13: Translation Service
- TranslationService with fetchFromUrl, importTranslation, removeTranslation
- TranslationController API endpoints
- URL scraping (best-effort HTTP fetch with strip_tags)
- Line-count distribution algorithm (match original slide line counts)
- Mark song as translated, remove translation
- Tests: 18 passing (18 assertions)

All tests passing: 103/103 (488 assertions)
Build: ✓ Vite production build successful
German UI: All user-facing text in German with 'Du' form
2026-03-01 19:55:37 +01:00

184 lines
5.4 KiB
PHP

<?php
namespace Tests\Feature;
use App\Models\Song;
use App\Models\SongArrangement;
use App\Models\SongArrangementGroup;
use App\Models\SongGroup;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Auth;
use Tests\TestCase;
class ArrangementControllerTest extends TestCase
{
use RefreshDatabase;
public function test_create_arrangement_clones_groups_from_default_arrangement(): void
{
[$song, $normal] = $this->createSongWithDefaultArrangement();
$user = User::factory()->create();
Auth::login($user);
$response = $this->post(route('arrangements.store', $song), [
'name' => 'Kurz',
]);
$response->assertRedirect();
$newArrangement = SongArrangement::query()
->where('song_id', $song->id)
->where('name', 'Kurz')
->first();
$this->assertNotNull($newArrangement);
$normalGroups = SongArrangementGroup::query()
->where('song_arrangement_id', $normal->id)
->orderBy('order')
->pluck('song_group_id')
->all();
$newGroups = SongArrangementGroup::query()
->where('song_arrangement_id', $newArrangement->id)
->orderBy('order')
->pluck('song_group_id')
->all();
$this->assertSame($normalGroups, $newGroups);
}
public function test_clone_arrangement_duplicates_current_arrangement_groups(): void
{
[$song, $normal] = $this->createSongWithDefaultArrangement();
$user = User::factory()->create();
Auth::login($user);
$response = $this->post(route('arrangements.clone', $normal), [
'name' => 'Normal Kopie',
]);
$response->assertRedirect();
$clone = SongArrangement::query()
->where('song_id', $song->id)
->where('name', 'Normal Kopie')
->first();
$this->assertNotNull($clone);
$this->assertFalse($clone->is_default);
$originalGroups = SongArrangementGroup::query()
->where('song_arrangement_id', $normal->id)
->orderBy('order')
->pluck('song_group_id')
->all();
$cloneGroups = SongArrangementGroup::query()
->where('song_arrangement_id', $clone->id)
->orderBy('order')
->pluck('song_group_id')
->all();
$this->assertSame($originalGroups, $cloneGroups);
}
public function test_update_arrangement_reorders_and_persists_groups(): void
{
[, $normal, $verse, $chorus, $bridge] = $this->createSongWithDefaultArrangement();
$user = User::factory()->create();
Auth::login($user);
$response = $this->put(route('arrangements.update', $normal), [
'groups' => [
['song_group_id' => $chorus->id, 'order' => 1],
['song_group_id' => $bridge->id, 'order' => 2],
['song_group_id' => $verse->id, 'order' => 3],
['song_group_id' => $chorus->id, 'order' => 4],
],
]);
$response->assertRedirect();
$updated = SongArrangementGroup::query()
->where('song_arrangement_id', $normal->id)
->orderBy('order')
->pluck('song_group_id')
->all();
$this->assertSame([
$chorus->id,
$bridge->id,
$verse->id,
$chorus->id,
], $updated);
}
public function test_cannot_delete_the_last_arrangement_of_a_song(): void
{
[$song, $normal] = $this->createSongWithDefaultArrangement();
$user = User::factory()->create();
Auth::login($user);
$this->assertSame(1, $song->arrangements()->count());
$response = $this->delete(route('arrangements.destroy', $normal));
$response->assertRedirect();
$response->assertSessionHas('error', 'Das letzte Arrangement kann nicht gelöscht werden.');
$this->assertTrue(SongArrangement::query()->whereKey($normal->id)->exists());
$this->assertSame(1, $song->arrangements()->count());
}
private function createSongWithDefaultArrangement(): array
{
$song = Song::factory()->create();
$verse = SongGroup::factory()->create([
'song_id' => $song->id,
'name' => 'Verse 1',
'order' => 1,
]);
$chorus = SongGroup::factory()->create([
'song_id' => $song->id,
'name' => 'Chorus',
'order' => 2,
]);
$bridge = SongGroup::factory()->create([
'song_id' => $song->id,
'name' => 'Bridge',
'order' => 3,
]);
$normal = SongArrangement::factory()->create([
'song_id' => $song->id,
'name' => 'Normal',
'is_default' => true,
]);
SongArrangementGroup::factory()->create([
'song_arrangement_id' => $normal->id,
'song_group_id' => $verse->id,
'order' => 1,
]);
SongArrangementGroup::factory()->create([
'song_arrangement_id' => $normal->id,
'song_group_id' => $chorus->id,
'order' => 2,
]);
SongArrangementGroup::factory()->create([
'song_arrangement_id' => $normal->id,
'song_group_id' => $verse->id,
'order' => 3,
]);
return [$song, $normal, $verse, $chorus, $bridge];
}
}