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(''); $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); } }