Menü: Symbole je Menüpunkt, gemeinsame Symbolauswahl
All checks were successful
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 2m47s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 2m33s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 2m41s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 2m41s
CI / PHP 8.3 / mysql:8.0 (pull_request) Successful in 3m41s
CI / PHP 8.4 / mysql:8.0 (pull_request) Successful in 3m44s
CI / PHP 8.3 / mysql:8.4 (pull_request) Successful in 3m18s
CI / PHP 8.4 / mysql:8.4 (pull_request) Successful in 3m9s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m0s

- Optionales Symbol für jeden Menü- und Unterpunkt (Kopfzeile,
  Aufklappmenüs, „Mehr“, Handy-Menü)
- Gemeinsame Liste resources/icons/icons.json (66 Lucide-Symbole) für
  Menü, Schnellzugriffe und Pagebuilder; `npm run icons` erzeugt
  Frontend-Zuordnung und SVGs für die Vorschau im Admin
- Admin-Auswahl mit Symbolvorschau und Suche

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Friederich Loheide 2026-09-26 14:14:52 +00:00
parent dda250aaad
commit 23c36d28b5
179 changed files with 872 additions and 684 deletions

View file

@ -54,9 +54,9 @@ class MenuTest extends TestCase
app(Settings::class)->set(Navigation::MENU_SETTING, [
['id' => 'a', 'type' => 'module', 'module' => 'home'],
['id' => 'b', 'type' => 'page', 'target' => (string) $mav->id, 'subpages' => true],
['id' => 'b', 'type' => 'page', 'target' => (string) $mav->id, 'subpages' => true, 'icon' => 'heart-handshake'],
['id' => 'c', 'type' => 'group', 'label' => 'Service', 'children' => [
['id' => 'c1', 'type' => 'module', 'module' => 'news', 'label' => 'Aktuelles'],
['id' => 'c1', 'type' => 'module', 'module' => 'news', 'label' => 'Aktuelles', 'icon' => 'gibt-es-nicht'],
['id' => 'c2', 'type' => 'link', 'url' => 'https://kantine.example.org', 'label' => 'Speiseplan', 'new_tab' => true],
['id' => 'c3', 'type' => 'link', 'url' => 'javascript:alert(1)', 'label' => 'Böse'],
]],
@ -75,6 +75,8 @@ class MenuTest extends TestCase
$this->assertTrue($menu[1]['children'][1]['active']);
$this->assertSame(['Aktuelles', 'Speiseplan'], array_column($menu[2]['children'], 'label'), 'Unsichere Links fallen weg');
$this->assertTrue($menu[2]['children'][1]['new_tab']);
$this->assertSame('heart-handshake', $menu[1]['icon']);
$this->assertNull($menu[2]['children'][0]['icon'], 'Unbekannte Symbole fallen weg');
$this->assertNull($menu[2]['href']);
$withRole = User::factory()->withRoles([$hr])->create();
@ -100,13 +102,14 @@ class MenuTest extends TestCase
$this->assertSame('home', collect($items)->first()['module']);
$component->set('data.items', [
'x' => ['id' => 'x', 'type' => 'module', 'module' => 'news', 'label' => 'News', 'roles' => [], 'children' => [
'x' => ['id' => 'x', 'type' => 'module', 'module' => 'news', 'label' => 'News', 'icon' => 'newspaper', 'roles' => [], 'children' => [
'y' => ['id' => 'y', 'type' => 'link', 'url' => '/termine', 'label' => 'Termine', 'roles' => []],
]],
])->call('save')->assertHasNoErrors();
$saved = app(Settings::class)->get(Navigation::MENU_SETTING);
$this->assertSame('News', $saved[0]['label']);
$this->assertSame('newspaper', $saved[0]['icon']);
$this->assertSame('/termine', $saved[0]['children'][0]['url']);
$component->set('data.items.x.children.y.url', 'ftp://nope')->call('save')->assertHasErrors(['data.items.x.children.y.url']);

40
tests/Unit/IconsTest.php Normal file
View file

@ -0,0 +1,40 @@
<?php
namespace Tests\Unit;
use App\Support\Icons;
use Tests\TestCase;
/**
* Liste, SVG-Daten und Frontend-Zuordnung müssen zusammenpassen
* (nach Änderungen an resources/icons/icons.json: npm run icons).
*/
class IconsTest extends TestCase
{
public function test_generated_files_match_the_list(): void
{
$names = array_keys(Icons::choices());
$svg = require resource_path('icons/svg.php');
$js = file_get_contents(resource_path('js/lib/icons.js'));
$this->assertSame($names, array_keys($svg), 'resources/icons/svg.php veraltet – npm run icons');
foreach ($names as $name) {
$this->assertStringContainsString("'{$name}':", $js, "icons.js ohne „{$name}“ – npm run icons");
$this->assertNotSame('', $svg[$name]);
}
// Bereits gespeicherte Schnellzugriffe nutzen diese Namen.
foreach (['link', 'building-2', 'heart-handshake', 'utensils'] as $legacy) {
$this->assertTrue(Icons::has($legacy));
}
}
public function test_options_are_safe_html_and_searchable(): void
{
$this->assertStringContainsString('<svg', Icons::options()['house']);
$this->assertArrayHasKey('house', Icons::search('startseite'));
$this->assertArrayNotHasKey('house', Icons::search('path'), 'Suche trifft nicht das SVG-Markup');
$this->assertFalse(Icons::has('<script>'));
}
}