pp-planer/tests/Feature/SongCcliMetadataTest.php
Thorsten Bus ae42b48753 feat(songs): per-song sections + section editing; fix CCLI import bugs
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.
2026-05-31 14:45:47 +02:00

50 lines
1.7 KiB
PHP

<?php
use App\Models\Song;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Schema;
uses(RefreshDatabase::class);
test('songs table has imported_from_ccli_at and ccli_source_url columns', function (): void {
expect(Schema::hasColumn('songs', 'imported_from_ccli_at'))->toBeTrue();
expect(Schema::hasColumn('songs', 'ccli_source_url'))->toBeTrue();
});
test('imported_from_ccli_at defaults to null', function (): void {
$song = Song::factory()->create();
expect($song->fresh()->imported_from_ccli_at)->toBeNull();
});
test('ccli_source_url defaults to null', function (): void {
$song = Song::factory()->create();
expect($song->fresh()->ccli_source_url)->toBeNull();
});
test('imported_from_ccli_at casts to Carbon instance', function (): void {
$song = Song::factory()->create(['imported_from_ccli_at' => '2026-05-10 12:00:00']);
expect($song->fresh()->imported_from_ccli_at)->toBeInstanceOf(Carbon::class);
});
test('fromCcli factory state populates both fields', function (): void {
$song = Song::factory()->fromCcli()->create();
$fresh = $song->fresh();
expect($fresh->imported_from_ccli_at)->not->toBeNull();
expect($fresh->imported_from_ccli_at)->toBeInstanceOf(Carbon::class);
expect($fresh->ccli_source_url)->not->toBeNull();
expect($fresh->ccli_source_url)->toContain('songselect.ccli.com');
});
test('migration rolls back cleanly', function (): void {
$this->expectException(RuntimeException::class);
$this->expectExceptionMessage('Destruktive Migration');
Artisan::call('migrate:rollback', ['--step' => 1]);
});