getElement() public method

public getElement ( ) : DOMElement
return DOMElement
Beispiel #1
0
 /**
  * Indicates if two documents are the same document.
  * 
  * @param Document|\DOMDocument $document The compared document
  *
  * @return bool
  *
  * @throws \InvalidArgumentException if the provided argument is not an instance of \DOMDocument or \DiDom\Document
  */
 public function is($document)
 {
     if ($document instanceof self) {
         $element = $document->getElement();
     } else {
         if (!$document instanceof DOMDocument) {
             throw new InvalidArgumentException(sprintf('Argument 1 passed to %s must be an instance of %s or DOMDocument, %s given', __METHOD__, __CLASS__, is_object($document) ? get_class($document) : gettype($document)));
         }
         $element = $document->documentElement;
     }
     if ($element === null) {
         return false;
     }
     return $this->getElement()->isSameNode($element);
 }
Beispiel #2
0
 public function testGetElement()
 {
     $html = $this->loadFixture('posts.html');
     $document = new Document($html, false);
     $domElement = $document->getElement();
     $this->assertInstanceOf('DOMElement', $domElement);
 }
Beispiel #3
0
 /**
  * @param  Document|\DOMDocument $document
  * @return bool
  * @throws \InvalidArgumentException
  */
 public function is($document)
 {
     if ($document instanceof Document) {
         $element = $document->getElement();
     } else {
         if (!$document instanceof DOMDocument) {
             throw new InvalidArgumentException(sprintf('Argument 1 passed to %s must be an instance of %s or %s, %s given', __METHOD__, __CLASS__, 'DOMDocument', gettype($document)));
         }
         $element = $document->documentElement;
     }
     return $this->getElement()->isSameNode($element);
 }
Beispiel #4
0
 public function testParent()
 {
     $html = $this->loadFixture('posts.html');
     $document = new Document($html, false);
     $element = $document->createElement('span', 'value');
     $parent = $element->parent();
     $this->assertInstanceOf('DiDom\\Document', $parent);
     $this->assertTrue($document->getElement()->isSameNode($parent->getElement()));
 }