pp-planer/tests/Feature/ProFileImportTest.php
Thorsten Bus e33418f716 feat: song pre/postfix, settings overhaul, export & schedule fixes
Resolves a batch of bugs and feature requests across songs, services,
settings and export:

Songs & sections
- Every song now carries permanent, empty, locked PREFIX (COPYRIGHT) and
  POSTFIX (BLANK) sections, deduplicated on import; locked sections cannot
  be edited or deleted via UI or API.
- Song edit modal: explicit Speichern/Schließen with dirty-tracking,
  editable section headline (combobox + custom values), and a fix for the
  419 CSRF errors after CCLI "Importieren & Bearbeiten" (token read fresh
  per request).
- CCLI bookmarklet "Importieren & Bearbeiten" now opens the edit dialog.

Service schedule & arrangements
- Fixed assigned songs showing no sections (slides loaded for all
  arrangements, not just the default).
- Added "Song entfernen / neu zuordnen" to reassign an assigned song.
- Worship-leader arrangement is created/selected lazily when the
  arrangement dialog opens (only when not user-overridden); the leader is
  resolved from the "Lobpreis" agenda item, and manual create/clone names
  are prefixed with the leader name.

Navigation
- "/" redirects to the next upcoming service's edit page (or the list).
- Service titles link to the edit page.

Settings
- Renamed "Makro-Import"/"Label-Import" menu items; fixed drag-and-drop
  imports (were downloading the dropped file); added label-import hint;
  made the panel scrollable.
- Nametag now uses a single MacroPicker; added song prefix/postfix label
  defaults (COPYRIGHT #24B34C / BLANK #000000); new "Export-Dateien" menu
  to upload prefix/postfix .pro files added to every export.

Export
- Filenames/playlist names are date-first ("YYYY-MM-DD <Title>").
- Keyvisual slide only for the first content-less item after real content;
  all other content-less items render as headlines.
- New "Vorschau herunterladen" for non-finalized services (filename and
  import name prefixed "Vorschau" with export timestamp).
- Uploaded prefix/postfix .pro files wrap every export.

Tests updated to the new behavior; full suite green (569 passed).
2026-06-01 08:56:20 +02:00

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(6, \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(7, $normalArrangement->arrangementLabels()->count());
}
}