function AttributeTest::getXPathResultCount

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Core/Template/AttributeTest.php \Drupal\Tests\Core\Template\AttributeTest::getXPathResultCount()
  2. 8.9.x core/tests/Drupal/Tests/Core/Template/AttributeTest.php \Drupal\Tests\Core\Template\AttributeTest::getXPathResultCount()
  3. 10 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.

4 calls to AttributeTest::getXPathResultCount()
AttributeTest::assertClass in core/tests/Drupal/Tests/Core/Template/AttributeTest.php
Checks that the given CSS class is present in the given HTML snippet.
AttributeTest::assertID in core/tests/Drupal/Tests/Core/Template/AttributeTest.php
Checks that the given CSS ID is present in the given HTML snippet.
AttributeTest::assertNoClass in core/tests/Drupal/Tests/Core/Template/AttributeTest.php
Checks that the given CSS class is not present in the given HTML snippet.
AttributeTest::assertNoID in core/tests/Drupal/Tests/Core/Template/AttributeTest.php
Checks that the given CSS ID is not present in the given HTML snippet.

File

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

Class

AttributeTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Core%21Template%21Attribute.php/class/Attribute/11.x" title="Collects, sanitizes, and renders HTML attributes." class="local">\Drupal\Core\Template\Attribute</a> @group Template

Namespace

Drupal\Tests\Core\Template

Code

protected function getXPathResultCount($query, $html) {
    $document = Html::load($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.