You are here

protected function AssertContentTrait::xpath in Drupal 10

Same name and namespace in other branches
  1. 8 core/tests/Drupal/KernelTests/AssertContentTrait.php \Drupal\KernelTests\AssertContentTrait::xpath()
  2. 9 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

10 calls to AssertContentTrait::xpath()
CommentUserNameTest::testUsername in core/modules/comment/tests/src/Kernel/Views/CommentUserNameTest.php
Tests the username formatter.
ElementsFieldsetTest::testFieldsetDescriptions in core/modules/system/tests/src/Kernel/Form/ElementsFieldsetTest.php
Tests different display options for fieldset element descriptions.
ExternalFormUrlTest::testActionUrlBehavior in core/tests/Drupal/KernelTests/Core/Form/ExternalFormUrlTest.php
Tests form behavior.
FormActionXssTest::testFormActionXss in core/tests/Drupal/KernelTests/Core/Form/FormActionXssTest.php
Tests form action attribute for XSS.
FormElementLabelTest::testAttributes in core/modules/system/tests/src/Kernel/Form/FormElementLabelTest.php
Ensures that attributes can be placed for form element label.

... See full list

File

core/tests/Drupal/KernelTests/AssertContentTrait.php, line 211

Class

AssertContentTrait
Provides test methods to assert content.

Namespace

Drupal\KernelTests

Code

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;
}