put('cms/bild.jpg', 'bild'); } public function test_a_card_with_framing_gets_position_origin_scale_and_a_larger_source_size(): void { $html = $this->publish('/karten', [$this->cards([ ['title' => 'Eng', 'image' => 'cms/bild.jpg', 'focus_x' => 30, 'focus_y' => 0, 'zoom' => 180], ['title' => 'Normal', 'image' => 'cms/bild.jpg'], ])]); $this->assertStringContainsString('style="object-position: 30% 0%; transform-origin: 30% 0%; scale: 1.8"', $html); $this->assertSame(1, substr_count($html, 'style="object-position'), 'Die Karte ohne Ausschnitt trägt keinen Stil.'); $this->assertStringContainsString('class="card-image" src=', $html); } public function test_cards_without_framing_render_exactly_as_before(): void { $html = $this->publish('/karten-alt', [$this->cards([['title' => 'Alt', 'image' => 'cms/bild.jpg']])]); $this->assertDoesNotMatchRegularExpression('/]* style=/', $html); $this->assertStringNotContainsString('transform-origin', $html); } public function test_the_framing_of_a_card_is_saved_only_when_it_differs_and_only_with_an_image(): void { $page = Page::query()->create(['path' => '/karten-speichern']); $service = app(PageService::class); $revision = $service->saveRevision($page, [$this->cards([ ['title' => 'Ausschnitt', 'image' => 'cms/bild.jpg', 'focus_x' => 20, 'focus_y' => 50, 'zoom' => 150], ['title' => 'Vorgabe', 'image' => 'cms/bild.jpg', 'focus_x' => 50, 'focus_y' => 50, 'zoom' => 100], ['title' => 'Ohne Bild', 'focus_x' => 10, 'zoom' => 200], ])], null, null, null); $items = $revision->sections[0]['slots'][0]['data']['items']; $this->assertSame(20, $items[0]['focus_x']); $this->assertSame(150, $items[0]['zoom']); $this->assertArrayNotHasKey('focus_y', $items[0], 'Die Mitte ist die Vorgabe und wird nicht gespeichert.'); $this->assertArrayNotHasKey('focus_x', $items[1]); $this->assertArrayNotHasKey('zoom', $items[1]); $this->assertArrayNotHasKey('zoom', $items[2]); } public function test_a_zoom_above_the_cap_is_rejected(): void { $page = Page::query()->create(['path' => '/karten-zu-gross']); $this->expectException(ValidationException::class); app(PageService::class)->saveRevision($page, [$this->cards([['title' => 'X', 'image' => 'cms/bild.jpg', 'zoom' => 400]])], null, null, null); } public function test_the_hero_puts_photo_and_video_into_a_clipping_frame_only_with_zoom(): void { $zoomed = $this->publish('/einstieg-zoom', [$this->widget('hero', 'photo_split', ['heading' => 'Stark', 'focus_x' => 40, 'focus_y' => 10, 'zoom' => 160], ['image' => 'cms/bild.jpg'])]); $this->assertStringContainsString('--lf-hero-focus-x: 40%; --lf-hero-focus-y: 10%; --lf-hero-zoom: 1.6', $zoomed); $this->assertMatchesRegularExpression('#
\s*publish('/einstieg-ohne', [$this->widget('hero', 'photo_split', ['heading' => 'Stark'], ['image' => 'cms/bild.jpg'])]); $this->assertStringNotContainsString('lf-hero__frame', $plain); $this->assertStringNotContainsString('--lf-hero-zoom', $plain); } public function test_image_and_text_wraps_the_image_in_a_frame_only_with_zoom(): void { $zoomed = $this->publish('/bt-zoom', [$this->widget('image_text', 'image_left', ['title' => 'Bild', 'body' => '

Text

', 'zoom' => 200], ['image' => 'cms/bild.jpg'])]); $this->assertStringContainsString('--bt-zoom: 2', $zoomed); $this->assertMatchesRegularExpression('#
\s*publish('/bt-ohne', [$this->widget('image_text', 'image_left', ['title' => 'Bild', 'body' => '

Text

'], ['image' => 'cms/bild.jpg'])]); $this->assertStringNotContainsString('lf-bt__frame', $plain); $this->assertStringNotContainsString('--bt-zoom', $plain); } public function test_the_premium_card_zooms_the_cut_out_but_never_the_whole_image(): void { $pillars = app(PillarService::class); $pillar = $pillars->create('Hilfe holen'); $pillars->present($pillar, 'Hilfe holen', 'hilfe-holen', 'Kurztext', true, 10); $cover = $this->publish('/pc-zoom', [$this->widget('topic_card', 'adaptive', ['alt' => 'Park', 'zoom' => 150], ['pillar' => $pillar->id, 'image' => 'cms/bild.jpg'])]); $this->assertStringContainsString('lf-pc--zoom', $cover); $this->assertStringContainsString('--pc-zoom: 1.5', $cover); $contain = $this->publish('/pc-ganz', [$this->widget('topic_card', 'adaptive', ['alt' => 'Park', 'zoom' => 150], ['pillar' => $pillar->id, 'image' => 'cms/bild.jpg'], ['fit' => 'contain'])]); $this->assertStringNotContainsString('lf-pc--zoom', $contain); $this->assertStringNotContainsString('--pc-zoom', $contain); } public function test_every_zooming_stylesheet_keeps_the_frame_filled_and_clipped(): void { $hero = (string) file_get_contents(resource_path('css/components/lf-hero.css')); $text = (string) file_get_contents(resource_path('css/components/lf-bild-text.css')); $card = (string) file_get_contents(resource_path('css/components/lf-premium-card.css')); $this->assertMatchesRegularExpression('/\.lf-hero__frame\s*\{[^}]*overflow: hidden/', $hero); $this->assertMatchesRegularExpression('/\.lf-bt__frame\s*\{[^}]*overflow: hidden/', $text); $this->assertMatchesRegularExpression('/\.lf-pc--zoom \.lf-pc__visual\s*\{[^}]*overflow: hidden/', $card); $this->assertStringContainsString('scale: var(--lf-hero-zoom, 1)', $hero); $this->assertStringContainsString('scale: var(--bt-zoom, 1)', $text); $this->assertStringContainsString('scale: var(--pc-zoom, 1)', $card); } public function test_the_dialogs_offer_a_zoom_slider_next_to_the_focus(): void { $hero = app(WidgetRegistry::class)->get('hero'); $fields = collect($hero->mediaSchema())->flatMap(fn ($group) => $group->getDefaultChildComponents())->keyBy(fn ($field) => method_exists($field, 'getName') ? $field->getName() : spl_object_id($field)); $this->assertInstanceOf(Slider::class, $fields['zoom']); $this->assertInstanceOf(Slider::class, $fields['focus_x']); } public function test_the_sliders_show_the_default_of_the_widget_when_nothing_is_saved_and_keep_saved_values(): void { $livewire = new class extends Component implements HasSchemas { use InteractsWithSchemas; public ?array $data = []; public function render(): string { return ''; } }; // Filaments Regler machte aus „kein Wert“ eine 0 und zeigte sie statt der Vorgabe der Darstellung. Schema::make($livewire)->statePath('data') ->components(ImageFraming::sliders(68, 50)) ->fill(['focus_y' => 0, 'zoom' => 150]); $this->assertSame(68, $livewire->data['focus_x']); $this->assertSame(0, (int) $livewire->data['focus_y'], 'Ein gespeicherter Wert 0 bleibt 0.'); $this->assertSame(150, (int) $livewire->data['zoom']); Schema::make($livewire)->statePath('data') ->components(ImageFraming::sliders()) ->fill([]); $this->assertSame([50, 50, 100], [$livewire->data['focus_x'], $livewire->data['focus_y'], $livewire->data['zoom']]); } /** * @param list> $items * @return array */ private function cards(array $items): array { return ['type' => 'cards', 'v' => 2, 'settings' => [], 'data' => ['items' => $items]]; } /** * @param array $data * @param array $refs * @param array $settings * @return array */ private function widget(string $type, string $variant, array $data, array $refs = [], array $settings = []): array { return ['type' => $type, 'v' => $type === 'hero' ? 2 : ($type === 'image_text' ? 3 : 1), 'variant' => $variant, 'settings' => $settings, 'data' => $data, 'refs' => $refs]; } /** * @param list> $widgets */ private function publish(string $path, array $widgets): string { $page = Page::query()->create(['path' => $path]); $service = app(PageService::class); $service->publish($page, $service->saveRevision($page, [['layout' => 'u4', 'style' => [], 'slots' => $widgets]], null, null, null)); return $this->get($path)->assertOk()->getContent(); } }