Ersetze die Symbolauswahl im CMS durch einen Wähler mit Raster, Gruppen und Suche

Das Feld steht in den Einstellungen aller Widgets und je Karte und Merkmal. Es trägt nur die Zeichnung des gewählten
Symbols; der Katalog mit allen Zeichnungen kommt beim Öffnen in einer Anfrage (nur Redaktion und Katalogverwaltung).
Mit Tastatur bedienbar. Dazu Katalog-Dokumentation, Tokens und Abnahme mit Screenshots (lokal geprüft, nicht auf luf-test).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
LarsandClaude Sonnet 5.5 committed 2026-11-24 21:42:25 +01:00
1 parent edca8e864c
commit 1270e2e948
21 files changed
+409 -16

No files matched your search

+91
View File
@@ -0,0 +1,91 @@
<?php
namespace Tests\Feature;
use App\Filament\Resources\Pages\Pages\CreatePage;
use App\Filament\Support\SymbolField;
use App\Models\User;
use App\Support\Brand\SymbolCatalog;
use Filament\Facades\Filament;
use Filament\Schemas\Schema;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\ViewErrorBag;
use Livewire\Livewire;
use Tests\TestCase;
/**
* Symbolwähler im CMS: Katalog und Bilder nur für Redaktion und Katalogverwaltung, Feld ohne Bilder im Formular.
*/
class SymbolPickerTest extends TestCase
{
use RefreshDatabase;
public function test_the_catalog_is_only_for_editorial_staff(): void
{
$this->get(route('editorial.symbols'))->assertRedirect();
$member = User::factory()->create();
$this->actingAs($member, 'staff')->get(route('editorial.symbols'))->assertForbidden();
}
public function test_the_catalog_lists_every_offered_symbol_in_groups_with_search_words(): void
{
$response = $this->actingAs(User::factory()->redakteur()->create(), 'staff')->getJson(route('editorial.symbols'))->assertOk();
$groups = $response->json('groups');
$keys = array_merge(...array_map(fn (array $group): array => array_column($group['items'], 'key'), $groups));
$this->assertSame(array_keys(SymbolCatalog::options()), $keys);
$this->assertGreaterThanOrEqual(70, count($keys));
$this->assertNotContains('signalstrahlen', $keys);
$this->assertNotContains('gelbe-unterstreichung', $keys);
$this->assertSame('Film', $groups[1]['name']);
$this->assertContains('wiedergabe', array_column($groups[1]['items'], 'key'));
$this->assertSame(mb_strtolower($groups[1]['items'][0]['title']), explode(' ', $groups[1]['items'][0]['search'])[0], 'Der Titel gehört zu den Suchwörtern.');
}
public function test_every_entry_carries_its_cleaned_drawing_so_no_single_image_requests_are_needed(): void
{
$response = $this->actingAs(User::factory()->redakteur()->create(), 'staff')->getJson(route('editorial.symbols'))->assertOk();
$this->assertStringContainsString('private', (string) $response->headers->get('Cache-Control'));
foreach ($response->json('groups') as $group) {
foreach ($group['items'] as $item) {
$this->assertStringStartsWith('<svg aria-hidden="true"', $item['svg'], $item['key']);
$this->assertStringContainsString('viewBox="', $item['svg'], $item['key']);
$this->assertStringNotContainsString('<title', $item['svg'], $item['key']);
$this->assertStringNotContainsString('<script', $item['svg'], $item['key']);
$this->assertMatchesRegularExpression('/^<svg[^>]*>.*<\/svg>$/s', $item['svg'], $item['key']);
}
}
}
public function test_the_field_carries_only_the_chosen_drawing_and_loads_the_rest_when_opened(): void
{
Filament::setCurrentPanel(Filament::getPanel('verwaltung'));
$editor = User::factory()->redakteur()->create();
$component = Livewire::actingAs($editor, 'staff')->test(CreatePage::class);
view()->share('errors', new ViewErrorBag);
$html = Schema::make($component->instance())
->statePath('probe')
->components([SymbolField::make('symbol', 'Symbol (optional)')])
->fill(['symbol' => 'wiedergabe'])
->toHtml();
$this->assertStringContainsString('Symbol (optional)', $html);
$this->assertStringContainsString('Wiedergabe', $html, 'Der Titel des gewählten Symbols steht schon im Formular.');
$this->assertStringContainsString('Anderes Symbol wählen', $html);
$this->assertStringContainsString('/redaktion/symbole', stripslashes($html));
// Nur das gewählte Symbol steht im Formular (als Vorschau und als Vorlage), alle anderen werden erst beim Öffnen geladen.
preg_match_all('~<svg aria-hidden="true" focusable="false".*?</svg>~s', $html, $drawings);
$this->assertCount(1, array_unique($drawings[0]));
$this->assertLessThanOrEqual(2, count($drawings[0]));
$this->assertLessThan(20000, strlen($html), 'Das Feld darf die Formularantwort nicht aufblähen.');
$this->assertTrue(Validator::make(['symbol' => 'wiedergabe'], ['symbol' => ['nullable', 'in:'.implode(',', array_keys(SymbolCatalog::options()))]])->passes());
}
}