function FieldRdfaTestBase::xpathContent

Same name in other branches
  1. 8.9.x core/modules/rdf/tests/src/Kernel/Field/FieldRdfaTestBase.php \Drupal\Tests\rdf\Kernel\Field\FieldRdfaTestBase::xpathContent()

Performs an xpath search on a certain content.

The search is relative to the root element of the $content variable.

Parameters

string $content: The html to parse.

string $xpath: The xpath string to use in the search.

array $arguments: Some arguments for the xpath.

Return value

array|false The return value of the xpath search. For details on the xpath string format and return values see the SimpleXML documentation, http://php.net/manual/function.simplexml-element-xpath.php.

8 calls to FieldRdfaTestBase::xpathContent()
NumberFieldRdfaTest::testDecimalFormatter in core/modules/rdf/tests/src/Kernel/Field/NumberFieldRdfaTest.php
Tests the decimal formatter.
NumberFieldRdfaTest::testDecimalFormatterWithSettings in core/modules/rdf/tests/src/Kernel/Field/NumberFieldRdfaTest.php
Tests the decimal formatter with settings.
NumberFieldRdfaTest::testFloatFormatter in core/modules/rdf/tests/src/Kernel/Field/NumberFieldRdfaTest.php
Tests the float formatter.
NumberFieldRdfaTest::testFloatFormatterWithScale in core/modules/rdf/tests/src/Kernel/Field/NumberFieldRdfaTest.php
Tests the float formatter with a scale. Scale is not exercised.
NumberFieldRdfaTest::testFloatFormatterWithScaleExercised in core/modules/rdf/tests/src/Kernel/Field/NumberFieldRdfaTest.php
Tests the float formatter with a scale. Scale is exercised.

... See full list

File

core/modules/rdf/tests/src/Kernel/Field/FieldRdfaTestBase.php, line 163

Class

FieldRdfaTestBase

Namespace

Drupal\Tests\rdf\Kernel\Field

Code

protected function xpathContent($content, $xpath, array $arguments = []) {
    if ($elements = $this->parseContent($content)) {
        $xpath = $this->buildXPathQuery($xpath, $arguments);
        $result = $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 ? $result : [];
    }
    else {
        return FALSE;
    }
}

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