feat: lit/divi-design-detach – Preset-Verweise aus Seiten und verschachtelten Presets entfernen
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
d4f235ae5e
commit
607e0a21ca
@@ -6,6 +6,7 @@ namespace LIT\MCP\Tests\Unit\Integrations\Divi\Design;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use LIT\MCP\Integrations\Divi\Design\PresetBook;
|
||||
use LIT\MCP\Integrations\Divi\Design\PresetDiff;
|
||||
use LIT\MCP\Integrations\Divi\Design\PresetScope;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use stdClass;
|
||||
@@ -146,4 +147,43 @@ final class PresetBookTest extends TestCase
|
||||
self::assertMatchesRegularExpression('/^[0-9a-z]{10}$/', PresetBook::newId());
|
||||
self::assertNotSame(PresetBook::newId(), PresetBook::newId());
|
||||
}
|
||||
|
||||
public function testWithoutNestedRefRemovesTheIdFromEveryStack(): void
|
||||
{
|
||||
$stored = self::stored();
|
||||
$stored['module']['divi/button']['items']['aaaaaaaaaa']['groupPresets'] = [
|
||||
'button.decoration.font' => ['presetId' => ['hhhhhhhhhh', 'gggggggggg'], 'groupName' => 'divi/font'],
|
||||
];
|
||||
$book = PresetBook::fromDivi($stored);
|
||||
|
||||
$after = $book->withoutNestedRef('gggggggggg');
|
||||
|
||||
self::assertSame([], $after->nestedUsers('gggggggggg'));
|
||||
self::assertSame([], $after->items(new PresetScope('module', 'divi/text'))['dddddddddd']['groupPresets']);
|
||||
self::assertSame(
|
||||
['button.decoration.font' => ['presetId' => ['hhhhhhhhhh'], 'groupName' => 'divi/font']],
|
||||
$after->items(new PresetScope('module', 'divi/button'))['aaaaaaaaaa']['groupPresets']
|
||||
);
|
||||
self::assertCount(2, $book->nestedUsers('gggggggggg'), 'immutable');
|
||||
self::assertSame(
|
||||
[['dddddddddd', 'changed', ['groupPresets']], ['aaaaaaaaaa', 'changed', ['groupPresets']]],
|
||||
array_map(
|
||||
static fn (array $row): array => [$row['id'], $row['action'], $row['fields']],
|
||||
array_reverse(PresetDiff::between($book, $after))
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function testWithoutNestedRefTakesAStringIdAndLeavesOthersAlone(): void
|
||||
{
|
||||
$book = PresetBook::fromDivi(self::stored());
|
||||
self::assertSame($book->rev(), $book->withoutNestedRef('zzzzzzzzzz')->rev());
|
||||
|
||||
$stored = self::stored();
|
||||
$text = &$stored['module']['divi/text']['items']['dddddddddd'];
|
||||
$text['groupPresets']['content.decoration.bodyFont']['presetId'] = 'gggggggggg';
|
||||
unset($text);
|
||||
|
||||
self::assertSame([], PresetBook::fromDivi($stored)->withoutNestedRef('gggggggggg')->nestedUsers('gggggggggg'));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user