public function testComment() { $dom = $this->html5->loadHTML('<!doctype html> <html lang="en"> <body> <div><!-- foo --></div> </body> </html>'); $stream = fopen('php://temp', 'w'); $r = new OutputRules($stream, $this->html5->getOptions()); $t = new Traverser($dom, $stream, $r, $this->html5->getOptions()); $list = $dom->getElementsByTagName('div'); $r->comment($list->item(0)->childNodes->item(0)); $this->assertEquals('<!-- foo -->', stream_get_contents($stream, -1, 0)); $dom = $this->html5->loadHTML('<!doctype html> <html lang="en"> <body> <div id="foo"></div> </body> </html>'); $dom->getElementById('foo')->appendChild(new \DOMComment('<!-- --> --> Foo -->')); $stream = fopen('php://temp', 'w'); $r = new OutputRules($stream, $this->html5->getOptions()); $t = new Traverser($dom, $stream, $r, $this->html5->getOptions()); $list = $dom->getElementsByTagName('div'); $r->comment($list->item(0)->childNodes->item(0)); // Could not find more definitive guidelines on what this should be. Went with // what the HTML5 spec says and what \DOMDocument::saveXML() produces. $this->assertEquals('<!--<!-- --> --> Foo -->-->', stream_get_contents($stream, -1, 0)); }