189 lines
6.5 KiB
PHP
189 lines
6.5 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Models\Service;
|
|
use App\Models\ServiceAgendaItem;
|
|
use App\Models\Setting;
|
|
use App\Models\Slide;
|
|
use App\Services\PlaylistExportService;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Support\Facades\Storage;
|
|
use ProPresenter\Parser\ProPlaylistReader;
|
|
use Tests\TestCase;
|
|
|
|
final class PlaylistSequenceTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
Storage::fake('public');
|
|
}
|
|
|
|
public function test_sermon_sequence_prepends_keyvisual_and_preacher_nametag_before_slides(): void
|
|
{
|
|
Setting::set('namenseinblender_macro_name', 'Namenseinblender');
|
|
Storage::disk('public')->put('slides/keyvisual.jpg', 'keyvisual-image');
|
|
Storage::disk('public')->put('slides/sermon.jpg', 'sermon-image');
|
|
|
|
$service = Service::factory()->create([
|
|
'title' => 'Predigt Service',
|
|
'date' => now(),
|
|
'key_visual_filename' => 'slides/keyvisual.jpg',
|
|
'moderator_name' => null,
|
|
'preacher_name' => 'Pastor Paul',
|
|
'preacher_name_override' => null,
|
|
]);
|
|
|
|
$agendaItem = ServiceAgendaItem::factory()->create([
|
|
'service_id' => $service->id,
|
|
'title' => 'Predigt',
|
|
'service_song_id' => null,
|
|
'sort_order' => 1,
|
|
'is_before_event' => false,
|
|
]);
|
|
|
|
Slide::factory()->create([
|
|
'service_id' => $service->id,
|
|
'service_agenda_item_id' => $agendaItem->id,
|
|
'type' => 'sermon',
|
|
'original_filename' => 'sermon.jpg',
|
|
'stored_filename' => 'slides/sermon.jpg',
|
|
'sort_order' => 0,
|
|
]);
|
|
|
|
$result = app(PlaylistExportService::class)->generatePlaylist($service);
|
|
$playlist = ProPlaylistReader::read($result['path']);
|
|
|
|
$names = array_map(fn ($entry) => $entry->getName(), $playlist->getEntries());
|
|
|
|
$kvIndex = array_search('Keyvisual-Predigt', $names, true);
|
|
$nameTagIndex = array_search('Predigername', $names, true);
|
|
$sermonIndex = array_search('Predigt', $names, true);
|
|
|
|
$this->assertNotFalse($kvIndex, 'Keyvisual-Predigt entry missing');
|
|
$this->assertNotFalse($nameTagIndex, 'Predigername entry missing');
|
|
$this->assertNotFalse($sermonIndex, 'Predigt entry missing');
|
|
|
|
$this->assertLessThan($nameTagIndex, $kvIndex, 'Keyvisual must come before preacher nametag');
|
|
$this->assertLessThan($sermonIndex, $nameTagIndex, 'Preacher nametag must come before sermon slides');
|
|
|
|
$this->cleanupTempDir($result['temp_dir']);
|
|
}
|
|
|
|
public function test_moderator_nametag_is_first_for_first_visible_agenda_item(): void
|
|
{
|
|
Setting::set('namenseinblender_macro_name', 'Namenseinblender');
|
|
Storage::disk('public')->put('slides/info.jpg', 'info-image');
|
|
|
|
$service = Service::factory()->create([
|
|
'title' => 'Moderator Service',
|
|
'date' => now(),
|
|
'key_visual_filename' => null,
|
|
'moderator_name' => 'Moderator Max',
|
|
]);
|
|
|
|
$agendaItem = ServiceAgendaItem::factory()->create([
|
|
'service_id' => $service->id,
|
|
'title' => 'Begrüßung',
|
|
'service_song_id' => null,
|
|
'sort_order' => 1,
|
|
'is_before_event' => false,
|
|
]);
|
|
|
|
Slide::factory()->create([
|
|
'service_id' => $service->id,
|
|
'service_agenda_item_id' => $agendaItem->id,
|
|
'type' => 'moderation',
|
|
'original_filename' => 'info.jpg',
|
|
'stored_filename' => 'slides/info.jpg',
|
|
'sort_order' => 0,
|
|
]);
|
|
|
|
$result = app(PlaylistExportService::class)->generatePlaylist($service);
|
|
$playlist = ProPlaylistReader::read($result['path']);
|
|
|
|
$names = array_map(fn ($entry) => $entry->getName(), $playlist->getEntries());
|
|
|
|
$this->assertNotEmpty($names);
|
|
$this->assertSame('Moderator', $names[0], 'Moderator nametag must be the first playlist entry');
|
|
|
|
$this->cleanupTempDir($result['temp_dir']);
|
|
}
|
|
|
|
public function test_without_macro_no_nametags_are_injected(): void
|
|
{
|
|
Setting::set('namenseinblender_macro_name', '');
|
|
Storage::disk('public')->put('slides/keyvisual.jpg', 'keyvisual-image');
|
|
Storage::disk('public')->put('slides/sermon.jpg', 'sermon-image');
|
|
|
|
$service = Service::factory()->create([
|
|
'title' => 'Ohne Macro',
|
|
'date' => now(),
|
|
'key_visual_filename' => 'slides/keyvisual.jpg',
|
|
'moderator_name' => 'Moderator Max',
|
|
'preacher_name' => 'Pastor Paul',
|
|
'preacher_name_override' => null,
|
|
]);
|
|
|
|
$agendaItem = ServiceAgendaItem::factory()->create([
|
|
'service_id' => $service->id,
|
|
'title' => 'Predigt',
|
|
'service_song_id' => null,
|
|
'sort_order' => 1,
|
|
'is_before_event' => false,
|
|
]);
|
|
|
|
Slide::factory()->create([
|
|
'service_id' => $service->id,
|
|
'service_agenda_item_id' => $agendaItem->id,
|
|
'type' => 'sermon',
|
|
'original_filename' => 'sermon.jpg',
|
|
'stored_filename' => 'slides/sermon.jpg',
|
|
'sort_order' => 0,
|
|
]);
|
|
|
|
$result = app(PlaylistExportService::class)->generatePlaylist($service);
|
|
$playlist = ProPlaylistReader::read($result['path']);
|
|
|
|
$names = array_map(fn ($entry) => $entry->getName(), $playlist->getEntries());
|
|
|
|
$this->assertNotContains('Moderator', $names);
|
|
$this->assertNotContains('Predigername', $names);
|
|
|
|
$kvIndex = array_search('Keyvisual-Predigt', $names, true);
|
|
$sermonIndex = array_search('Predigt', $names, true);
|
|
$this->assertNotFalse($kvIndex, 'Keyvisual-Predigt entry missing');
|
|
$this->assertNotFalse($sermonIndex, 'Predigt entry missing');
|
|
$this->assertLessThan($sermonIndex, $kvIndex, 'Keyvisual must come before sermon slides');
|
|
|
|
$this->cleanupTempDir($result['temp_dir']);
|
|
}
|
|
|
|
private function cleanupTempDir(string $dir): void
|
|
{
|
|
if (! is_dir($dir)) {
|
|
return;
|
|
}
|
|
|
|
$items = scandir($dir);
|
|
if ($items === false) {
|
|
return;
|
|
}
|
|
|
|
foreach ($items as $item) {
|
|
if ($item === '.' || $item === '..') {
|
|
continue;
|
|
}
|
|
|
|
$path = $dir.'/'.$item;
|
|
is_dir($path) ? $this->cleanupTempDir($path) : unlink($path);
|
|
}
|
|
|
|
rmdir($dir);
|
|
}
|
|
}
|