Exemplo n.º 1
0
 public function testAnyDescendant()
 {
     $xml = '<?xml version="1.0" ?>
   <test>
     <li id="one"/><li id="two"/><li id="three">
       <li id="inner-one" class="foo">
         <li id="inner-inner-one" class="foo"/>
         <il id="inner-inner-two"/>
         <li id="dont-match-me"/>
       </li>
       <li id="inner-two"/>
     </li>
     <li id="four"/>
     <li id="five"/>
   </test>';
     $doc = new DomDocument();
     $doc->loadXML($xml);
     $handler = new QueryPathCssEventHandler($doc);
     $handler->find('*');
     $matches = $handler->getMatches();
     $this->assertEquals(11, $matches->count());
     $handler = new QueryPathCssEventHandler($doc);
     $handler->find('*.foo');
     $matches = $handler->getMatches();
     $this->assertEquals(2, $matches->count());
     $this->assertEquals('inner-inner-one', $this->nthMatch($matches, 1)->getAttribute('id'));
     $handler = new QueryPathCssEventHandler($doc);
     $handler->find('test > li *.foo');
     $matches = $handler->getMatches();
     $this->assertEquals(2, $matches->count());
     $this->assertEquals('inner-inner-one', $this->nthMatch($matches, 1)->getAttribute('id'));
 }
Exemplo n.º 2
0
 /**
  * Pseudo-class handler for :has(filter).
  * This can also be used as a general filtering routine.
  */
 public function has($filter)
 {
     $matches = $this->candidateList();
     //$found = array();
     $found = new SplObjectStorage();
     foreach ($matches as $item) {
         $handler = new QueryPathCssEventHandler($item);
         $these = $handler->find($filter)->getMatches();
         if (count($these) > 0) {
             $found->attach($item);
         }
     }
     $this->matches = $found;
     return $this;
 }
Exemplo n.º 3
0
 public function replaceAll($selector, DOMDocument $document)
 {
     $replacement = $this->size() > 0 ? $this->getFirstMatch() : $this->document->createTextNode('');
     $c = new QueryPathCssEventHandler($document);
     $c->find($selector);
     $temp = $c->getMatches();
     foreach ($temp as $item) {
         $node = $replacement->cloneNode();
         $node = $document->importNode($node);
         $item->parentNode->replaceChild($node, $item);
     }
     return qp($document, NULL, $this->options);
 }
 public function replaceAll($selector, DOMDocument $document)
 {
     $replacement = $this->size() > 0 ? $this->matches[0] : $this->document->createTextNode('');
     $c = new QueryPathCssEventHandler($document);
     $c->find($selector);
     $temp = $c->getMatches();
     foreach ($temp as $item) {
         $item->parentNode->replaceChild($item, $replacement);
     }
     return $this;
 }