Skip to content

Commit

Permalink
The library now works the same way as DomDocument when loadHTML() is …
Browse files Browse the repository at this point in the history
…not called.
  • Loading branch information
ivopetkov committed Nov 9, 2020
1 parent 98e40b4 commit 667e450
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
4 changes: 0 additions & 4 deletions src/HTML5DOMDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -288,10 +288,6 @@ private function addBodyElementIfMissing(): bool
*/
public function saveHTML(\DOMNode $node = null): string
{
if (!$this->loaded) {
return '<!DOCTYPE html>';
}

$nodeMode = $node !== null;
if ($nodeMode && $node instanceof \DOMDocument) {
$nodeMode = false;
Expand Down
13 changes: 12 additions & 1 deletion tests/Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function testSaveHTML()

$dom = new HTML5DOMDocument();
// without loading anything
$this->assertTrue('<!DOCTYPE html>' === $dom->saveHTML());
$this->assertTrue('' === $dom->saveHTML());
}

/**
Expand Down Expand Up @@ -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('<div>text</div>', $dom->saveHTML());
}
}

0 comments on commit 667e450

Please # to comment.