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:
@@ -7,6 +7,7 @@ namespace LIT\MCP\Tests\Unit\Integrations\Divi\BlockTree;
|
||||
use InvalidArgumentException;
|
||||
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;
|
||||
use stdClass;
|
||||
@@ -74,4 +75,31 @@ final class BlockTest extends TestCase
|
||||
self::assertEquals($block->attrs()['localAttrs'], $copy->attrs()['localAttrs']);
|
||||
self::assertNotSame($block->attrs()['nested']['obj'], $copy->attrs()['nested']['obj']);
|
||||
}
|
||||
|
||||
public function testCopyAsRegeneratesTheDelimitersAndKeepsChildrenAndText(): void
|
||||
{
|
||||
$document = (new Parser())->parse("<!-- wp:divi/row {\"a\":1} -->\n<!-- wp:divi/column /-->\n<!-- /wp:divi/row -->");
|
||||
$row = $document->children()[0];
|
||||
|
||||
$copy = $row->copyAs('divi/global-layout', ['globalModule' => '5', 'blockName' => 'divi/row']);
|
||||
|
||||
self::assertSame(
|
||||
"<!-- wp:divi/global-layout {\"globalModule\":\"5\",\"blockName\":\"divi/row\"} -->\n<!-- wp:divi/column /-->\n"
|
||||
. '<!-- /wp:divi/global-layout -->',
|
||||
Serializer::block($copy)
|
||||
);
|
||||
self::assertTrue($copy->isOpaque());
|
||||
self::assertSame(
|
||||
"<!-- wp:divi/row {\"a\":1} -->\n<!-- wp:divi/column /-->\n<!-- /wp:divi/row -->",
|
||||
Serializer::block($row)
|
||||
);
|
||||
self::assertFalse($row->copyAs('divi/row', [])->isOpaque());
|
||||
}
|
||||
|
||||
public function testCopyAsRefusesInvalidNames(): void
|
||||
{
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
|
||||
Block::create('divi/text')->copyAs('Divi Text', []);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user