feat: Divi path IDs, attribute paths and outline

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:
2026-09-26 11:35:03 +02:00
co-authored by Claude Opus 5.5
parent 8222240ed6
commit 08d70abfc7
6 changed files with 654 additions and 0 deletions
@@ -0,0 +1,60 @@
<?php
declare(strict_types=1);
namespace LIT\MCP\Tests\Unit\Integrations\Divi\BlockTree;
use LIT\MCP\Integrations\Divi\BlockTree\NodeIndex;
use LIT\MCP\Integrations\Divi\BlockTree\Parser;
use PHPUnit\Framework\TestCase;
final class NodeIndexTest extends TestCase
{
public function testAssignsPathIdsPerParentAndLetter(): void
{
$index = NodeIndex::build((new Parser())->parse($this->fixture('synthetic-basic.html')));
self::assertSame(
[
's0', 's0.r0', 's0.r0.c0', 's0.r0.c0.m0', 's0.r0.c1', 's0.r0.c1.m0', 's0.r0.c1.m1', 's0.r0.c1.m2',
's1', 's1.r0', 's1.r0.c0', 's1.r0.c0.m0', 's1.r0.c1', 's1.r0.c1.m0', 's1.r0.c1.m0.m0',
's1.r0.c1.m0.m1',
],
array_column($index->entries(), 'id')
);
self::assertSame('divi/button', $index->find('s0.r0.c1.m2')?->name());
self::assertSame('s0.r0.c1', $index->parentId($index->find('s0.r0.c1.m2')));
self::assertNull($index->parentId($index->find('s1')));
self::assertSame('divi/placeholder', $index->root() instanceof \LIT\MCP\Integrations\Divi\BlockTree\Block
? $index->root()->name() : '');
self::assertSame($index->root(), $index->parentOf($index->find('s0')));
self::assertNull($index->find('s9'));
}
public function testGlobalAndForeignBlocksAreLeavesWithOwnLetters(): void
{
$index = NodeIndex::build((new Parser())->parse($this->fixture('synthetic-mixed.html')));
self::assertSame(
['x0', 's0', 's0.c0', 's0.c0.m0', 's0.c1', 's0.c1.r0', 's0.c1.r0.c0', 's0.c1.r0.c0.m0', 's0.c1.r0.c1',
's1', 's1.g0', 's1.g1', 's1.g2'],
array_column($index->entries(), 'id')
);
self::assertSame(1, preg_match(NodeIndex::ID_PATTERN, 's1.g2'));
self::assertSame(0, preg_match(NodeIndex::ID_PATTERN, 's1..g2'));
}
public function testDocumentWithoutPlaceholderIsItsOwnRoot(): void
{
$document = (new Parser())->parse('<!-- wp:divi/section /-->');
$index = NodeIndex::build($document);
self::assertSame($document, $index->root());
self::assertSame('s0', $index->entries()[0]['id']);
}
private function fixture(string $name): string
{
return (string) file_get_contents(dirname(__DIR__, 4) . '/Fixtures/divi/' . $name);
}
}