-
- Predigtfolien
-
-
- Folien für diesen Gottesdienst
-
+
+
+
+
+
+ {{ sermonSlides.length }} {{ sermonSlides.length === 1 ? 'Folie' : 'Folien' }}
+
+
+
+
-
+
+
+
+
+
diff --git a/routes/web.php b/routes/web.php
index 21b8db2..22e1946 100644
--- a/routes/web.php
+++ b/routes/web.php
@@ -56,6 +56,7 @@
Route::post('/services/{service}/reopen', [ServiceController::class, 'reopen'])->name('services.reopen');
Route::delete('/services/{service}', [ServiceController::class, 'destroy'])->name('services.destroy');
Route::get('/services/{service}/download', [ServiceController::class, 'download'])->name('services.download');
+ Route::get('/services/{service}/download-bundle/{blockType}', [ServiceController::class, 'downloadBundle'])->name('services.download-bundle');
Route::get('/services/{service}/edit', [ServiceController::class, 'edit'])->name('services.edit');
Route::get('/songs/{song}/translate', [TranslationController::class, 'page'])->name('songs.translate');
diff --git a/tests/Feature/ProBundleExportTest.php b/tests/Feature/ProBundleExportTest.php
new file mode 100644
index 0000000..eb09f8b
--- /dev/null
+++ b/tests/Feature/ProBundleExportTest.php
@@ -0,0 +1,129 @@
+create();
+ $service = Service::factory()->create();
+
+ $filenames = [
+ 'info-1.jpg',
+ 'info-2.jpg',
+ 'info-3.jpg',
+ ];
+
+ foreach ($filenames as $index => $filename) {
+ Storage::disk('public')->put('slides/'.$filename, 'fake-image-content-'.$index);
+
+ Slide::factory()->create([
+ 'service_id' => $service->id,
+ 'type' => 'information',
+ 'stored_filename' => $filename,
+ 'original_filename' => 'Original '.$filename,
+ 'sort_order' => $index,
+ ]);
+ }
+
+ $response = $this->actingAs($user)->get(route('services.download-bundle', [
+ 'service' => $service,
+ 'blockType' => 'information',
+ ]));
+
+ $response->assertOk();
+ $response->assertHeader('content-type', 'application/zip');
+
+ $baseResponse = $response->baseResponse;
+ if (! $baseResponse instanceof BinaryFileResponse) {
+ $this->fail('Es wurde keine Dateiantwort zurückgegeben.');
+ }
+
+ $copiedPath = sys_get_temp_dir().'/probundle-test-'.uniqid().'.probundle';
+ copy($baseResponse->getFile()->getPathname(), $copiedPath);
+
+ $zip = new ZipArchive();
+ $openResult = $zip->open($copiedPath);
+
+ $this->assertTrue($openResult === true);
+ $this->assertSame(4, $zip->numFiles);
+
+ $names = [];
+ for ($i = 0; $i < $zip->numFiles; $i++) {
+ $name = $zip->getNameIndex($i);
+ if ($name !== false) {
+ $names[] = $name;
+ }
+ }
+ $zip->close();
+
+ @unlink($copiedPath);
+
+ $this->assertContains('information.pro', $names);
+ $this->assertContains('info-1.jpg', $names);
+ $this->assertContains('info-2.jpg', $names);
+ $this->assertContains('info-3.jpg', $names);
+ }
+
+ public function test_ungueltiger_block_type_liefert_422(): void
+ {
+ $user = User::factory()->create();
+ $service = Service::factory()->create();
+
+ $response = $this->actingAs($user)->getJson(route('services.download-bundle', [
+ 'service' => $service,
+ 'blockType' => 'ungueltig',
+ ]));
+
+ $response->assertStatus(422);
+ }
+
+ public function test_probundle_ohne_slides_enthaelt_nur_pro_datei(): void
+ {
+ $user = User::factory()->create();
+ $service = Service::factory()->create();
+
+ $response = $this->actingAs($user)->get(route('services.download-bundle', [
+ 'service' => $service,
+ 'blockType' => 'sermon',
+ ]));
+
+ $response->assertOk();
+
+ $baseResponse = $response->baseResponse;
+ if (! $baseResponse instanceof BinaryFileResponse) {
+ $this->fail('Es wurde keine Dateiantwort zurückgegeben.');
+ }
+
+ $copiedPath = sys_get_temp_dir().'/probundle-empty-test-'.uniqid().'.probundle';
+ copy($baseResponse->getFile()->getPathname(), $copiedPath);
+
+ $zip = new ZipArchive();
+ $openResult = $zip->open($copiedPath);
+
+ $this->assertTrue($openResult === true);
+ $this->assertSame(1, $zip->numFiles);
+ $this->assertSame('sermon.pro', $zip->getNameIndex(0));
+ $zip->close();
+
+ @unlink($copiedPath);
+ }
+}