function FieldRdfaTestBase::assertFormatterRdfa

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

Helper function to test the formatter's RDFa.

Parameters

array $formatter: An associative array describing the formatter to test and its settings containing:

  • type: The machine name of the field formatter to test.
  • settings: The settings of the field formatter to test.

string $property: The property that should be found.

array $expected_rdf_value: An associative array describing the expected value of the property containing:

  • value: The actual value of the string or URI.
  • type: The type of RDF value, e.g. 'literal' for a string, or 'uri'.

Defaults to 'literal'.

  • datatype: (optional) The datatype of the value (e.g. xsd:dateTime).
16 calls to FieldRdfaTestBase::assertFormatterRdfa()
DateTimeFieldRdfaTest::testDefaultFormatter in core/modules/rdf/tests/src/Kernel/Field/DateTimeFieldRdfaTest.php
Tests the default formatter.
EmailFieldRdfaTest::testAllFormatters in core/modules/rdf/tests/src/Kernel/Field/EmailFieldRdfaTest.php
Tests all email formatters.
EntityReferenceRdfaTest::testAllFormatters in core/modules/rdf/tests/src/Kernel/Field/EntityReferenceRdfaTest.php
Tests all the entity reference formatters.
FieldRdfaDatatypeCallbackTest::testDefaultFormatter in core/modules/rdf/tests/src/Kernel/Field/FieldRdfaDatatypeCallbackTest.php
Tests the default formatter.
LinkFieldRdfaTest::runTestAllFormatters in core/modules/rdf/tests/src/Kernel/Field/LinkFieldRdfaTest.php
Helper function to test all link formatters.

... See full list

File

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

Class

FieldRdfaTestBase

Namespace

Drupal\Tests\rdf\Kernel\Field

Code

protected function assertFormatterRdfa($formatter, $property, $expected_rdf_value) {
    $expected_rdf_value += [
        'type' => 'literal',
    ];
    // The field formatter will be rendered inside the entity. Set the field
    // formatter in the entity display options before rendering the entity.
    \Drupal::service('entity_display.repository')->getViewDisplay('entity_test', 'entity_test')
        ->setComponent($this->fieldName, $formatter)
        ->save();
    $build = \Drupal::entityTypeManager()->getViewBuilder($this->entity
        ->getEntityTypeId())
        ->view($this->entity, 'default');
    $output = \Drupal::service('renderer')->renderRoot($build);
    $this->setRawContent($output);
    $this->assertTrue($this->hasRdfProperty($output, $this->uri, $this->uri, $property, $expected_rdf_value), "Formatter {$formatter['type']} exposes data correctly for {$this->fieldType} fields.");
}

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