/** Returns a HTML representation of this element and the elements it contains. * @return string the HTML. */ public function toHtml() { $generator = new HtmlGenerator(); return $generator->createHtml($this); }
/** Tests for {@link HtmlGenerator::createHtml}. */ public function testCreateHtml() { $generator = new HtmlGenerator(); $e = new Element('html'); $this->assertSame('<html></html>', $generator->createHtml($e), 'HTML for single element incorrect.'); $e = new Element('html', ['lang' => 'nl']); $this->assertSame('<html lang="nl"></html>', $generator->createHtml($e), 'HTML attribute rendered incorrect.'); $e = new Element('html', []); $this->assertSame('<html></html>', $generator->createHtml($e), 'Empty HTML attribute collection rendered incorrect.'); $e = new Element('html', [], new Element('head')); $this->assertSame('<html><head></head></html>', $generator->createHtml($e), 'HTML children rendered incorrect.'); $e = new Element('p', ['title' => '&']); $this->assertSame('<p title="&"></p>', $generator->createHtml($e), '& in attribute not properly escaped.'); $e = new Element('p', ['title' => '<']); $this->assertSame('<p title="<"></p>', $generator->createHtml($e), '< in attribute not properly escaped.'); $e = new Element('p', ['title' => '>']); $this->assertSame('<p title=">"></p>', $generator->createHtml($e), '> in attribute not properly escaped.'); $e = new Element('p', ['title' => '"']); $this->assertSame('<p title="""></p>', $generator->createHtml($e), '" in attribute not properly escaped.'); $e = new Element('p', [], '&'); $this->assertSame('<p>&</p>', $generator->createHtml($e), '& in content not properly escaped.'); $e = new Element('p', [], '<'); $this->assertSame('<p><</p>', $generator->createHtml($e), '< in content not properly escaped.'); $e = new Element('p', [], '>'); $this->assertSame('<p>></p>', $generator->createHtml($e), '> in content not properly escaped.'); $e = new Element('p', [], '"'); $this->assertSame('<p>"</p>', $generator->createHtml($e), '" in content escaped.'); }