Skip to content

Commit

Permalink
Add more Serializer tests to make infection happy
Browse files Browse the repository at this point in the history
  • Loading branch information
theseer committed Dec 3, 2023
1 parent 879b14e commit e4a4887
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions tests/serializer/HTMLSerializerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,59 @@ public function testEncodingGetSerializedCorrectly() {

}

public function testNoRedundantNamespaceDeclarationsAreCreated(): void {
$dom = new DOMDocument();
$dom->preserveWhiteSpace = false;
$dom->loadXML('<html xmlns="http://www.w3.org/1999/xhtml" xmlns:a="urn:a" xmlns:c="urn:c">
<p xmlns="http://www.w3.org/1999/xhtml" xmlns:a="urn:a" a:attr="value" xmlns:b="urn:b">
<a:a />
<b:b />
</p>
<h:p xmlns:h="http://www.w3.org/1999/xhtml" xmlns:c="urn:c" c:attr="value">
<a:a />
</h:p>
</html>
');

$expected = implode("\n", [
'<html xmlns="http://www.w3.org/1999/xhtml" xmlns:c="urn:c" xmlns:a="urn:a">',
' <p a:attr="value" xmlns:b="urn:b">',
' <a:a></a:a>',
' <b:b></b:b>',
' </p>',
' <p c:attr="value">',
' <a:a></a:a>',
' </p>',
'</html>' . "\n"
]);

$this->assertSame(
$expected,
(new HTMLSerializer())->noHtml5Doctype()->serialize($dom)
);
}

public function testNoRedundantNamespacesAreCreated(): void {
$dom = new DOMDocument();
$dom->preserveWhiteSpace = false;
$dom->loadXML(
'<html xmlns="http://www.w3.org/1999/xhtml" xmlns:a="a:a" xmlns:b="http://www.w3.org/1999/xhtml" xmlns:c="c:c">
<b:p xmlns:a="a:a" xmlns:b="http://www.w3.org/1999/xhtml" xmlns:c="c:c"/>
</html>
');

$expected = implode("\n", [
'<html xmlns="http://www.w3.org/1999/xhtml" xmlns:c="c:c" xmlns:a="a:a">',
' <p></p>',
'</html>' . "\n"
]);

$this->assertSame(
$expected,
(new HTMLSerializer())->noHtml5Doctype()->serialize($dom)
);
}


private function createInputDocument(): Document {
return Document::fromString(file_get_contents(__DIR__ . '/../_data/serializer/input.xml'));
Expand Down

0 comments on commit e4a4887

Please sign in to comment.