create(array_merge(['is_active' => true], $attributes)); $playlist = DisplayPlaylist::factory()->create([ 'display_id' => $display->id, 'status' => DisplayPlaylist::STATUS_PUBLISHED, 'published_at' => now(), ]); DisplayPlaylistItem::factory()->create([ 'display_playlist_id' => $playlist->id, 'display_version_id' => DisplayVersion::factory()->create()->id, 'sort_order' => 0, ]); return $display->fresh(); } // ======================================== // Embed-Route // ======================================== it('serves the player for a published display', function () { $display = publishedDisplay(); $this->get(route('display.embed', ['display' => $display->id])) ->assertSuccessful() ->assertHeader('X-Robots-Tag', 'noindex'); }); it('never hands out a preview token', function () { $display = publishedDisplay(); $token = $display->ensurePreviewToken(); // Die Route liefert eine Datei (BinaryFileResponse) – der Inhalt kommt aus der Datei selbst. $response = $this->get(route('display.embed', ['display' => $display->id]))->assertSuccessful(); $body = file_get_contents($response->baseResponse->getFile()->getPathname()); expect($body)->not->toContain($token) ->and($body)->toContain('DisplayPlayer'); }); it('returns 404 for an inactive display', function () { $display = publishedDisplay(['is_active' => false]); $this->get(route('display.embed', ['display' => $display->id]))->assertNotFound(); }); it('returns 404 while only a draft exists', function () { $display = Display::factory()->create(['is_active' => true]); $playlist = DisplayPlaylist::factory()->create([ 'display_id' => $display->id, 'status' => DisplayPlaylist::STATUS_DRAFT, ]); DisplayPlaylistItem::factory()->create([ 'display_playlist_id' => $playlist->id, 'display_version_id' => DisplayVersion::factory()->create()->id, 'sort_order' => 0, ]); $this->get(route('display.embed', ['display' => $display->id]))->assertNotFound(); }); it('returns 404 for a published playlist without modules', function () { $display = Display::factory()->create(['is_active' => true]); DisplayPlaylist::factory()->create([ 'display_id' => $display->id, 'status' => DisplayPlaylist::STATUS_PUBLISHED, ]); $this->get(route('display.embed', ['display' => $display->id]))->assertNotFound(); }); it('returns 404 for an unknown display', function () { $this->get('/embed/display/999999')->assertNotFound(); }); // ======================================== // Sektion auf der Website // ======================================== it('embeds the display on the homepage once one is published', function () { $display = publishedDisplay(); $this->get('/') ->assertSuccessful() ->assertSee(route('display.embed', ['display' => $display->id])) ->assertSee('Aktuelles aus unserem'); }); it('shows no display section while nothing is published', function () { $this->get('/') ->assertSuccessful() ->assertDontSee('/embed/display/') ->assertDontSee('Aktuelles aus unserem'); }); it('prefers the display that is configured in the cms', function () { publishedDisplay(); $second = publishedDisplay(); \FluxCms\Core\Models\CmsContent::create([ 'group' => 'referenzen', 'key' => 'display_feed', 'type' => 'json', 'value' => ['de' => ['title' => 'Showroom', 'display_id' => (string) $second->id]], 'order' => 0, ]); $this->get('/') ->assertSuccessful() ->assertSee(route('display.embed', ['display' => $second->id])); }); it('falls back to another display when the configured one is gone', function () { $display = publishedDisplay(); \FluxCms\Core\Models\CmsContent::create([ 'group' => 'referenzen', 'key' => 'display_feed', 'type' => 'json', 'value' => ['de' => ['title' => 'Showroom', 'display_id' => '999999']], 'order' => 0, ]); $this->get('/') ->assertSuccessful() ->assertSee(route('display.embed', ['display' => $display->id])); });