$variable]) ); self::assertSame( '{"t":"\u003cp\u003eA \u0026 B\u003c/p\u003e \u002d\u002d \u005c/ ä","e":{},"l":[]}', Serializer::attributes(['t' => '
A & B
-- \\/ ä', 'e' => new stdClass(), 'l' => []]) ); } public function testRegeneratesOnlyTheChangedOpener(): void { $content = ''; $document = (new Parser())->parse($content); $text = $document->children()[0]->children()[0]; $text->setAttrs(['x' => 'z']); self::assertSame( '', Serializer::document($document) ); } public function testNewBlocksAreWrittenAsPairs(): void { $block = Block::create('divi/row', ['builderVersion' => '5.2.1'], [Block::create('divi/column')]); self::assertSame( '' . '', Serializer::block($block) ); self::assertSame('', Serializer::block(Block::create('core/paragraph'))); } public function testVoidBlockGettingAChildBecomesAPair(): void { $document = (new Parser())->parse(''); $column = $document->children()[0]; $column->insertChild(0, Block::create('divi/text')); self::assertSame( '', Serializer::document($document) ); } public function testInsertAndRemoveKeepSurroundingText(): void { $document = (new Parser())->parse("A\nBC"); [$text, $code] = $document->children(); $new = Block::create('divi/button'); $document->insertChild(1, $new); self::assertSame( "A\nBC", Serializer::document($document) ); self::assertSame(2, $document->removeChild($code)); self::assertSame(0, $document->indexOf($text)); $document->insertChild(99, $code); self::assertSame(2, $document->indexOf($code)); $empty = new Document(); $empty->append("\n"); $empty->insertChild(0, Block::create('divi/section')); self::assertSame("\n", Serializer::document($empty)); } public function testCopyIsDeepAndSerializesIdentically(): void { $content = ''; $row = (new Parser())->parse($content)->children()[0]; $copy = $row->copy(); $copy->children()[0]->setAttrs(['b' => 2]); self::assertSame($content, Serializer::block($row)); self::assertSame('', Serializer::block($copy)); } }