Mit KI erzeugt.
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('~~', $html); $this->assertStringContainsString('Vollständigen Hinweis anzeigen', $html); $this->assertStringNotContainsString('data-ready', $html); } public function test_without_a_line_limit_the_responsive_mode_has_no_limit_attribute_and_the_default_threshold(): void { $html = $this->publish('/hinweis-ohne-grenze', ['text' => self::FULL, 'short' => self::SHORT], ['mode' => 'responsive']); $this->assertStringContainsString('data-mode="responsive" data-narrow="40">', $html); $this->assertStringNotContainsString('data-limit', $html); } public function test_the_always_collapsed_mode_is_marked_so_that_width_and_limit_do_not_matter(): void { $html = $this->publish('/hinweis-immer', ['text' => self::FULL, 'short' => self::SHORT], ['mode' => 'collapsed', 'line_limit' => 'l1']); $this->assertStringContainsString('data-mode="collapsed"', $html); $script = (string) file_get_contents(base_path('resources/js/notice.js')); $this->assertStringContainsString("if (mode === 'responsive') {", $script); $this->assertMatchesRegularExpression("/var next = true;\s+if \(mode === 'responsive'\)/", $script, 'Im Modus „collapsed“ ist der Hinweis ohne Prüfung einklappbar.'); } public function test_the_icon_size_is_independent_of_the_font_size_and_the_symbol_is_decorative(): void { $html = $this->publish('/hinweis-symbol', ['text' => self::FULL], ['symbol' => 'buch', 'symbol_size' => 'xs', 'size' => 'xs', 'symbol_align' => 'center']); $this->assertMatchesRegularExpression('~]*class="brand-symbol notice-symbol notice-symbol--xs"~', $html); $this->assertStringContainsString('aria-hidden="true"', $html); $this->assertStringContainsString('notice notice--size-xs notice--symbol-center', $html); $css = (string) file_get_contents(base_path('resources/css/components/lf-hinweiszeile.css')); $this->assertMatchesRegularExpression('/\.notice-symbol--xs \{ --notice-sym: 1rem; \}/', $css); $this->assertMatchesRegularExpression('/\.notice--size-xs \{ --notice-fs: 0\.8125rem; \}/', $css); } public function test_the_default_markup_has_no_class_beyond_the_base_class(): void { $html = $this->publish('/hinweis-vorgabe', ['text' => self::FULL]); $this->assertStringContainsString('', $html); $this->assertStringNotContainsString('notice-symbol', $html); $this->assertStringNotContainsString('scope-light', $html); } public function test_surface_border_and_accent_bar_use_tokens_and_the_light_value_group(): void { $html = $this->publish('/hinweis-flaeche', ['text' => self::FULL], ['surface' => 'green', 'border' => 'line', 'bar' => 'left', 'align' => 'center']); $this->assertStringContainsString('notice--center', $html); $this->assertStringContainsString('notice--surface scope-light notice--surface-green', $html); $this->assertStringContainsString('notice--border', $html); $this->assertStringContainsString('notice--bar notice--bar-left', $html); $css = (string) file_get_contents(base_path('resources/css/components/lf-hinweiszeile.css')); $this->assertSame(0, preg_match('/#[0-9a-f]{3,8}\b/i', preg_replace('/#a8212b/', '', $css)), 'Farben nur über Tokens (die Rotmarkierung entspricht der der Fließtexte).'); $this->assertStringContainsString('--notice-bg: var(--lf-green-tint)', $css); $this->assertStringContainsString('border-inline-start: 4px solid var(--color-action)', $css); } public function test_clean_stores_both_texts_sanitised_and_requires_the_full_text(): void { $errors = new WidgetErrors; [$clean] = $this->type()->clean(['text' => 'Hinweis Link kursiv', 'short' => ''], [], $errors); $this->assertTrue($errors->isEmpty()); $this->assertStringNotContainsString('onclick', $clean['text']); $this->assertStringNotContainsString('javascript:', $clean['text']); $this->assertStringNotContainsString('assertStringNotContainsString('/*', $boot); $this->assertStringNotContainsString('Kein Springen', $boot); $this->assertStringContainsString('window.lfNotice = { scan: scan };', $boot); $this->assertStringContainsString('lineCount(full) > limit', $boot); } public function test_the_stylesheet_and_script_cover_progressive_enhancement_and_accessibility(): void { $css = (string) file_get_contents(base_path('resources/css/components/lf-hinweiszeile.css')); $script = (string) file_get_contents(base_path('resources/js/notice.js')); $app = (string) file_get_contents(base_path('resources/css/app.css')); $entry = (string) file_get_contents(base_path('resources/js/app.js')); $this->assertStringContainsString("@import './components/lf-hinweiszeile.css';", $app); $this->assertStringContainsString("import './notice.js';", $entry); // Grundzustand ohne JavaScript: Kurztext aus, Schalter versteckt; Kurzdarstellung erst mit data-state. $this->assertMatchesRegularExpression('/\.notice-short \{ display: none; \}/', $css); $this->assertStringContainsString('.notice-toggle[hidden] { display: none; }', $css); $this->assertStringContainsString(".notice[data-state='short'] .notice-short { display: block; }", $css); // Kein Flackern: unsichtbar bis zum ersten Ergebnis, mit Rückfall ohne Skript. $this->assertStringContainsString('html.js .notice[data-notice]:not([data-ready])', $css); $this->assertStringContainsString('animation: notice-failsafe', $css); // Links bleiben über der Klickfläche bedienbar; Fokus und Druck. $this->assertMatchesRegularExpression('/\.notice \.prose a \{\s*position: relative;\s*z-index: 1;/', $css); $this->assertStringContainsString('.notice:has(.notice-toggle:focus-visible)', $css); $this->assertStringContainsString('@media print', $css); // Schalter: aria-expanded und aria-controls; Zeilen werden gezählt, nicht die Höhe geschätzt. $this->assertStringContainsString("toggle.setAttribute('aria-expanded'", $script); $this->assertStringContainsString("toggle.setAttribute('aria-controls'", $script); $this->assertStringContainsString('getClientRects', $script); $this->assertStringContainsString('ResizeObserver', $script); $this->assertStringContainsString('lineCount(full) > limit', $script); } public function test_the_prose_rules_of_the_website_texts_apply_to_the_notice(): void { $css = (string) file_get_contents(base_path('resources/css/widgets.css')); $this->assertStringContainsString('.scope-dark :is(.widget-prose, .widget-heading, .widget-cards, .widget-notice) .prose {', $css); $this->assertStringContainsString(":is(.widget-prose, .widget-heading, .widget-cards, .widget-notice) .prose span.color[data-color='rot']", $css); } public function test_the_summary_names_the_start_of_the_full_text(): void { $summary = $this->type()->summary(['data' => ['text' => self::FULL]]); $this->assertStringStartsWith('Dieses Bild wurde mit KI erzeugt', $summary); } }
Dieses Bild wurde mit KI~', $html); $this->assertMatchesRegularExpression('~~', $html); $this->assertStringContainsString('Vollständigen Hinweis anzeigen', $html); $this->assertStringNotContainsString('data-ready', $html); } public function test_without_a_line_limit_the_responsive_mode_has_no_limit_attribute_and_the_default_threshold(): void { $html = $this->publish('/hinweis-ohne-grenze', ['text' => self::FULL, 'short' => self::SHORT], ['mode' => 'responsive']); $this->assertStringContainsString('data-mode="responsive" data-narrow="40">', $html); $this->assertStringNotContainsString('data-limit', $html); } public function test_the_always_collapsed_mode_is_marked_so_that_width_and_limit_do_not_matter(): void { $html = $this->publish('/hinweis-immer', ['text' => self::FULL, 'short' => self::SHORT], ['mode' => 'collapsed', 'line_limit' => 'l1']); $this->assertStringContainsString('data-mode="collapsed"', $html); $script = (string) file_get_contents(base_path('resources/js/notice.js')); $this->assertStringContainsString("if (mode === 'responsive') {", $script); $this->assertMatchesRegularExpression("/var next = true;\s+if \(mode === 'responsive'\)/", $script, 'Im Modus „collapsed“ ist der Hinweis ohne Prüfung einklappbar.'); } public function test_the_icon_size_is_independent_of_the_font_size_and_the_symbol_is_decorative(): void { $html = $this->publish('/hinweis-symbol', ['text' => self::FULL], ['symbol' => 'buch', 'symbol_size' => 'xs', 'size' => 'xs', 'symbol_align' => 'center']); $this->assertMatchesRegularExpression('~]*class="brand-symbol notice-symbol notice-symbol--xs"~', $html); $this->assertStringContainsString('aria-hidden="true"', $html); $this->assertStringContainsString('notice notice--size-xs notice--symbol-center', $html); $css = (string) file_get_contents(base_path('resources/css/components/lf-hinweiszeile.css')); $this->assertMatchesRegularExpression('/\.notice-symbol--xs \{ --notice-sym: 1rem; \}/', $css); $this->assertMatchesRegularExpression('/\.notice--size-xs \{ --notice-fs: 0\.8125rem; \}/', $css); } public function test_the_default_markup_has_no_class_beyond_the_base_class(): void { $html = $this->publish('/hinweis-vorgabe', ['text' => self::FULL]); $this->assertStringContainsString('', $html); $this->assertStringNotContainsString('notice-symbol', $html); $this->assertStringNotContainsString('scope-light', $html); } public function test_surface_border_and_accent_bar_use_tokens_and_the_light_value_group(): void { $html = $this->publish('/hinweis-flaeche', ['text' => self::FULL], ['surface' => 'green', 'border' => 'line', 'bar' => 'left', 'align' => 'center']); $this->assertStringContainsString('notice--center', $html); $this->assertStringContainsString('notice--surface scope-light notice--surface-green', $html); $this->assertStringContainsString('notice--border', $html); $this->assertStringContainsString('notice--bar notice--bar-left', $html); $css = (string) file_get_contents(base_path('resources/css/components/lf-hinweiszeile.css')); $this->assertSame(0, preg_match('/#[0-9a-f]{3,8}\b/i', preg_replace('/#a8212b/', '', $css)), 'Farben nur über Tokens (die Rotmarkierung entspricht der der Fließtexte).'); $this->assertStringContainsString('--notice-bg: var(--lf-green-tint)', $css); $this->assertStringContainsString('border-inline-start: 4px solid var(--color-action)', $css); } public function test_clean_stores_both_texts_sanitised_and_requires_the_full_text(): void { $errors = new WidgetErrors; [$clean] = $this->type()->clean(['text' => 'Hinweis Link kursiv', 'short' => ''], [], $errors); $this->assertTrue($errors->isEmpty()); $this->assertStringNotContainsString('onclick', $clean['text']); $this->assertStringNotContainsString('javascript:', $clean['text']); $this->assertStringNotContainsString('assertStringNotContainsString('/*', $boot); $this->assertStringNotContainsString('Kein Springen', $boot); $this->assertStringContainsString('window.lfNotice = { scan: scan };', $boot); $this->assertStringContainsString('lineCount(full) > limit', $boot); } public function test_the_stylesheet_and_script_cover_progressive_enhancement_and_accessibility(): void { $css = (string) file_get_contents(base_path('resources/css/components/lf-hinweiszeile.css')); $script = (string) file_get_contents(base_path('resources/js/notice.js')); $app = (string) file_get_contents(base_path('resources/css/app.css')); $entry = (string) file_get_contents(base_path('resources/js/app.js')); $this->assertStringContainsString("@import './components/lf-hinweiszeile.css';", $app); $this->assertStringContainsString("import './notice.js';", $entry); // Grundzustand ohne JavaScript: Kurztext aus, Schalter versteckt; Kurzdarstellung erst mit data-state. $this->assertMatchesRegularExpression('/\.notice-short \{ display: none; \}/', $css); $this->assertStringContainsString('.notice-toggle[hidden] { display: none; }', $css); $this->assertStringContainsString(".notice[data-state='short'] .notice-short { display: block; }", $css); // Kein Flackern: unsichtbar bis zum ersten Ergebnis, mit Rückfall ohne Skript. $this->assertStringContainsString('html.js .notice[data-notice]:not([data-ready])', $css); $this->assertStringContainsString('animation: notice-failsafe', $css); // Links bleiben über der Klickfläche bedienbar; Fokus und Druck. $this->assertMatchesRegularExpression('/\.notice \.prose a \{\s*position: relative;\s*z-index: 1;/', $css); $this->assertStringContainsString('.notice:has(.notice-toggle:focus-visible)', $css); $this->assertStringContainsString('@media print', $css); // Schalter: aria-expanded und aria-controls; Zeilen werden gezählt, nicht die Höhe geschätzt. $this->assertStringContainsString("toggle.setAttribute('aria-expanded'", $script); $this->assertStringContainsString("toggle.setAttribute('aria-controls'", $script); $this->assertStringContainsString('getClientRects', $script); $this->assertStringContainsString('ResizeObserver', $script); $this->assertStringContainsString('lineCount(full) > limit', $script); } public function test_the_prose_rules_of_the_website_texts_apply_to_the_notice(): void { $css = (string) file_get_contents(base_path('resources/css/widgets.css')); $this->assertStringContainsString('.scope-dark :is(.widget-prose, .widget-heading, .widget-cards, .widget-notice) .prose {', $css); $this->assertStringContainsString(":is(.widget-prose, .widget-heading, .widget-cards, .widget-notice) .prose span.color[data-color='rot']", $css); } public function test_the_summary_names_the_start_of_the_full_text(): void { $summary = $this->type()->summary(['data' => ['text' => self::FULL]]); $this->assertStringStartsWith('Dieses Bild wurde mit KI erzeugt', $summary); } }
Hinweis Link kursiv