'Export Test Song', 'ccli_id' => '54321', 'author' => 'Test Author', 'copyright_text' => 'Test Publisher', 'copyright_year' => 2024, 'publisher' => 'Test Publisher', ]); $verse = $song->groups()->create(['name' => 'Verse 1', 'color' => '#2196F3', 'order' => 0]); $verse->slides()->create(['order' => 0, 'text_content' => 'First line of verse']); $verse->slides()->create(['order' => 1, 'text_content' => 'Second line of verse']); $chorus = $song->groups()->create(['name' => 'Chorus', 'color' => '#F44336', 'order' => 1]); $chorus->slides()->create(['order' => 0, 'text_content' => 'Chorus text']); $arrangement = $song->arrangements()->create(['name' => 'normal', 'is_default' => true]); $arrangement->arrangementGroups()->create(['song_group_id' => $verse->id, 'order' => 0]); $arrangement->arrangementGroups()->create(['song_group_id' => $chorus->id, 'order' => 1]); $arrangement->arrangementGroups()->create(['song_group_id' => $verse->id, 'order' => 2]); return $song; } public function test_download_pro_gibt_datei_zurueck(): void { $user = User::factory()->create(); $song = $this->createSongWithContent(); $response = $this->actingAs($user)->get("/api/songs/{$song->id}/download-pro"); $response->assertOk(); $response->assertHeader('content-disposition'); $this->assertStringContains('Export Test Song.pro', $response->headers->get('content-disposition')); } public function test_download_pro_song_ohne_gruppen_gibt_422(): void { $user = User::factory()->create(); $song = Song::factory()->create(); $response = $this->actingAs($user)->get("/api/songs/{$song->id}/download-pro"); $response->assertStatus(422); } public function test_download_pro_erfordert_authentifizierung(): void { $song = Song::factory()->create(); $response = $this->getJson("/api/songs/{$song->id}/download-pro"); $response->assertUnauthorized(); } public function test_download_pro_roundtrip_import_export(): void { $user = User::factory()->create(); $sourcePath = base_path('../propresenter-work/ref/Test.pro'); $file = new \Illuminate\Http\UploadedFile($sourcePath, 'Test.pro', 'application/octet-stream', null, true); $importResponse = $this->actingAs($user)->postJson(route('api.songs.import-pro'), ['file' => $file]); $importResponse->assertOk(); $songId = $importResponse->json('songs.0.id'); $song = Song::find($songId); $this->assertNotNull($song); $this->assertGreaterThan(0, $song->groups()->count()); $exportResponse = $this->actingAs($user)->get("/api/songs/{$songId}/download-pro"); $exportResponse->assertOk(); } private function assertStringContains(string $needle, ?string $haystack): void { $this->assertNotNull($haystack); $this->assertTrue( str_contains($haystack, $needle), "Failed asserting that '{$haystack}' contains '{$needle}'" ); } }