Example #1
0
 public function testIteration()
 {
     $document = new HTMLDocument(test\Helper::HTML_MORE);
     foreach ($document->querySelectorAll("p") as $i => $p) {
         $paragraphItem = $document->getElementsByTagName("p")[$i];
         $this->assertSame($paragraphItem, $p);
     }
 }
Example #2
0
 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));
 }
Example #3
0
 public function testReplaceWithInSameDocument()
 {
     $document = new HTMLDocument(test\Helper::HTML_MORE);
     $h2 = $document->getElementById("who");
     $beforeH2 = $h2->previousSibling;
     $h1 = $document->firstChild;
     $h2->replaceWith($h1);
     $this->assertSame($h1, $beforeH2->nextSibling);
     $this->assertNotSame($h1, $document->firstChild);
 }
Example #4
0
 public function testQuerySelectorAll()
 {
     $document = new HTMLDocument(test\Helper::HTML_MORE);
     $pListTagName = $document->getElementsByTagName("p");
     $pListQuerySelector = $document->querySelectorAll("p");
     $this->assertEquals($pListTagName->length, $pListQuerySelector->length);
     for ($i = 0, $len = $pListQuerySelector->length; $i < $len; $i++) {
         $this->assertSame($pListQuerySelector->item($i), $pListTagName->item($i));
     }
 }
 function process() {
   $d = new HTMLDocument($this->getResponce());
   $d->setTemplate($this->getPackage()->getResourcePath('WelcomeToFreeform.html'));
   if($p = Package::getPackageByName('freddy')) {
     $d->setVariable('freddy', new Location('Freddy'));
   }
   if($p = Package::getPackageByName('freeformdemo')) {
     $d->setVariable('demo', new Location('FDWelcome'));
   }
   $this->getResponce()->setDocument($d);
 }
Example #6
0
 public function testToggle()
 {
     $document = new HTMLDocument(test\Helper::HTML_MORE);
     $h2 = $document->getElementById("who");
     $classString = "h-who m-before-p m-test";
     $this->assertEquals($classString, $h2->getAttribute("class"));
     $classStringNoBefore = str_replace("m-before-p ", "", $classString);
     $h2->classList->toggle("m-before-p");
     $this->assertEquals($classStringNoBefore, $h2->getAttribute("class"));
     $h2->classList->toggle("m-before-p");
     $this->assertEquals("{$classStringNoBefore} m-before-p", $h2->getAttribute("class"));
 }
 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);
 }
Example #8
0
\t\ttext3
\t</div>
\t<div id="div3" class="hello hello2">
\t\ttext4
\t\t<div id="div4" class="hello2">
\t\t\ttext5
\t\t</div>
\t</div>
\ttext6
\t<div id="div5" class="hello2">
\t</div>
\ttext7
</body> 
</html> 
HTML;
$doc = new HTMLDocument($html);
echo 'by id:';
var_dump($doc->getElementById('div3')->getOuterHTML());
echo 'by tag:';
foreach ($doc->getElementsByTag('div') as $elem) {
    var_dump($elem->__toString());
}
echo 'by class:';
foreach ($doc->getElementsByClass('hello') as $elem) {
    var_dump($elem->__toString());
}
echo 'by attribute:';
foreach ($doc->getElementsByAttribute('class', 'hello2') as $elem) {
    var_dump($elem->__toString());
}
echo 'find----' . PHP_EOL;
 public function __construct()
 {
     parent::__construct('1.0', 'utf-8', 'html');
     $this->alerts = new AlertStack();
 }
Example #10
0
 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);
 }