feat: GroupKeys und PresetAssignment – Preset-Stapel und Gruppen-Presets über eine Engstelle

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Jan-Niclas Loosen
2026-10-18 16:45:29 +02:00
co-authored by Claude Sonnet 5.5
parent 6546e23e7f
commit fafa140546
6 changed files with 796 additions and 17 deletions
@@ -0,0 +1,67 @@
<?php
declare(strict_types=1);
namespace LIT\MCP\Tests\Unit\Integrations\Divi\Design;
use InvalidArgumentException;
use LIT\MCP\Integrations\Divi\Design\GroupKeys;
use PHPUnit\Framework\TestCase;
final class GroupKeysTest extends TestCase
{
/** @return array<string, string> groupId => groupName, as DesignSystemWriter::groupsOf() returns it. */
private static function groups(): array
{
return [
'title.decoration.font' => 'divi/font',
'content.decoration.bodyFont' => 'divi/font-body',
'module.decoration.spacing' => 'divi/spacing',
'button.decoration.spacing' => 'divi/spacing',
];
}
public function testShortNameFullNameAndPathFindTheGroup(): void
{
self::assertSame('content.decoration.bodyFont', GroupKeys::resolve(self::groups(), 'font-body'));
self::assertSame('content.decoration.bodyFont', GroupKeys::resolve(self::groups(), 'divi/font-body'));
self::assertSame('content.decoration.bodyFont', GroupKeys::resolve(self::groups(), 'content.decoration.bodyFont'));
self::assertSame('title.decoration.font', GroupKeys::resolve(self::groups(), 'font'));
}
public function testSeveralGroupsWithTheSameNameNeedThePath(): void
{
self::assertSame('button.decoration.spacing', GroupKeys::resolve(self::groups(), 'button.decoration.spacing'));
foreach (['spacing', 'divi/spacing'] as $key) {
try {
GroupKeys::resolve(self::groups(), $key);
self::fail('Ambiguous group name must throw.');
} catch (InvalidArgumentException $e) {
self::assertSame(GroupKeys::AMBIGUOUS, $e->getCode());
self::assertSame(
sprintf(
'Gruppe "%s" ist mehrdeutig; bitte den Attributpfad angeben: '
. 'module.decoration.spacing, button.decoration.spacing.',
$key
),
$e->getMessage()
);
}
}
}
public function testUnknownGroup(): void
{
try {
GroupKeys::resolve(self::groups(), 'sizing');
self::fail('Unknown group must throw.');
} catch (InvalidArgumentException $e) {
self::assertSame(GroupKeys::UNKNOWN, $e->getCode());
self::assertSame('keine Gruppe "sizing"', $e->getMessage());
}
$this->expectException(InvalidArgumentException::class);
GroupKeys::resolve([], 'font');
}
}