function AttributeTest::getXPathResultCount

Same name and namespace in other branches
  1. 11.x core/tests/Drupal/Tests/Core/Template/AttributeTest.php \Drupal\Tests\Core\Template\AttributeTest::getXPathResultCount()
  2. 10 core/tests/Drupal/Tests/Core/Template/AttributeTest.php \Drupal\Tests\Core\Template\AttributeTest::getXPathResultCount()
  3. 8.9.x core/tests/Drupal/Tests/Core/Template/AttributeTest.php \Drupal\Tests\Core\Template\AttributeTest::getXPathResultCount()

Counts the occurrences of the given XPath query in a given HTML snippet.

Parameters

string $query: The XPath query to execute.

string $html: The HTML snippet to check.

Return value

int The number of results that are found.

File

core/tests/Drupal/Tests/Core/Template/AttributeTest.php, line 449

Class

AttributeTest
@coversDefaultClass \Drupal\Core\Template\Attribute[[api-linebreak]] @group Template

Namespace

Drupal\Tests\Core\Template

Code

protected function getXPathResultCount($query, $html) {
  $document = new \DOMDocument();
  $document->loadHTML($html);
  $xpath = new \DOMXPath($document);
  return $xpath->query($query)->length;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.