- DiviComposition::references() builds the one VariableRef with the entry's
live map (S22/S31) and passes it to AttrWriter; Placeholders only needs the
design system now, Placeholders::references() is gone (no reach-through).
- DesignSystem::colorIdFor()/variableFor() replace the dead colorId()/variable()
and carry Placeholders' lookup incl. the S13a ambiguity check (byLabel moved,
messages unchanged); isColorVariable() decides color vs content for {{var:}}.
- DesignSystem::colorReferenceIds() (VariableRef color names) and
contentVariableIds() (DynamicContentRules design names) replace the two
inline computations; same lists, same order.
Tests: fixtures/tests get the VariableRef from ComposeFixture::references() or
build it with the map; DesignSystemTest uses the new lookups (+2 tests).
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01At3V6SjwbMe6eMzVGW3Hs7
116 lines
5.1 KiB
PHP
116 lines
5.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace LIT\MCP\Tests\Unit\Integrations\Divi\Design;
|
|
|
|
use InvalidArgumentException;
|
|
use LIT\MCP\Integrations\Divi\Design\DesignSystem;
|
|
use LIT\MCP\Tests\Support\DiviFixtures;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
final class DesignSystemTest extends TestCase
|
|
{
|
|
public function testReadsColorsVariablesFontsSizesAndPresets(): void
|
|
{
|
|
$design = DiviFixtures::designSystem();
|
|
|
|
self::assertSame(
|
|
['id' => 'gcid-a1b2', 'label' => 'Nachtblau', 'value' => '#0b3d59'],
|
|
$design->colors()[2]
|
|
);
|
|
self::assertCount(3, $design->colors());
|
|
self::assertSame(['heading' => 'Open Sans', 'body' => 'Lato'], $design->fonts());
|
|
self::assertSame(
|
|
[['id' => 'gvid-r1', 'type' => 'numbers', 'label' => 'Radius', 'value' => '8px'],
|
|
['id' => 'gvid-s1', 'type' => 'strings', 'label' => 'Telefon', 'value' => '0221 123']],
|
|
$design->variables()
|
|
);
|
|
self::assertSame('16', $design->sizes()['body_font_size']);
|
|
self::assertSame('30', $design->sizes()['body_header_size']);
|
|
self::assertSame(
|
|
['kind' => 'module', 'module' => 'divi/button', 'id' => 'p-1', 'name' => 'Standard', 'default' => true],
|
|
$design->presets()[0]
|
|
);
|
|
self::assertSame(['p-1' => 'Standard', 'p-2' => 'CTA primär', 'g-1' => 'Fließtext groß'], $design->presetNames());
|
|
}
|
|
|
|
/** The name lists VariableRef/DynamicContentRules check references against (H3: one place). */
|
|
public function testReferenceNameLists(): void
|
|
{
|
|
$design = new DesignSystem(
|
|
[['id' => 'gcid-a', 'label' => 'A', 'value' => '#000']],
|
|
[
|
|
['id' => 'gvid-c', 'type' => 'colors', 'label' => 'C', 'value' => '#fff'],
|
|
['id' => 'gvid-t', 'type' => 'strings', 'label' => 'T', 'value' => 'x'],
|
|
],
|
|
[],
|
|
['heading' => '', 'body' => ''],
|
|
[]
|
|
);
|
|
|
|
self::assertSame(['gcid-a', 'gvid-c'], $design->colorReferenceIds());
|
|
self::assertSame(['--et_global_heading_font', '--et_global_body_font', 'gvid-t'], $design->contentVariableIds());
|
|
self::assertTrue($design->isColorVariable('gvid-c'));
|
|
self::assertFalse($design->isColorVariable('gvid-t'));
|
|
self::assertFalse($design->isColorVariable('gcid-a'));
|
|
}
|
|
|
|
public function testLabelLookupsRefuseAmbiguousLabels(): void
|
|
{
|
|
$design = new DesignSystem(
|
|
[['id' => 'gcid-a', 'label' => 'Blau', 'value' => '#00f'], ['id' => 'gcid-b', 'label' => 'blau', 'value' => '#00e']],
|
|
[],
|
|
[],
|
|
['heading' => '', 'body' => ''],
|
|
[]
|
|
);
|
|
|
|
self::assertSame('gcid-b', $design->colorIdFor('gcid-b'));
|
|
$this->expectException(InvalidArgumentException::class);
|
|
$this->expectExceptionMessage('Name der globale Farbe "Blau" ist mehrdeutig; bitte die ID angeben: gcid-a, gcid-b.');
|
|
$design->colorIdFor('Blau');
|
|
}
|
|
|
|
public function testLooksUpByAliasLabelOrId(): void
|
|
{
|
|
$design = DiviFixtures::designSystem();
|
|
|
|
self::assertSame('gcid-primary-color', $design->colorIdFor('primary'));
|
|
self::assertSame('gcid-a1b2', $design->colorIdFor('nachtblau'));
|
|
self::assertSame('gcid-a1b2', $design->colorIdFor('gcid-a1b2'));
|
|
self::assertNull($design->colorIdFor('secondary'));
|
|
self::assertNull($design->colorIdFor('Alt'));
|
|
self::assertSame('gvid-s1', $design->variableFor('telefon'));
|
|
self::assertSame('p-2', $design->modulePresetId('divi/button', 'cta PRIMÄR'));
|
|
self::assertNull($design->modulePresetId('divi/text', 'Standard'));
|
|
self::assertSame(['Standard', 'CTA primär'], $design->modulePresetNames('divi/button'));
|
|
self::assertSame('{{color:primary}}', DesignSystem::colorPlaceholder('gcid-primary-color', 'Primärfarbe'));
|
|
self::assertSame('{{color:Nachtblau}}', DesignSystem::colorPlaceholder('gcid-a1b2', 'Nachtblau'));
|
|
}
|
|
|
|
/** Ruling S13a/S34: a preset name several presets of the module share fails with their ids. */
|
|
public function testAmbiguousPresetNamesFail(): void
|
|
{
|
|
$design = DesignSystem::fromDivi([], [], ['module' => ['divi/button' => ['default' => 'p-1', 'items' => [
|
|
'p-1' => ['id' => 'p-1', 'name' => 'Standard', 'moduleName' => 'divi/button'],
|
|
'p-3' => ['id' => 'p-3', 'name' => 'standard', 'moduleName' => 'divi/button'],
|
|
]]]], []);
|
|
|
|
self::assertSame('p-3', $design->modulePresetId('divi/button', 'p-3'));
|
|
$this->expectException(\InvalidArgumentException::class);
|
|
$this->expectExceptionMessage('p-1, p-3');
|
|
$design->modulePresetId('divi/button', 'STANDARD');
|
|
}
|
|
|
|
public function testToleratesEmptyOrOddInput(): void
|
|
{
|
|
$design = DesignSystem::fromDivi([], ['fonts' => 'x'], ['module' => 'y'], []);
|
|
|
|
self::assertSame([], $design->colors());
|
|
self::assertSame(['heading' => '', 'body' => ''], $design->fonts());
|
|
self::assertSame([], $design->presets());
|
|
self::assertSame('14', $design->sizes()['body_font_size']);
|
|
}
|
|
}
|