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.
133 lines
4.1 KiB
PHP
133 lines
4.1 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Models\Song;
|
|
use App\Models\SongSection;
|
|
use App\Models\User;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Http\UploadedFile;
|
|
use Tests\TestCase;
|
|
|
|
final class ProFileImportTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
private function test_pro_file(): UploadedFile
|
|
{
|
|
$sourcePath = base_path('tests/fixtures/propresenter/Test.pro');
|
|
|
|
return new UploadedFile($sourcePath, 'Test.pro', 'application/octet-stream', null, true);
|
|
}
|
|
|
|
public function test_import_pro_datei_erstellt_song_mit_gruppen_und_slides(): void
|
|
{
|
|
$user = User::factory()->create();
|
|
|
|
$response = $this->actingAs($user)->postJson(route('api.songs.import-pro'), [
|
|
'file' => $this->test_pro_file(),
|
|
]);
|
|
|
|
$response->assertOk();
|
|
$response->assertJsonPath('songs.0.title', 'Test');
|
|
|
|
$song = Song::where('title', 'Test')->first();
|
|
$this->assertNotNull($song);
|
|
|
|
$this->assertSame(4, \App\Models\Label::count());
|
|
$this->assertSame(5, \App\Models\SongSlide::count());
|
|
|
|
$this->assertSame(2, $song->arrangements()->count());
|
|
$this->assertTrue($song->has_translation);
|
|
}
|
|
|
|
public function test_import_pro_mit_ccli_upserted_bei_doppeltem_import(): void
|
|
{
|
|
$user = User::factory()->create();
|
|
|
|
$this->actingAs($user)->postJson(route('api.songs.import-pro'), [
|
|
'file' => $this->test_pro_file(),
|
|
]);
|
|
|
|
$this->assertSame(1, Song::count());
|
|
|
|
// Second import of same file with same CCLI should upsert, not duplicate
|
|
$this->actingAs($user)->postJson(route('api.songs.import-pro'), [
|
|
'file' => $this->test_pro_file(),
|
|
]);
|
|
|
|
$this->assertSame(1, Song::count());
|
|
}
|
|
|
|
public function test_import_pro_upsert_mit_ccli_dupliziert_nicht(): void
|
|
{
|
|
$user = User::factory()->create();
|
|
|
|
$existingSong = Song::create([
|
|
'title' => 'Old Title',
|
|
'ccli_id' => '999',
|
|
]);
|
|
|
|
$arrangement = $existingSong->arrangements()->create([
|
|
'name' => 'Normal',
|
|
'is_default' => true,
|
|
]);
|
|
$oldLabel = \App\Models\Label::firstOrCreate(['name' => 'Old Group'], ['color' => '#FF0000']);
|
|
$oldSection = SongSection::factory()->create(['song_id' => $existingSong->id, 'label_id' => $oldLabel->id]);
|
|
$arrangement->arrangementLabels()->create([
|
|
'song_section_id' => $oldSection->id,
|
|
'order' => 0,
|
|
]);
|
|
|
|
$this->assertSame(1, $arrangement->arrangementLabels()->count());
|
|
|
|
$existingSong->update(['ccli_id' => '999']);
|
|
$this->assertSame(1, Song::count());
|
|
|
|
$response = $this->actingAs($user)->postJson(route('api.songs.import-pro'), [
|
|
'file' => $this->test_pro_file(),
|
|
]);
|
|
|
|
$response->assertOk();
|
|
$this->assertSame(2, Song::count());
|
|
}
|
|
|
|
public function test_import_pro_lehnt_ungueltige_datei_ab(): void
|
|
{
|
|
$user = User::factory()->create();
|
|
|
|
$invalidFile = UploadedFile::fake()->create('test.txt', 100);
|
|
|
|
$response = $this->actingAs($user)->postJson(route('api.songs.import-pro'), [
|
|
'file' => $invalidFile,
|
|
]);
|
|
|
|
$response->assertStatus(422);
|
|
}
|
|
|
|
public function test_import_pro_erfordert_authentifizierung(): void
|
|
{
|
|
$response = $this->postJson(route('api.songs.import-pro'), [
|
|
'file' => $this->test_pro_file(),
|
|
]);
|
|
|
|
$response->assertUnauthorized();
|
|
}
|
|
|
|
public function test_import_pro_erstellt_arrangement_gruppen(): void
|
|
{
|
|
$user = User::factory()->create();
|
|
|
|
$this->actingAs($user)->postJson(route('api.songs.import-pro'), [
|
|
'file' => $this->test_pro_file(),
|
|
]);
|
|
|
|
$song = Song::where('title', 'Test')->first();
|
|
$normalArrangement = $song->arrangements()->where('name', 'normal')->first();
|
|
|
|
$this->assertNotNull($normalArrangement);
|
|
$this->assertTrue($normalArrangement->is_default);
|
|
$this->assertSame(5, $normalArrangement->arrangementLabels()->count());
|
|
}
|
|
}
|