Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #559 from stof/manipulator_fix

Fixed the XPath prefixing when the query wraps a union in braces
  • Loading branch information...
commit e0a4d934df9569f1cc5d1b8de9849ceeca87f7a8 2 parents 7ac4d79 + 7ee4948
@stof stof authored
View
11 src/Behat/Mink/Selector/Xpath/Manipulator.php
@@ -46,13 +46,22 @@ public function prepend($xpath, $prefix)
// Split any unions into individual expressions.
foreach (preg_split(self::UNION_PATTERN, $xpath) as $expression) {
$expression = trim($expression);
+ $parenthesis = '';
+
+ // If the union is inside some braces, we need to preserve the opening braces and apply
+ // the prefix only inside it.
+ if (preg_match('/^[\(\s*]+/', $expression, $matches)) {
+ $parenthesis = $matches[0];
+ $expression = substr($expression, strlen($parenthesis));
+ }
+
// add prefix before element selector
if (0 === strpos($expression, '/')) {
$expression = $prefix . $expression;
} else {
$expression = $prefix . '/' . $expression;
}
- $expressions[] = $expression;
+ $expressions[] = $parenthesis . $expression;
}
return implode(' | ', $expressions);
View
10 tests/Selector/Xpath/ManipulatorTest.php
@@ -34,6 +34,16 @@ public function getPrependedXpath()
'some_tag1 | some_tag2',
'some_xpath/some_tag1 | some_xpath/some_tag2',
),
+ 'wrapped union' => array(
+ 'some_xpath',
+ '(some_tag1 | some_tag2)/some_child',
+ '(some_xpath/some_tag1 | some_xpath/some_tag2)/some_child',
+ ),
+ 'multiple wrapped union' => array(
+ 'some_xpath',
+ '( ( some_tag1 | some_tag2)/some_child | some_tag3)/leaf',
+ '( ( some_xpath/some_tag1 | some_xpath/some_tag2)/some_child | some_xpath/some_tag3)/leaf',
+ ),
'parent union' => array(
'some_xpath | another_xpath',
'some_tag1 | some_tag2',
Please sign in to comment.
Something went wrong with that request. Please try again.