Files
LarsandClaude Opus 5.5 cc47cac93e Hauptadresse statt Zweitadresse, Abspielgeschwindigkeit je Video
- Weitere Adressen einer Website (z. B. www.stommer.info) leiten per 301 auf die
  Hauptadresse um; vorher blockierte der Browser Skripte, Schriften und Videos,
  die von der Hauptadresse kamen (kein Titelvideo, Ersatzschrift)
- Site::origin() nimmt verbindlich das Feld domain
- Videos: Abspielgeschwindigkeit 0,5x bis 1x, gilt im Titelbereich und Rundgang

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-30 11:30:42 +01:00

183 lines
7.9 KiB
PHP

<?php
namespace Tests\Feature;
use App\Availability\NextFreeStays;
use App\Enums\BookingStatus;
use App\Enums\UserRole;
use App\Filament\Resources\Videos\Pages\EditVideo;
use App\Filament\Resources\Videos\VideoResource;
use App\Models\Booking;
use App\Models\FloorPlan;
use App\Models\Page;
use App\Models\Photo;
use App\Models\Property;
use App\Models\Site;
use App\Models\User;
use App\Models\Video;
use Carbon\CarbonImmutable;
use Database\Seeders\PropertySeeder;
use Database\Seeders\SiteSeeder;
use Database\Seeders\WebsiteContentSeeder;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Storage;
use Livewire\Livewire;
use Tests\TestCase;
class VideoTourTest extends TestCase
{
use RefreshDatabase;
private Property $property;
protected function setUp(): void
{
parent::setUp();
Storage::fake('public');
$this->travelTo(CarbonImmutable::parse('2026-10-22 10:00'));
$this->seed([PropertySeeder::class, WebsiteContentSeeder::class, SiteSeeder::class]);
$this->withoutVite();
$this->property = Property::sole();
}
public function test_chapters_are_read_as_minutes_and_seconds_sorted_and_matched_to_rooms(): void
{
$video = Video::factory()->for($this->property)->create(['chapters' => [
['at' => '0:42', 'label' => 'Schlafzimmer', 'room' => 'Schlafzimmer'],
['at' => '16', 'label' => 'Wohnzimmer', 'room' => null],
['at' => 'gleich', 'label' => 'Ungültig'],
['at' => '1:05', 'label' => ''],
]]);
$this->assertSame([16, 42], array_column($video->chapterList(), 'seconds'));
$this->assertSame(['0:16', '0:42'], array_column($video->chapterList(), 'time'));
$this->assertSame(42, $video->chapterForRoom('schlafzimmer')['seconds']);
$this->assertNull($video->chapterForRoom('Bad'));
$this->assertSame(65, Video::seconds('1:05'));
$this->assertNull(Video::seconds('1:75'));
}
public function test_hero_plays_a_silent_loop_instead_of_the_photo_and_shows_the_next_free_dates(): void
{
$loop = $this->videoWithFiles('Garten und Meer');
$loop->update(['playback_rate' => 0.75]);
Booking::factory()->for($this->property)->create(['arrival' => '2026-10-23', 'departure' => '2026-10-27', 'status' => BookingStatus::Confirmed]);
$this->updateSection('start', 'hero', ['video_id' => $loop->id, 'show_free_dates' => true, 'free_dates_nights' => 3]);
$stays = app(NextFreeStays::class)->for($this->property, nights: 3);
$this->assertCount(3, $stays);
$this->assertSame('2026-10-27', $stays[0]['arrival']->toDateString(), 'starts after the occupied nights');
$this->assertTrue($stays[1]['arrival']->greaterThanOrEqualTo($stays[0]['departure']), 'stays do not overlap');
$this->assertGreaterThanOrEqual(3, $stays[0]['nights']);
$this->get('/')
->assertOk()
->assertSee('data-video-loop', false)
->assertSee('data-src="'.$loop->url().'"', false)
->assertSee('aria-label="Video: Garten und Meer"', false)
->assertSee('data-playback-rate="0.75"', false)
->assertSee('Nächste freie Termine')
->assertSee(e($stays[0]['url']), false);
}
public function test_tour_section_offers_chapters_and_floor_plan_rooms_jump_into_it(): void
{
$tour = $this->videoWithFiles('Rundgang', [['at' => '0:16', 'label' => 'Wohnzimmer', 'room' => 'Wohnzimmer'], ['at' => '0:34', 'label' => 'Bad']]);
FloorPlan::factory()->for($this->property)->create([
'photo_id' => Photo::factory()->create()->id,
'rooms' => [['id' => 'a', 'name' => 'Wohnzimmer', 'points' => '10,10 40,10 40,40', 'is_visible' => true]],
]);
$page = Site::sole()->pages()->where('slug', 'wohnung')->sole();
$page->update(['sections' => [...$page->sections,
['type' => 'tour', 'data' => ['heading' => 'Kommen Sie herein', 'video_id' => $tour->id, 'layout' => 'right', 'show_chapters' => true]],
['type' => 'floor_plan', 'data' => ['heading' => 'Der Grundriss']],
]]);
$this->get('/wohnung')
->assertOk()
->assertSee('Kommen Sie herein')
->assertSee('preload="none"', false)
->assertSee('data-tour-seek="16"', false)
->assertSee('data-tour-seek="34"', false)
->assertSee('data-tour-link="16"', false)
->assertSee('Im Rundgang ansehen');
}
public function test_booking_section_shows_the_three_steps_unless_switched_off(): void
{
$this->get('/buchen')->assertOk()->assertSeeInOrder(['Anfrage senden', 'Angebot erhalten', 'Annehmen']);
$this->updateSection('buchen', 'booking', ['show_steps' => false]);
$this->get('/buchen')->assertOk()->assertDontSee('So läuft Ihre Buchung ab');
}
public function test_content_editor_uploads_a_video_with_poster_and_chapters(): void
{
$this->actingAs(User::factory()->role(UserRole::Content)->create());
$video = Video::factory()->for($this->property)->create(['title' => 'Rundgang']);
$this->get(VideoResource::getUrl('index'))->assertOk()->assertSee('Rundgang');
Livewire::test(EditVideo::class, ['record' => $video->id])
->fillForm([
'file' => UploadedFile::fake()->createWithContent('rundgang.mp4', (string) file_get_contents(base_path('tests/Fixtures/video.mp4'))),
'poster' => UploadedFile::fake()->image('standbild.jpg', 1280, 720),
'chapters' => [['at' => '0:7', 'label' => 'Garten']],
])
->call('save')
->assertHasFormErrors(['chapters.0.at']);
Livewire::test(EditVideo::class, ['record' => $video->id])
->fillForm([
'file' => UploadedFile::fake()->createWithContent('rundgang.mp4', (string) file_get_contents(base_path('tests/Fixtures/video.mp4'))),
'poster' => UploadedFile::fake()->image('standbild.jpg', 1280, 720),
'chapters' => [['at' => '0:07', 'label' => 'Garten', 'room' => null]],
'playback_rate' => '0.75',
])
->call('save')
->assertHasNoFormErrors();
Livewire::test(EditVideo::class, ['record' => $video->id])->assertSchemaStateSet(['playback_rate' => '0.75']);
$video->refresh();
$this->assertNotNull($video->url());
$this->assertNotNull($video->posterUrl());
$this->assertSame(7, $video->chapterList()[0]['seconds']);
$this->assertSame(0.75, $video->playbackRate());
}
public function test_uploads_allow_videos_up_to_100_mb(): void
{
$this->assertContains('max:102400', config('livewire.temporary_file_upload.rules'));
$this->assertSame(100 * 1024 * 1024, config('media-library.max_file_size'));
}
/**
* @param list<array<string, mixed>>|null $chapters
*/
private function videoWithFiles(string $title, ?array $chapters = null): Video
{
$video = Video::factory()->for($this->property)->create(['title' => $title, 'chapters' => $chapters]);
$video->addMedia(UploadedFile::fake()->createWithContent('video.mp4', (string) file_get_contents(base_path('tests/Fixtures/video.mp4'))))->toMediaCollection(Video::COLLECTION);
$video->addMedia(UploadedFile::fake()->image('poster.jpg', 640, 360))->toMediaCollection(Video::POSTER);
return $video->fresh();
}
/**
* @param array<string, mixed> $data
*/
private function updateSection(string $slug, string $type, array $data): void
{
$page = Site::sole()->pages()->where('slug', $slug)->sole();
$page->update(['sections' => array_map(
fn (array $section): array => $section['type'] === $type ? [...$section, 'data' => [...$section['data'], ...$data]] : $section,
$page->sections,
)]);
$this->assertInstanceOf(Page::class, $page);
}
}