Refactor lyric storage so each song owns its sections instead of sharing global labels. Adds song_sections (per song+label) owning song_slides; labels stay global ProPresenter group tags (name/color/macro). Arrangements now reference sections, so editing/importing one song no longer corrupts others that share a label name. - New: song_sections table + migration with safe backfill; SongSection, SongArrangementSection models; SongSectionController (edit/add/delete sections, immediate persistence) wired into SongEditModal. - Refactor writers/readers: CcliImport, ProImport, SongService, ArrangementController, SongController, ProExport, PDF, Translation (translation reset now section-scoped), CCLI pairing. - CCLI import fixes: parse SongSelect copy-icon format (German "Vers" abbrev + trailing author), fill empty CTS-synced songs instead of blocking as duplicate, distinct label colors per section kind, import&edit/existing-song open the edit modal (no 404/405), teleport paste dialog above assign dialog, preview shows section content, correct SongSelect search URL, copy-icon instructions. - Bookmarklet clicks #generalCopyLyricsButton and captures clipboard; serves correct host from request. - Export: embed key-visual/background under fixed bundle-relative names. - Tests updated for the section model; new section + isolation coverage.
175 lines
5.6 KiB
PHP
175 lines
5.6 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Models\Label;
|
|
use App\Models\Song;
|
|
use App\Models\SongArrangement;
|
|
use App\Models\SongArrangementLabel;
|
|
use App\Models\SongSection;
|
|
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_uses_default_song_group_ordering(): 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);
|
|
|
|
$defaultLabelOrder = SongArrangementLabel::query()
|
|
->where('song_arrangement_id', $normal->id)
|
|
->orderBy('order')
|
|
->pluck('song_section_id')
|
|
->all();
|
|
|
|
$newLabels = SongArrangementLabel::query()
|
|
->where('song_arrangement_id', $newArrangement->id)
|
|
->orderBy('order')
|
|
->pluck('song_section_id')
|
|
->all();
|
|
|
|
$this->assertSame($defaultLabelOrder, $newLabels);
|
|
}
|
|
|
|
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);
|
|
|
|
$originalLabels = SongArrangementLabel::query()
|
|
->where('song_arrangement_id', $normal->id)
|
|
->orderBy('order')
|
|
->pluck('song_section_id')
|
|
->all();
|
|
|
|
$cloneLabels = SongArrangementLabel::query()
|
|
->where('song_arrangement_id', $clone->id)
|
|
->orderBy('order')
|
|
->pluck('song_section_id')
|
|
->all();
|
|
|
|
$this->assertSame($originalLabels, $cloneLabels);
|
|
}
|
|
|
|
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' => [
|
|
['section_id' => $chorus->id, 'order' => 1],
|
|
['section_id' => $bridge->id, 'order' => 2],
|
|
['section_id' => $verse->id, 'order' => 3],
|
|
['section_id' => $chorus->id, 'order' => 4],
|
|
],
|
|
]);
|
|
|
|
$response->assertRedirect();
|
|
|
|
$updated = SongArrangementLabel::query()
|
|
->where('song_arrangement_id', $normal->id)
|
|
->orderBy('order')
|
|
->pluck('song_section_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();
|
|
|
|
$verseLabel = Label::factory()->create(['name' => 'Verse 1']);
|
|
$chorusLabel = Label::factory()->create(['name' => 'Chorus']);
|
|
$bridgeLabel = Label::factory()->create(['name' => 'Bridge']);
|
|
|
|
$verse = SongSection::factory()->create(['song_id' => $song->id, 'label_id' => $verseLabel->id, 'order' => 1]);
|
|
$chorus = SongSection::factory()->create(['song_id' => $song->id, 'label_id' => $chorusLabel->id, 'order' => 2]);
|
|
$bridge = SongSection::factory()->create(['song_id' => $song->id, 'label_id' => $bridgeLabel->id, 'order' => 3]);
|
|
|
|
$normal = SongArrangement::factory()->create([
|
|
'song_id' => $song->id,
|
|
'name' => 'Normal',
|
|
'is_default' => true,
|
|
]);
|
|
|
|
SongArrangementLabel::factory()->create([
|
|
'song_arrangement_id' => $normal->id,
|
|
'song_section_id' => $verse->id,
|
|
'order' => 1,
|
|
]);
|
|
|
|
SongArrangementLabel::factory()->create([
|
|
'song_arrangement_id' => $normal->id,
|
|
'song_section_id' => $chorus->id,
|
|
'order' => 2,
|
|
]);
|
|
|
|
SongArrangementLabel::factory()->create([
|
|
'song_arrangement_id' => $normal->id,
|
|
'song_section_id' => $verse->id,
|
|
'order' => 3,
|
|
]);
|
|
|
|
return [$song, $normal, $verse, $chorus, $bridge];
|
|
}
|
|
}
|