feat: global instance in the builder's format, deglobalize, library content rules
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -6,6 +6,7 @@ namespace LIT\MCP\Tests\Unit\Integrations\Divi\BlockTree;
|
||||
|
||||
use LIT\MCP\Integrations\Divi\BlockTree\Block;
|
||||
use LIT\MCP\Integrations\Divi\BlockTree\Parser;
|
||||
use LIT\MCP\Integrations\Divi\BlockTree\Serializer;
|
||||
use LogicException;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
@@ -51,4 +52,52 @@ final class ContainerTest extends TestCase
|
||||
$this->expectException(LogicException::class);
|
||||
$void->append('text');
|
||||
}
|
||||
|
||||
public function testReplaceChildKeepsTheTextAround(): void
|
||||
{
|
||||
$document = (new Parser())->parse("A<!-- wp:divi/text /-->B");
|
||||
$new = Block::create('divi/button');
|
||||
|
||||
$document->replaceChild($document->children()[0], $new);
|
||||
|
||||
self::assertSame('A<!-- wp:divi/button --><!-- /wp:divi/button -->B', Serializer::document($document));
|
||||
}
|
||||
|
||||
public function testUnifyLineBreaksOnlyTouchesWhitespaceBetweenBlocks(): void
|
||||
{
|
||||
$document = (new Parser())->parse(
|
||||
"<!-- wp:divi/section -->\r\n<!-- wp:divi/row -->\r\n<!-- /wp:divi/row -->\r\n<!-- /wp:divi/section -->x\r\ny"
|
||||
);
|
||||
|
||||
$document->unifyLineBreaks();
|
||||
|
||||
self::assertSame(
|
||||
"<!-- wp:divi/section -->\n<!-- wp:divi/row -->\n<!-- /wp:divi/row -->\n<!-- /wp:divi/section -->x\r\ny",
|
||||
Serializer::document($document)
|
||||
);
|
||||
}
|
||||
|
||||
/** Global instances stay opaque: their bytes are Divi's, even the whitespace inside. */
|
||||
public function testUnifyLineBreaksLeavesOpaqueBlocksAlone(): void
|
||||
{
|
||||
$markup = "<!-- wp:divi/global-layout {\"globalModule\":\"5\"} -->\r\n<!-- wp:divi/text /-->\r\n"
|
||||
. "<!-- /wp:divi/global-layout -->\r\n";
|
||||
$document = (new Parser())->parse($markup);
|
||||
|
||||
$document->unifyLineBreaks();
|
||||
|
||||
self::assertSame(substr($markup, 0, -2) . "\n", Serializer::document($document));
|
||||
}
|
||||
|
||||
public function testReplaceChildRefusesOnAnOpaqueBlock(): void
|
||||
{
|
||||
$document = (new Parser())->parse(
|
||||
'<!-- wp:divi/global-layout {"globalModule":"5"} --><!-- wp:divi/text /--><!-- /wp:divi/global-layout -->'
|
||||
);
|
||||
$instance = $document->children()[0];
|
||||
|
||||
$this->expectException(LogicException::class);
|
||||
|
||||
$instance->replaceChild($instance->children()[0], Block::create('divi/button'));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user