Пример #1
0
 /**
  * @throws SyntaxError When unknown operator is found
  */
 public function toXpath()
 {
     $path = $this->selector->toXpath();
     $attrib = $this->xpathAttrib();
     $value = $this->value;
     if ($this->operator == 'exists') {
         $path->addCondition($attrib);
     } elseif ($this->operator == '=') {
         $path->addCondition(sprintf('%s = %s', $attrib, XPathExpr::xpathLiteral($value)));
     } elseif ($this->operator == '!=') {
         // FIXME: this seems like a weird hack...
         if ($value) {
             $path->addCondition(sprintf('not(%s) or %s != %s', $attrib, $attrib, XPathExpr::xpathLiteral($value)));
         } else {
             $path->addCondition(sprintf('%s != %s', $attrib, XPathExpr::xpathLiteral($value)));
         }
         // path.addCondition('%s != %s' % (attrib, xpathLiteral(value)))
     } elseif ($this->operator == '~=') {
         $path->addCondition(sprintf("contains(concat(' ', normalize-space(%s), ' '), %s)", $attrib, XPathExpr::xpathLiteral(' ' . $value . ' ')));
     } elseif ($this->operator == '|=') {
         // Weird, but true...
         $path->addCondition(sprintf('%s = %s or starts-with(%s, %s)', $attrib, XPathExpr::xpathLiteral($value), $attrib, XPathExpr::xpathLiteral($value . '-')));
     } elseif ($this->operator == '^=') {
         $path->addCondition(sprintf('starts-with(%s, %s)', $attrib, XPathExpr::xpathLiteral($value)));
     } elseif ($this->operator == '$=') {
         // Oddly there is a starts-with in XPath 1.0, but not ends-with
         $path->addCondition(sprintf('substring(%s, string-length(%s)-%s) = %s', $attrib, $attrib, strlen($value) - 1, XPathExpr::xpathLiteral($value)));
     } elseif ($this->operator == '*=') {
         // FIXME: case sensitive?
         $path->addCondition(sprintf('contains(%s, %s)', $attrib, XPathExpr::xpathLiteral($value)));
     } else {
         throw new SyntaxError(sprintf('Unknown operator: %s', $this->operator));
     }
     return $path;
 }
Пример #2
0
 protected function _xpath_contains($xpath, $expr)
 {
     // text content, minus tags, must contain expr
     if ($expr instanceof ElementNode) {
         $expr = $expr->formatElement();
     }
     // FIXME: lower-case is only available with XPath 2
     //$xpath->addCondition(sprintf('contains(lower-case(string(.)), %s)', XPathExpr::xpathLiteral(strtolower($expr))));
     $xpath->addCondition(sprintf('contains(string(.), %s)', XPathExpr::xpathLiteral($expr)));
     // FIXME: Currently case insensitive matching doesn't seem to be happening
     return $xpath;
 }
Пример #3
0
 public function toXpath()
 {
     $selXpath = $this->selector->toXpath();
     $selXpath->addCondition(sprintf("contains(concat(' ', normalize-space(@class), ' '), %s)", XPathExpr::xpathLiteral(' ' . $this->className . ' ')));
     return $selXpath;
 }
Пример #4
0
 public function toXpath()
 {
     $path = $this->selector->toXpath();
     $path->addCondition(sprintf('@id = %s', XPathExpr::xpathLiteral($this->id)));
     return $path;
 }
Пример #5
0
 /**
  * @dataProvider getXPathLiteralValues
  */
 public function testXpathLiteral($value, $literal)
 {
     $this->assertEquals($literal, XPathExpr::xpathLiteral($value));
 }