feat: Outline und Knoten zeigen Gruppen-Presets mit Namen
Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Haiku 5.5
parent
ca3bbf5ad1
commit
c3f08e2d33
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace LIT\MCP\Tests\Unit\Integrations\Divi\BlockTree;
|
||||
|
||||
use LIT\MCP\Integrations\Divi\BlockTree\Block;
|
||||
use LIT\MCP\Integrations\Divi\BlockTree\NodeSummary;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class NodeSummaryTest extends TestCase
|
||||
{
|
||||
public function testGroupPresetsByGroupId(): void
|
||||
{
|
||||
$block = Block::create('divi/blurb', ['groupPreset' => [
|
||||
'content.decoration.bodyFont' => ['presetId' => ['ja6o54jtlc'], 'groupName' => 'divi/font-body'],
|
||||
'module.decoration.spacing' => ['presetId' => ['apzj7e17ok', 'b2b2b2b2b2'], 'groupName' => 'divi/spacing'],
|
||||
]]);
|
||||
|
||||
self::assertSame(
|
||||
[
|
||||
'content.decoration.bodyFont' => ['groupName' => 'divi/font-body', 'presetIds' => ['ja6o54jtlc']],
|
||||
'module.decoration.spacing' => [
|
||||
'groupName' => 'divi/spacing',
|
||||
'presetIds' => ['apzj7e17ok', 'b2b2b2b2b2'],
|
||||
],
|
||||
],
|
||||
NodeSummary::groupPresets($block)
|
||||
);
|
||||
}
|
||||
|
||||
public function testPresetIdAsStringIsAccepted(): void
|
||||
{
|
||||
$block = Block::create('divi/text', ['groupPreset' => [
|
||||
'content.decoration.bodyFont' => ['presetId' => 'ja6o54jtlc', 'groupName' => 'divi/font-body'],
|
||||
]]);
|
||||
|
||||
self::assertSame(
|
||||
['content.decoration.bodyFont' => ['groupName' => 'divi/font-body', 'presetIds' => ['ja6o54jtlc']]],
|
||||
NodeSummary::groupPresets($block)
|
||||
);
|
||||
}
|
||||
|
||||
public function testEmptyIdsAreFilteredAndBrokenEntriesLeftOut(): void
|
||||
{
|
||||
$block = Block::create('divi/text', ['groupPreset' => [
|
||||
'a.one' => ['presetId' => ['', 'x1', 7, null], 'groupName' => 'divi/font'],
|
||||
'a.two' => ['presetId' => [''], 'groupName' => 'divi/font'],
|
||||
'a.three' => ['presetId' => ['x2']],
|
||||
'a.four' => ['presetId' => ['x3'], 'groupName' => ''],
|
||||
'a.five' => ['presetId' => ['x4'], 'groupName' => ['divi/font']],
|
||||
'a.six' => 'kein Eintrag',
|
||||
]]);
|
||||
|
||||
self::assertSame(
|
||||
['a.one' => ['groupName' => 'divi/font', 'presetIds' => ['x1']]],
|
||||
NodeSummary::groupPresets($block)
|
||||
);
|
||||
}
|
||||
|
||||
public function testBlockWithoutOrWithBrokenGroupPreset(): void
|
||||
{
|
||||
self::assertSame([], NodeSummary::groupPresets(Block::create('divi/text')));
|
||||
self::assertSame([], NodeSummary::groupPresets(Block::create('divi/text', ['groupPreset' => 'x'])));
|
||||
self::assertSame([], NodeSummary::groupPresets(Block::create('divi/text', ['groupPreset' => []])));
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ namespace LIT\MCP\Tests\Unit\Integrations\Divi\BlockTree;
|
||||
|
||||
use LIT\MCP\Integrations\Divi\BlockTree\AttrMap;
|
||||
use LIT\MCP\Integrations\Divi\BlockTree\Block;
|
||||
use LIT\MCP\Integrations\Divi\BlockTree\Document;
|
||||
use LIT\MCP\Integrations\Divi\BlockTree\NodeIndex;
|
||||
use LIT\MCP\Integrations\Divi\BlockTree\NodeSummary;
|
||||
use LIT\MCP\Integrations\Divi\BlockTree\Outline;
|
||||
@@ -26,7 +27,8 @@ final class OutlineTest extends TestCase
|
||||
|
||||
self::assertSame(
|
||||
['id' => 's0.r0.c1.m0', 'type' => 'heading', 'label' => '', 'excerpt' => 'Willkommen bei Müller & Söhne',
|
||||
'info' => '', 'presets' => ['Hero-Titel'], 'children' => 0, 'editable' => true, 'depth' => 3,
|
||||
'info' => '', 'presets' => ['Hero-Titel'], 'group_presets' => [], 'children' => 0,
|
||||
'editable' => true, 'depth' => 3,
|
||||
'truncated' => false, 'global_id' => null],
|
||||
$rows[5]
|
||||
);
|
||||
@@ -41,6 +43,56 @@ final class OutlineTest extends TestCase
|
||||
);
|
||||
}
|
||||
|
||||
public function testGroupPresetsAreShownWithNamesInRowAndText(): void
|
||||
{
|
||||
$content = DiviFixtures::markup('stage4/page--designsystem.html');
|
||||
$outline = new Outline([
|
||||
'vdcl6msnuo' => '[Fixture] Blurb Leistung',
|
||||
'ja6o54jtlc' => '[Fixture] Fließtext',
|
||||
'apzj7e17ok' => '[Fixture] Abstand Karte',
|
||||
]);
|
||||
|
||||
$rows = $outline->rows(NodeIndex::build((new Parser())->parse($content)));
|
||||
$byId = array_column($rows, null, 'id');
|
||||
|
||||
self::assertSame([], $byId['s0.r0.c0.m1']['group_presets']);
|
||||
self::assertSame(['font-body: [Fixture] Fließtext'], $byId['s0.r0.c0.m2']['group_presets']);
|
||||
self::assertSame(['spacing: [Fixture] Abstand Karte'], $byId['s0.r0.c0.m5']['group_presets']);
|
||||
self::assertSame(['[Fixture] Blurb Leistung'], $byId['s0.r0.c0.m5']['presets']);
|
||||
|
||||
$lines = explode("\n", $outline->text($rows));
|
||||
self::assertStringContainsString(
|
||||
's0.r0.c0.m2 text "Text mit Gruppen-Preset" {Gruppen-Presets: font-body: [Fixture] Fließtext} – ',
|
||||
$lines[5]
|
||||
);
|
||||
self::assertStringContainsString(
|
||||
's0.r0.c0.m5 blurb "Blurb mit Modul- und Gruppen-Preset" {Preset: [Fixture] Blurb Leistung} '
|
||||
. '{Gruppen-Presets: spacing: [Fixture] Abstand Karte} – Möbel nach Maß',
|
||||
$lines[8]
|
||||
);
|
||||
self::assertStringNotContainsString('Gruppen-Presets', $lines[3]);
|
||||
}
|
||||
|
||||
public function testUnknownGroupPresetFallsBackToTheIdAndStacksAreListed(): void
|
||||
{
|
||||
$block = Block::create('divi/blurb', ['groupPreset' => [
|
||||
'module.decoration.spacing' => ['presetId' => ['a1', 'b2'], 'groupName' => 'divi/spacing'],
|
||||
'title.decoration.font' => ['presetId' => ['c3'], 'groupName' => 'divi/font'],
|
||||
]]);
|
||||
$document = new Document();
|
||||
$document->append($block);
|
||||
$index = NodeIndex::build($document);
|
||||
$outline = new Outline(['a1' => 'Abstand Karte']);
|
||||
|
||||
$rows = $outline->rows($index);
|
||||
|
||||
self::assertSame(['spacing: Abstand Karte, b2', 'font: c3'], $rows[0]['group_presets']);
|
||||
self::assertStringContainsString(
|
||||
'{Gruppen-Presets: spacing: Abstand Karte, b2; font: c3}',
|
||||
$outline->text($rows)
|
||||
);
|
||||
}
|
||||
|
||||
public function testGlobalInstancesShowTheirLibraryIdAndRootType(): void
|
||||
{
|
||||
$content = DiviFixtures::markup('stage3/page--globale-instanzen.html');
|
||||
|
||||
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace LIT\MCP\Tests\Unit\Integrations\Divi\Pages;
|
||||
|
||||
use LIT\MCP\Integrations\Divi\Design\DesignSystem;
|
||||
use LIT\MCP\Integrations\Divi\Design\DesignSystemReader;
|
||||
use LIT\MCP\Integrations\Divi\Library\LibraryAccess;
|
||||
use LIT\MCP\Integrations\Divi\Pages\DiviNodeGetAbility;
|
||||
@@ -25,6 +26,56 @@ final class DiviReadAbilitiesTest extends TestCase
|
||||
return $reader;
|
||||
}
|
||||
|
||||
/** The stage 4 preset inventory (tests/Fixtures/divi/stage4/presets.json) as the design system reads it. */
|
||||
private function designWithGroupPresets(): DesignSystemReader
|
||||
{
|
||||
$stored = json_decode(DiviFixtures::markup('stage4/presets.json'), true)['stored'];
|
||||
$reader = Mockery::mock(DesignSystemReader::class);
|
||||
$reader->allows('read')->andReturn(DesignSystem::fromDivi([], [], $stored, []));
|
||||
|
||||
return $reader;
|
||||
}
|
||||
|
||||
public function testOutlineShowsGroupPresetsWithNames(): void
|
||||
{
|
||||
DiviFixtures::givenPost(DiviFixtures::markup('stage4/page--designsystem.html'));
|
||||
$ability = new DiviOutlineAbility(new DiviPageLoader(DiviFixtures::schema()), $this->designWithGroupPresets());
|
||||
|
||||
$result = $ability->execute(['post_id' => 7]);
|
||||
$byId = array_column($result['nodes'], null, 'id');
|
||||
|
||||
self::assertSame([], $byId['s0.r0.c0.m1']['group_presets']);
|
||||
self::assertSame(['[Fixture] Text Hinweis'], $byId['s0.r0.c0.m1']['presets']);
|
||||
self::assertSame(['font-body: [Fixture] Fließtext'], $byId['s0.r0.c0.m2']['group_presets']);
|
||||
self::assertSame(['spacing: [Fixture] Abstand Karte'], $byId['s0.r0.c0.m5']['group_presets']);
|
||||
self::assertStringContainsString(
|
||||
'{Preset: [Fixture] Blurb Leistung} {Gruppen-Presets: spacing: [Fixture] Abstand Karte}',
|
||||
$result['outline']
|
||||
);
|
||||
self::assertContains('group_presets', $ability->outputSchema()['properties']['nodes']['items']['required']);
|
||||
}
|
||||
|
||||
public function testNodeGetListsGroupPresetsWithGroupAndNames(): void
|
||||
{
|
||||
DiviFixtures::givenPost(DiviFixtures::markup('stage4/page--designsystem.html'));
|
||||
$ability = new DiviNodeGetAbility(new DiviPageLoader(DiviFixtures::schema()), $this->designWithGroupPresets());
|
||||
|
||||
$blurb = $ability->execute(['post_id' => 7, 'id' => 's0.r0.c0.m5']);
|
||||
$plain = $ability->execute(['post_id' => 7, 'id' => 's0.r0.c0.m3']);
|
||||
|
||||
self::assertSame(
|
||||
[[
|
||||
'group_id' => 'module.decoration.spacing',
|
||||
'group' => 'spacing',
|
||||
'presets' => [['id' => 'apzj7e17ok', 'name' => '[Fixture] Abstand Karte']],
|
||||
]],
|
||||
$blurb['group_presets']
|
||||
);
|
||||
self::assertSame([['id' => 'vdcl6msnuo', 'name' => '[Fixture] Blurb Leistung']], $blurb['presets']);
|
||||
self::assertSame([], $plain['group_presets']);
|
||||
self::assertArrayNotHasKey('groupPreset', $blurb['attrs']);
|
||||
}
|
||||
|
||||
public function testOutlineListsNodesWithTreeRevAndPostRev(): void
|
||||
{
|
||||
$content = DiviFixtures::markup('synthetic-basic.html');
|
||||
|
||||
Reference in New Issue
Block a user