refactor: one VariableRef per composition, design lookups in DesignSystem (H3)
- 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
This commit is contained in:
@@ -44,7 +44,7 @@ final class PlaceholdersTest extends TestCase
|
||||
self::assertSame($expected, $resolved);
|
||||
if ($expected !== $input) {
|
||||
// What placeholders produce passes the strict checker unchanged (ruling S1/S25).
|
||||
self::assertSame($resolved, $placeholders->references()->canonical($resolved, ComposeFixture::sanitizer()));
|
||||
self::assertSame($resolved, ComposeFixture::references()->canonical($resolved, ComposeFixture::sanitizer()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ 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;
|
||||
@@ -34,16 +35,53 @@ final class DesignSystemTest extends TestCase
|
||||
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->colorId('primary'));
|
||||
self::assertSame('gcid-a1b2', $design->colorId('nachtblau'));
|
||||
self::assertSame('gcid-a1b2', $design->colorId('gcid-a1b2'));
|
||||
self::assertNull($design->colorId('secondary'));
|
||||
self::assertNull($design->colorId('Alt'));
|
||||
self::assertSame('gvid-s1', $design->variable('telefon')['id'] ?? null);
|
||||
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'));
|
||||
|
||||
@@ -71,6 +71,7 @@ final class DiviCompositionTest extends TestCase
|
||||
self::assertSame([7], $this->registryCalls, 'the registry is read once per post');
|
||||
self::assertSame($composition->attrWriter(), $composition->attrWriter());
|
||||
self::assertSame($composition->placeholders(), $composition->placeholders());
|
||||
self::assertSame($composition->references(), $composition->references());
|
||||
}
|
||||
|
||||
public function testWithoutAPostTheDefaultMapApplies(): void
|
||||
@@ -97,6 +98,8 @@ final class DiviCompositionTest extends TestCase
|
||||
self::assertNotSame($base, $seven);
|
||||
self::assertNotSame($seven->placeholders(), $eight->placeholders());
|
||||
self::assertNotSame($base->placeholders(), $seven->placeholders());
|
||||
self::assertNotSame($seven->references(), $eight->references());
|
||||
self::assertNotSame($base->references(), $seven->references());
|
||||
self::assertSame([7, 8], $this->registryCalls);
|
||||
}
|
||||
|
||||
|
||||
@@ -91,7 +91,7 @@ final class DiviWriterTest extends TestCase
|
||||
$writer = $this->writer(Mockery::mock(DiviSaver::class), FakeChangeLog::forbidden());
|
||||
$page = $writer->page(['post_id' => 7, 'tree_rev' => Rev::of($content)]);
|
||||
|
||||
$writer->composition($page)->placeholders();
|
||||
$writer->composition($page)->references();
|
||||
|
||||
self::assertSame([7], $this->registryCalls, 'the live dynamic content map of post 7 (ruling S22)');
|
||||
}
|
||||
|
||||
@@ -61,12 +61,13 @@ final class DynamicContentMapTest extends TestCase
|
||||
self::assertSame('select', $map['post_date']['date_format']);
|
||||
self::assertSame('text', $map['post_excerpt']['words']);
|
||||
|
||||
$placeholders = new Placeholders(DiviFixtures::designSystem(), $map);
|
||||
$placeholders = new Placeholders(DiviFixtures::designSystem());
|
||||
$references = new VariableRef(DiviFixtures::designSystem(), $map);
|
||||
foreach (array_keys(Placeholders::POST) as $key) {
|
||||
$reference = $placeholders->resolve('{{post:' . $key . '}}');
|
||||
self::assertSame(
|
||||
$reference,
|
||||
$placeholders->references()->canonical($reference, ComposeFixture::sanitizer()),
|
||||
$references->canonical($reference, ComposeFixture::sanitizer()),
|
||||
$key
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user