function AssertContentTrait::xpath
Same name in other branches
- 9 core/tests/Drupal/KernelTests/AssertContentTrait.php \Drupal\KernelTests\AssertContentTrait::xpath()
- 10 core/tests/Drupal/KernelTests/AssertContentTrait.php \Drupal\KernelTests\AssertContentTrait::xpath()
- 11.x core/tests/Drupal/KernelTests/AssertContentTrait.php \Drupal\KernelTests\AssertContentTrait::xpath()
Performs an xpath search on the contents of the internal browser.
The search is relative to the root element (HTML tag normally) of the page.
Parameters
string $xpath: The xpath string to use in the search.
array $arguments: 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
\SimpleXMLElement[]|bool The return value of the xpath search or FALSE on failure. For details on the xpath string format and return values see the SimpleXML documentation.
See also
http://php.net/manual/function.simplexml-element-xpath.php
51 calls to AssertContentTrait::xpath()
- AggregatorTestBase::createFeed in core/
modules/ aggregator/ src/ Tests/ AggregatorTestBase.php - Creates an aggregator feed.
- AreaEntityTest::doTestRender in core/
modules/ views/ tests/ src/ Kernel/ Handler/ AreaEntityTest.php - Tests rendering the entity area handler.
- AssertContentTrait::assertFieldByXPath in core/
tests/ Drupal/ KernelTests/ AssertContentTrait.php - Asserts that a field exists in the current page by the given XPath.
- AssertContentTrait::assertFieldChecked in core/
tests/ Drupal/ KernelTests/ AssertContentTrait.php - Asserts that a checkbox field in the current page is checked.
- AssertContentTrait::assertLink in core/
tests/ Drupal/ KernelTests/ AssertContentTrait.php - Passes if a link with the specified label is found.
File
-
core/
tests/ Drupal/ KernelTests/ AssertContentTrait.php, line 226
Class
- AssertContentTrait
- Provides test methods to assert content.
Namespace
Drupal\KernelTestsCode
protected function xpath($xpath, array $arguments = []) {
if ($this->parse()) {
$xpath = $this->buildXPathQuery($xpath, $arguments);
$result = $this->elements
->xpath($xpath);
// Some combinations of PHP / libxml versions return an empty array
// instead of the documented FALSE. Forcefully convert any falsish values
// to an empty array to allow foreach(...) constructions.
return $result ?: [];
}
return FALSE;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.