From 667e4504c73a4f36f754c235c8159acf263ff75e Mon Sep 17 00:00:00 2001 From: Ivo Petkov Date: Mon, 9 Nov 2020 10:57:17 +0200 Subject: [PATCH] The library now works the same way as DomDocument when loadHTML() is not called. --- src/HTML5DOMDocument.php | 4 ---- tests/Test.php | 13 ++++++++++++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/HTML5DOMDocument.php b/src/HTML5DOMDocument.php index 2054b46..cea8993 100644 --- a/src/HTML5DOMDocument.php +++ b/src/HTML5DOMDocument.php @@ -288,10 +288,6 @@ private function addBodyElementIfMissing(): bool */ public function saveHTML(\DOMNode $node = null): string { - if (!$this->loaded) { - return ''; - } - $nodeMode = $node !== null; if ($nodeMode && $node instanceof \DOMDocument) { $nodeMode = false; diff --git a/tests/Test.php b/tests/Test.php index 0108208..43be52a 100644 --- a/tests/Test.php +++ b/tests/Test.php @@ -42,7 +42,7 @@ public function testSaveHTML() $dom = new HTML5DOMDocument(); // without loading anything - $this->assertTrue('' === $dom->saveHTML()); + $this->assertTrue('' === $dom->saveHTML()); } /** @@ -1465,4 +1465,15 @@ public function testInternalEntityFromGetters(string $dom, string $expectedFromP static::assertEquals($expectedFromGetter, $node->getTextContent()); } } + + /** + * + */ + public function testSaveHTMLWithoutLoadHTML() + { + $dom = new \IvoPetkov\HTML5DOMDocument(); + $dom->appendChild($dom->createElement('div')); + $dom->querySelector('*')->innerHTML = 'text'; + $this->assertEquals('
text
', $dom->saveHTML()); + } }