feat: PresetBook nennt Presets mit Verweisen auf Farben/Variablen und ersetzt Variablen-Verweise durch ihren Wert
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
a4ea487174
commit
653169a133
@@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||
namespace LIT\MCP\Tests\Unit\Integrations\Divi\Design;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use LIT\MCP\Integrations\Divi\Compose\VariableRef;
|
||||
use LIT\MCP\Integrations\Divi\Design\PresetBook;
|
||||
use LIT\MCP\Integrations\Divi\Design\PresetDiff;
|
||||
use LIT\MCP\Integrations\Divi\Design\PresetScope;
|
||||
@@ -57,6 +58,101 @@ final class PresetBookTest extends TestCase
|
||||
return $stored;
|
||||
}
|
||||
|
||||
/**
|
||||
* stored() with references: CTA primär uses color gcid-holz000001, Doppelt variable gvid-slogan0001 (whole with
|
||||
* before/after, and embedded in a longer value), Lesetext variable gvid-radius0001 in its styleAttrs.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public static function storedWithReferences(): array
|
||||
{
|
||||
$stored = self::stored();
|
||||
$stored['module']['divi/button']['items']['aaaaaaaaaa']['attrs'] = [
|
||||
'button' => ['decoration' => ['background' => ['desktop' => ['value' => [
|
||||
'color' => VariableRef::serialize('color', 'gcid-holz000001', []),
|
||||
]]]]],
|
||||
];
|
||||
$stored['module']['divi/button']['items']['bbbbbbbbbb']['attrs'] = [
|
||||
'button' => ['innerContent' => ['desktop' => ['value' => [
|
||||
'text' => VariableRef::serialize('content', 'gvid-slogan0001', ['before' => 'Ab ', 'after' => '!']),
|
||||
]]]],
|
||||
'module' => ['meta' => ['adminLabel' => ['desktop' => [
|
||||
'value' => 'Vorher ' . VariableRef::serialize('content', 'gvid-slogan0001', []),
|
||||
]]]],
|
||||
];
|
||||
$stored['group']['divi/font-body']['items']['gggggggggg']['styleAttrs'] = [
|
||||
'font' => ['size' => VariableRef::serialize('content', 'gvid-radius0001', [])],
|
||||
];
|
||||
|
||||
return $stored;
|
||||
}
|
||||
|
||||
public function testReferencingListsThePresetsThatNameAColorOrVariable(): void
|
||||
{
|
||||
$book = PresetBook::fromDivi(self::storedWithReferences());
|
||||
|
||||
self::assertSame(
|
||||
[['id' => 'aaaaaaaaaa', 'name' => 'CTA primär', 'scope' => 'divi/button']],
|
||||
$book->referencing('gcid-holz000001')
|
||||
);
|
||||
self::assertSame(
|
||||
[['id' => 'bbbbbbbbbb', 'name' => 'Doppelt', 'scope' => 'divi/button']],
|
||||
$book->referencing('gvid-slogan0001')
|
||||
);
|
||||
self::assertSame(
|
||||
[['id' => 'gggggggggg', 'name' => 'Lesetext', 'scope' => 'divi/font-body']],
|
||||
$book->referencing('gvid-radius0001')
|
||||
);
|
||||
self::assertSame([], $book->referencing('gvid-fehlt00001'));
|
||||
}
|
||||
|
||||
public function testWithVariableResolvedReplacesWholeReferencesOnly(): void
|
||||
{
|
||||
$stored = self::storedWithReferences();
|
||||
$button = new PresetScope('module', 'divi/button');
|
||||
$book = PresetBook::fromDivi($stored)->withVariableResolved('gvid-slogan0001', 'Holz mit Herz');
|
||||
$attrs = $book->items($button)['bbbbbbbbbb']['attrs'];
|
||||
|
||||
self::assertSame('Holz mit Herz', $attrs['button']['innerContent']['desktop']['value']['text']);
|
||||
self::assertSame(
|
||||
$stored['module']['divi/button']['items']['bbbbbbbbbb']['attrs']['module'],
|
||||
$attrs['module'],
|
||||
'an embedded reference stays'
|
||||
);
|
||||
self::assertSame($stored['module']['divi/button']['items']['aaaaaaaaaa'], $book->items($button)['aaaaaaaaaa']);
|
||||
}
|
||||
|
||||
/** Ruling V9: a strings variable keeps the before/after of the reference. */
|
||||
public function testWithVariableResolvedFramesTheValueWithBeforeAndAfter(): void
|
||||
{
|
||||
$book = PresetBook::fromDivi(self::storedWithReferences())
|
||||
->withVariableResolved('gvid-slogan0001', 'Holz mit Herz', true);
|
||||
|
||||
self::assertSame(
|
||||
'Ab Holz mit Herz!',
|
||||
$book->items(new PresetScope('module', 'divi/button'))['bbbbbbbbbb']['attrs']['button']['innerContent']
|
||||
['desktop']['value']['text']
|
||||
);
|
||||
}
|
||||
|
||||
public function testWithVariableResolvedReachesStyleAttrsAndLeavesOtherPresetsAlone(): void
|
||||
{
|
||||
$stored = self::storedWithReferences();
|
||||
$book = PresetBook::fromDivi($stored)->withVariableResolved('gvid-radius0001', '8px');
|
||||
|
||||
self::assertSame(
|
||||
['font' => ['size' => '8px']],
|
||||
$book->items(new PresetScope('group', 'divi/font-body'))['gggggggggg']['styleAttrs']
|
||||
);
|
||||
self::assertSame(
|
||||
PresetBook::fromDivi($stored)->items(new PresetScope('module', 'divi/button')),
|
||||
$book->items(new PresetScope('module', 'divi/button'))
|
||||
);
|
||||
self::assertSame(
|
||||
PresetBook::fromDivi($stored)->data(),
|
||||
PresetBook::fromDivi($stored)->withVariableResolved('gvid-fehlt00001', 'x')->data()
|
||||
);
|
||||
}
|
||||
/** Final review I-2: presets whose HTML/CSS Divi's prepare_data() would strip for editors. */
|
||||
public function testMarkupOutsideListsUntouchedPresetsWithHtmlOrCss(): void
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user