Mit KI erzeugt.

'; private const FULL = '

Dieses Bild wurde mit KI erzeugt und zeigt keine realen Personen. Mehr dazu in den '; /** * @param array $data * @param array $settings */ private function publish(string $path, array $data, array $settings = []): string { $page = Page::query()->create(['path' => $path]); $service = app(PageService::class); $sections = [['layout' => 'u4', 'style' => [], 'slots' => [['type' => 'notice', 'v' => 1, 'variant' => 'standard', 'settings' => $settings, 'data' => $data]]]]; $service->publish($page, $service->saveRevision($page, $sections, null, null, null)); return $this->get($path)->assertOk()->getContent(); } private function type(): NoticeWidget { $type = app(WidgetRegistry::class)->get('notice'); $this->assertInstanceOf(NoticeWidget::class, $type); return $type; } public function test_the_widget_is_registered_with_enumerated_settings_and_two_rich_text_fields(): void { $type = $this->type(); $this->assertSame('Hinweiszeile', $type->label()); $this->assertSame([1, 2, 3, 4], $type->supportedUnits()); $this->assertSame(['mode', 'line_limit', 'narrow', 'size', 'align', 'symbol', 'symbol_size', 'symbol_align', 'surface', 'border', 'bar'], array_keys($type->settings())); $this->assertSame(['full', 'responsive', 'collapsed'], array_keys(NoticeWidget::MODE)); $this->assertSame(['xs', 's', 'm', 'l'], array_keys(NoticeWidget::SIZE)); // Die Grenze steht als Zeichenkette (nicht als Zahlenschlüssel), sonst verwürfe die Prüfung sie als Ganzzahl. foreach (array_keys(NoticeWidget::LINE_LIMIT) as $key) { $this->assertIsString($key); } $children = collect($type->dataFields())->keyBy(fn ($field) => $field->getName()); $this->assertInstanceOf(RichEditor::class, $children['text']); $this->assertInstanceOf(RichEditor::class, $children['short']); } public function test_layout_falls_back_to_the_defaults_for_missing_and_invalid_values(): void { $default = NoticeWidget::layout([]); $this->assertSame(['mode' => 'full', 'limit' => null, 'narrow' => 40.0, 'size' => 's', 'align' => 'left', 'symbol' => null, 'symbolSize' => 's', 'symbolAlign' => 'top', 'surface' => null, 'border' => false, 'bar' => null], $default); $invalid = NoticeWidget::layout(['mode' => 'weird', 'line_limit' => '99', 'narrow' => 'x', 'size' => 'xxl', 'align' => 'justify', 'symbol' => 'gibt-es-nicht', 'surface' => 'pink', 'border' => 'thick', 'bar' => 'diagonal']); $this->assertSame($default, $invalid); $chosen = NoticeWidget::layout(['mode' => 'responsive', 'line_limit' => 'l2', 'narrow' => 'wide', 'size' => 'l', 'align' => 'center', 'symbol_size' => 'xs', 'surface' => 'yellow', 'border' => 'line', 'bar' => 'left']); $this->assertSame(['responsive', 2, 56.0, 'l', 'center', 'xs', 'yellow', true, 'left'], [$chosen['mode'], $chosen['limit'], $chosen['narrow'], $chosen['size'], $chosen['align'], $chosen['symbolSize'], $chosen['surface'], $chosen['border'], $chosen['bar']]); } public function test_a_mode_without_a_short_text_shows_the_full_text_like_the_full_mode(): void { $this->assertSame('full', NoticeWidget::layout(['mode' => 'collapsed'], false)['mode']); $this->assertSame('collapsed', NoticeWidget::layout(['mode' => 'collapsed'], true)['mode']); $html = $this->publish('/hinweis-ohne-kurztext', ['text' => self::FULL], ['mode' => 'collapsed']); $this->assertStringContainsString('class="notice-full prose"', $html); $this->assertStringNotContainsString('data-notice=', $html); $this->assertStringNotContainsString('notice-toggle', $html); } public function test_only_the_preview_tells_that_the_mode_needs_a_short_text(): void { $widget = ['data' => ['text' => self::FULL], 'settings' => ['mode' => 'responsive']]; $this->assertNull($this->type()->resolve($widget, RenderContext::publicPage())['notice']); $this->assertStringContainsString('Kurztext', (string) $this->type()->resolve($widget, RenderContext::preview())['notice']); $this->assertNull($this->type()->resolve(['data' => $widget['data'], 'settings' => []], RenderContext::preview())['notice']); $this->assertNull($this->type()->resolve(['data' => $widget['data'] + ['short' => self::SHORT], 'settings' => $widget['settings']], RenderContext::preview())['notice']); } public function test_the_full_mode_outputs_the_text_only_without_any_toggle_markup(): void { $html = $this->publish('/hinweis-volltext', ['text' => self::FULL, 'short' => self::SHORT]); $this->assertStringContainsString('

', $html); $this->assertStringContainsString('
', $html); $this->assertStringContainsString('KI', $html); $this->assertStringContainsString('assertStringNotContainsString('notice-short', $html); $this->assertStringNotContainsString('data-notice-toggle', $html); $this->assertStringNotContainsString('Mit KI erzeugt.', $html, 'Im Volltext erscheint der Kurztext nirgends.'); } public function test_the_responsive_mode_carries_its_rules_as_data_and_always_outputs_the_full_text(): void { $html = $this->publish('/hinweis-responsiv', ['text' => self::FULL, 'short' => self::SHORT], ['mode' => 'responsive', 'line_limit' => 'l2', 'narrow' => 'narrow']); $this->assertStringContainsString('data-notice="" data-mode="responsive" data-narrow="30" data-limit="2"', $html); $this->assertStringContainsString('

Mit KI erzeugt.

', $html); // Ohne JavaScript bleibt der vollständige Hinweis sichtbar: Er steht ohne hidden im Quelltext, der Schalter ist versteckt. $this->assertMatchesRegularExpression('~

Dieses Bild wurde mit KI~', $html); $this->assertMatchesRegularExpression('~