protected function DrupalWebTestCase::buildXPathQuery in SimpleTest 7.2
Same name and namespace in other branches
- 6.2 drupal_web_test_case.php \DrupalWebTestCase::buildXPathQuery()
Builds an XPath query.
Builds an XPath query by replacing placeholders in the query by the value of the arguments.
XPath 1.0 (the version supported by libxml2, the underlying XML library used by PHP) doesn't support any form of quotation. This function simplifies the building of XPath expression.
Parameters
$xpath: An XPath query, possibly with placeholders in the form ':name'.
$args: An array of arguments with keys in the form ':name' matching the placeholders in the query. The values may be either strings or numeric values.
Return value
An XPath query with arguments replaced.
2 calls to DrupalWebTestCase::buildXPathQuery()
- DrupalWebTestCase::constructFieldXpath in ./
drupal_web_test_case.php - Helper function: construct an XPath for the given set of attributes and value.
- DrupalWebTestCase::xpath in ./
drupal_web_test_case.php - Perform an xpath search on the contents of the internal browser. The search is relative to the root element (HTML tag normally) of the page.
File
- ./
drupal_web_test_case.php, line 2322 - Provides DrupalTestCase, DrupalUnitTestCase, and DrupalWebTestCase classes.
Class
- DrupalWebTestCase
- Test case for typical Drupal tests.
Code
protected function buildXPathQuery($xpath, array $args = array()) {
// Replace placeholders.
foreach ($args as $placeholder => $value) {
// XPath 1.0 doesn't support a way to escape single or double quotes in a
// string literal. We split double quotes out of the string, and encode
// them separately.
if (is_string($value)) {
// Explode the text at the quote characters.
$parts = explode('"', $value);
// Quote the parts.
foreach ($parts as &$part) {
$part = '"' . $part . '"';
}
// Return the string.
$value = count($parts) > 1 ? 'concat(' . implode(', \'"\', ', $parts) . ')' : $parts[0];
}
$xpath = preg_replace('/' . preg_quote($placeholder) . '\\b/', $value, $xpath);
}
return $xpath;
}