parse();
return $treeBuilder->document();
}
public function testDocument() {
$html = "";
$doc = $this->parse($html);
$this->assertInstanceOf('\DOMDocument', $doc);
$this->assertEquals('html', $doc->documentElement->tagName);
}
public function testElements() {
$html = "
";
$doc = $this->parse($html);
$root = $doc->documentElement;
$this->assertEquals('html', $root->tagName);
$this->assertEquals('html', $root->localName);
$this->assertEquals('html', $root->nodeName);
$this->assertEquals(2, $root->childNodes->length);
$kids = $root->childNodes;
$this->assertEquals('head', $kids->item(0)->tagName);
$this->assertEquals('body', $kids->item(1)->tagName);
$head = $kids->item(0);
$this->assertEquals(1, $head->childNodes->length);
$this->assertEquals('title', $head->childNodes->item(0)->tagName);
}
public function testAttributes() {
$html = "
";
$doc = $this->parse($html);
$root = $doc->documentElement;
$body = $root->GetElementsByTagName('body')->item(0);
$this->assertEquals('body', $body->tagName);
$this->assertTrue($body->hasAttributes());
$this->assertEquals('a', $body->getAttribute('id'));
$this->assertEquals('b c', $body->getAttribute('class'));
$body2 = $doc->getElementById('a');
$this->assertEquals('body', $body2->tagName);
$this->assertEquals('a', $body2->getAttribute('id'));
}
public function testMissingHtmlTag() {
$html = "test";
$doc = $this->parse($html);
$this->assertEquals('html', $doc->documentElement->tagName);
$this->assertEquals('title', $doc->documentElement->childNodes->item(0)->tagName);
}
public function testComment() {
$html = '';
$doc = $this->parse($html);
$comment = $doc->documentElement->childNodes->item(0);
$this->assertEquals(XML_COMMENT_NODE, $comment->nodeType);
$this->assertEquals("Hello World.", $comment->data);
$html = '';
$doc = $this->parse($html);
$comment = $doc->childNodes->item(1);
$this->assertEquals(XML_COMMENT_NODE, $comment->nodeType);
$this->assertEquals("Hello World.", $comment->data);
$comment = $doc->childNodes->item(2);
$this->assertEquals(XML_ELEMENT_NODE, $comment->nodeType);
$this->assertEquals("html", $comment->tagName);
}
public function testCDATA() {
$html = "";
$doc = $this->parse($html);
$wrapper = $doc->getElementsByTagName('mathml')->item(0);
$this->assertEquals(1, $wrapper->childNodes->length);
$cdata = $wrapper->childNodes->item(0);
$this->assertEquals(XML_CDATA_SECTION_NODE, $cdata->nodeType);
$this->assertEquals('test', $cdata->data);
}
public function testText() {
$html = "test";
$doc = $this->parse($html);
$wrapper = $doc->getElementsByTagName('mathml')->item(0);
$this->assertEquals(1, $wrapper->childNodes->length);
$data = $wrapper->childNodes->item(0);
$this->assertEquals(XML_TEXT_NODE, $data->nodeType);
$this->assertEquals('test', $data->data);
}
public function testParseErrors() {
$html = "parse($html);
// We're JUST testing that we can access errors. Actual testing of
// error messages happen in the Tokenizer's tests.
$this->assertGreaterThan(0, count($doc->errors));
$this->assertTrue(is_string($doc->errors[0]));
}
public function testProcessingInstruction() {
// Test the simple case, which is where PIs are inserted into the DOM.
$doc = $this->parse('');
$this->assertEquals(1, $doc->documentElement->childNodes->length);
$pi = $doc->documentElement->firstChild;
$this->assertInstanceOf('\DOMProcessingInstruction', $pi);
$this->assertEquals('foo', $pi->nodeName);
$this->assertEquals('bar', $pi->data);
// Leading xml PIs should be ignored.
$doc = $this->parse('');
$this->assertEquals(2, $doc->childNodes->length);
$this->assertInstanceOf('\DOMDocumentType', $doc->childNodes->item(0));
$this->assertInstanceOf('\DOMElement', $doc->childNodes->item(1));
}
public function testAutocloseP() {
$html = "";
$doc = $this->parse($html);
$p = $doc->getElementsByTagName('p')->item(0);
$this->assertEquals(0, $p->childNodes->length);
$this->assertEquals('figure', $p->nextSibling->tagName);
}
public function testAutocloseLI() {
$this->markTestIncomplete("Incomplete.");
}
public function testMathML() {
$this->markTestIncomplete("Incomplete.");
}
public function testSVG() {
$this->markTestIncomplete("Incomplete.");
}
}