parse(''); $section = $document->children()[0]; self::assertTrue($section->isOpaque()); $this->expectException(LogicException::class); $section->insertChild(0, Block::create('divi/text')); } public function testInsertChildRefusesOnABlockWithUndecodableAttrs(): void { $document = (new Parser())->parse(''); $section = $document->children()[0]; self::assertTrue($section->isOpaque()); $this->expectException(LogicException::class); $section->insertChild(0, Block::create('divi/text')); } public function testRemoveChildRefusesOnAnOpaqueBlock(): void { $document = (new Parser())->parse( '' ); $section = $document->children()[0]; $row = $section->children()[0]; self::assertTrue($section->isOpaque()); $this->expectException(LogicException::class); $section->removeChild($row); } public function testAppendRefusesOnAVoidBlock(): void { $void = Block::parsed('divi/image', [], '', true, false); $this->expectException(LogicException::class); $void->append('text'); } public function testReplaceChildKeepsTheTextAround(): void { $document = (new Parser())->parse("AB"); $new = Block::create('divi/button'); $document->replaceChild($document->children()[0], $new); self::assertSame('AB', Serializer::document($document)); } public function testUnifyLineBreaksOnlyTouchesWhitespaceBetweenBlocks(): void { $document = (new Parser())->parse( "\r\n\r\n\r\nx\r\ny" ); $document->unifyLineBreaks(); self::assertSame( "\n\n\nx\r\ny", Serializer::document($document) ); } /** Global instances stay opaque: their bytes are Divi's, even the whitespace inside. */ public function testUnifyLineBreaksLeavesOpaqueBlocksAlone(): void { $markup = "\r\n\r\n" . "\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( '' ); $instance = $document->children()[0]; $this->expectException(LogicException::class); $instance->replaceChild($instance->children()[0], Block::create('divi/button')); } }