public function testElementSiblings() { $document = new HTMLDocument(test\Helper::HTML_MORE); $whoHeading = $document->getElementById("who"); $plugParagraph = $document->querySelector("p.plug"); $formsAnchor = $document->querySelector("a[name='forms']"); $this->assertEquals("p", $whoHeading->nextElementSibling->tagName); $this->assertSame($formsAnchor, $whoHeading->nextElementSibling->nextElementSibling); $this->assertSame($plugParagraph, $whoHeading->previousElementSibling); $this->assertInstanceOf("\\Gt\\Dom\\Element", $formsAnchor); $firstImg = $document->querySelector("img"); $this->assertEquals("h1", $firstImg->previousElementSibling->tagName); $this->assertNull($firstImg->previousElementSibling->previousElementSibling); $this->assertNull($document->body->lastElementChild->nextElementSibling); }
public function testQuerySelector() { $document = new HTMLDocument(test\Helper::HTML_MORE); $h2TagName = $document->getElementsByTagName("h2")->item(0); $h2QuerySelector = $document->querySelector("h2"); $this->assertSame($h2QuerySelector, $h2TagName); }
public function testChildren() { $document = new HTMLDocument(test\Helper::HTML_MORE); $children = $document->body->children; $this->assertNotSame($children, $document->body->childNodes); $this->assertNotCount($document->body->childNodes->length, $children); $firstImg = $document->querySelector("img"); $this->assertSame($firstImg, $children->item(1)); }
public function testNamedItem() { $document = new HTMLDocument(test\Helper::HTML_MORE); $whoNamed = $document->body->children->namedItem("who"); $whoH2 = $document->getElementById("who"); $this->assertSame($whoNamed, $whoH2, "Named item should match by id first"); $formsNamed = $document->body->children->namedItem("forms"); $formsAnchor = $document->querySelector("a[name='forms']"); $this->assertSame($formsNamed, $formsAnchor, "Named item should match name when no id match"); }
public function testOuterHTML() { $document = new HTMLDocument(test\Helper::HTML_MORE); $p = $document->querySelector(".link-to-twitter"); $this->assertContains("<a href=", $p->outerHTML); $this->assertContains("Greg Bowler", $p->outerHTML); $this->assertContains("<p", $p->outerHTML); $this->assertContains("</p>", $p->outerHTML); $this->assertNotContains("<h2", $p->outerHTML); $this->assertNotContains("name=\"forms\">", $p->outerHTML); }