$settings * @return array */ private function heading(array $settings = []): array { return ['type' => 'heading', 'v' => 1, 'settings' => $settings, 'data' => ['heading' => 'Titel', 'intro' => 'Einleitung']]; } /** * @param array $settings * @return array */ private function cards(array $settings = []): array { return ['type' => 'cards', 'v' => 1, 'settings' => $settings, 'data' => ['items' => [['title' => 'Karte', 'text' => 'Text']]]]; } /** * @param array $widget */ private function publish(string $path, array $widget): Page { $page = Page::query()->create(['path' => $path]); $service = app(PageService::class); $service->publish($page, $service->saveRevision($page, [['layout' => 'u4', 'style' => [], 'slots' => [$widget]]], null, null, null)); return $page->fresh(); } /** * @param array $widget */ private function hull(string $path, array $widget): string { $this->publish($path, $widget); $html = $this->get($path)->assertOk()->getContent(); preg_match('/
]*>/', $html, $match); $this->assertStringNotContainsString('widget-palette', $match[0] ?? ''); $this->assertStringContainsString('Titel', $html); } public function test_a_colour_used_only_by_a_widget_is_counted_and_cannot_be_removed(): void { $page = $this->publish('/nur-widget', $this->heading(['palette' => 'c2'])); $usage = DesignPalette::usage(); $this->assertArrayHasKey('c2', $usage); $this->assertSame($page->id, $usage['c2'][0]['page_id']); $this->assertSame(1, $usage['c2'][0]['published']); $this->assertArrayNotHasKey('c1', $usage); $this->assertNotEmpty(DesignPalette::remove('c2')); $this->assertNotNull(DesignPalette::find('c2')); } public function test_a_draft_that_only_a_widget_uses_is_counted_as_draft(): void { $page = $this->publish('/entwurf', $this->heading()); app(PageService::class)->saveRevision($page, [['layout' => 'u4', 'style' => [], 'slots' => [$this->heading(['palette' => 'c1'])]]], null, null, null); $usage = DesignPalette::usage(); $this->assertSame(0, $usage['c1'][0]['published']); $this->assertSame(1, $usage['c1'][0]['draft']); } public function test_image_text_takes_the_palette_colour_on_its_own_face(): void { $widget = ['type' => 'image_text', 'v' => 3, 'variant' => 'image_left', 'settings' => ['palette' => 'c1', 'surface' => 'cream'], 'data' => ['title' => 'Titel', 'body' => '

Text

'], 'refs' => []]; $this->publish('/bt', $widget); $html = $this->get('/bt')->assertOk()->getContent(); $this->assertStringContainsString('lf-bt lf-bt--palette', $html); $this->assertStringNotContainsString('lf-bt--cream', $html); $this->assertStringContainsString('widget-palette widget-palette--face scope-dark', $html); } public function test_the_notice_widget_keeps_its_own_surface_setting_and_offers_no_palette(): void { $this->assertArrayNotHasKey('palette', app(WidgetRegistry::class)->get('notice')->settingOptions()); $this->assertArrayHasKey('surface', app(WidgetRegistry::class)->get('notice')->settingOptions()); } public function test_the_hero_offers_sizes_but_no_palette(): void { $options = app(WidgetRegistry::class)->get('hero')->settingOptions(); $this->assertArrayHasKey('heading_size', $options); $this->assertArrayHasKey('text_size', $options); $this->assertArrayNotHasKey('palette', $options); } private function editor(): User { $editor = User::factory()->redakteur()->create(); $editor->saveAppAuthenticationSecret('JBSWY3DPEHPK3PXP'); return $editor; } public function test_editor_saves_sizes_and_colour_and_shows_them_in_the_widget_dialog(): void { Filament::setCurrentPanel(Filament::getPanel('verwaltung')); $widget = ['type' => 'heading', 'data' => ['settings' => ['heading_size' => 'xlarge', 'text_size' => 'large', 'palette' => 'c2'], 'data' => ['heading' => 'Größe', 'intro' => '

Text

']]]; $slots = [(string) Str::uuid() => ['widget' => [(string) Str::uuid() => $widget]]]; Livewire::actingAs($this->editor(), 'staff') ->test(CreatePage::class) ->fillForm(['path' => '/groesse', 'sections' => [['id' => null, 'layout' => 'u4', 'style' => [], 'slots' => $slots]]]) ->call('create') ->assertHasNoFormErrors(); $page = Page::query()->where('path', '/groesse')->firstOrFail(); $this->assertSame( ['heading_size' => 'xlarge', 'text_size' => 'large', 'palette' => 'c2'], $page->latestRevision->sections[0]['slots'][0]['settings'], ); $component = Livewire::actingAs($this->editor(), 'staff')->test(EditPage::class, ['record' => $page->id]); $sectionKey = array_key_first($component->get('data.sections')); $slotKey = array_key_first($component->get("data.sections.$sectionKey.slots")); $itemKey = array_key_first($component->get("data.sections.$sectionKey.slots.$slotKey.widget")); $component->mountAction(TestAction::make('edit')->schemaComponent("sections.$sectionKey.slots.$slotKey.widget")->arguments(['item' => $itemKey])) ->assertFormFieldExists('settings.heading_size') ->assertFormFieldExists('settings.text_size') ->assertFormFieldExists('settings.palette'); } /** * Beim Einspielen der Migrationen speichert der Seeder eine Seite, bevor site_settings existiert. In PostgreSQL bricht eine * dort fehlgeschlagene Abfrage die ganze Transaktion ab (SQLSTATE 25P02), auch wenn der Fehler abgefangen wird; die CI fand * das erst beim Wegwerf-Postgres. Darum darf die Palette ohne Tabelle gar nicht abgefragt werden. */ public function test_saving_a_widget_before_the_settings_table_exists_runs_no_query_against_it(): void { Schema::drop('site_settings'); DesignPalette::flush(); $queries = []; // Vor der Ausführung mitschneiden: Eine fehlgeschlagene Abfrage löst QueryExecuted nie aus, und sie ist genau der Fehler. DB::beforeExecuting(function (string $sql) use (&$queries): void { $queries[] = $sql; }); $saved = app(WidgetRegistry::class)->normalize([['id' => null, 'type' => 'heading', 'v' => 2, 'variant' => 'standard', 'settings' => [], 'data' => ['heading' => 'Titel'], 'refs' => []]]); $this->assertCount(1, $saved); $this->assertSame([], DesignPalette::slots()); $this->assertSame([], array_filter($queries, fn (string $sql): bool => str_contains($sql, 'site_settings') && ! str_contains($sql, 'sqlite_master'))); } }