Пример #1
0
 /**
  * Sets the dom tree and the css selector to compare against
  *
  * @param mixed $dom          Dom tree to search into.
  * @param mixed $selector     Css selector to match element.
  * @param string $message     Customised message on failure.
  */
 public function __construct($dom, $selector, $message = '%s')
 {
     parent::__construct($message);
     $this->dom = $dom;
     $this->selector = $selector;
     $css_selector = new CssSelector($this->dom);
     $this->value = $css_selector->getTexts($this->selector);
 }
Пример #2
0
 /**
  *    Sets the dom tree and the css selector to compare against
  *    @param mixed $dom          Dom tree to search into.
  *    @param mixed $selector     Css selector to match element.
  *    @param string $message     Customised message on failure.
  *    @access public
  */
 function CssSelectorExpectation($dom, $selector, $message = '%s')
 {
     $this->SimpleExpectation($message);
     $this->_dom = $dom;
     $this->_selector = $selector;
     $css_selector = new CssSelector($this->_dom);
     $this->_value = $css_selector->getTexts($this->_selector);
 }
Пример #3
0
 public function testParseExceptions()
 {
     try {
         CssSelector::toXPath('h1:');
         $this->fail('->parse() throws an Exception if the css selector is not valid');
     } catch (\Exception $e) {
         $this->assertInstanceOf('\\Symfony\\Component\\CssSelector\\Exception\\ParseException', $e, '->parse() throws an Exception if the css selector is not valid');
         $this->assertEquals("Expected identifier, but <eof at 3> found.", $e->getMessage(), '->parse() throws an Exception if the css selector is not valid');
     }
 }
Пример #4
0
 public function children($query = null)
 {
     $children = array();
     if (!$this->hasChildren()) {
         return $children;
     }
     if ($query == null) {
         foreach ($this->childNodes as $child) {
             if ($child->nodeType == XML_ELEMENT_NODE) {
                 $children[] = $child;
             }
         }
         return $children;
     }
     return $this->query(CssSelector::toXPath($query, 'child::'));
 }
Пример #5
0
 function toXPath($cssExpr, $prefix = 'descendant-or-self::')
 {
     return CssSelector::toXPath($cssExpr, $prefix);
 }
Пример #6
0
 public function find($query)
 {
     return $this->xpath()->query(CssSelector::toXPath($query, 'descendant::'));
 }
Пример #7
0
 function parseCss()
 {
     $this->css = $this->stripComments($this->css);
     $this->substituteIncludes();
     $this->substituteVars();
     $this->buildUrls();
     $matches = array();
     preg_match_all('/([^{]*)\\s*{([^}]+)(?:\\s+)?}(?:\\s+)?/', $this->css, $matches);
     $this->selectors = array();
     for ($i = 0; $i < count($matches[0]); ++$i) {
         $selector = new CssSelector($matches[0][$i]);
         if (isset($this->selectors[$selector->selector])) {
             $selector->inherit($this->selectors[$selector->selector]);
         }
         $this->selectors[$selector->selector] = $selector;
     }
     foreach ($this->selectors as $selector) {
         if ($selector->hasSuper()) {
             $super = $this->selectors[$selector->super];
             $selector->inherit($super);
         }
     }
 }