You are here

protected function FieldRdfaTestBase::assertFormatterRdfa in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/rdf/src/Tests/Field/FieldRdfaTestBase.php \Drupal\rdf\Tests\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/src/Tests/Field/DateTimeFieldRdfaTest.php
Tests the default formatter.
EmailFieldRdfaTest::testAllFormatters in core/modules/rdf/src/Tests/Field/EmailFieldRdfaTest.php
Tests all email formatters.
EntityReferenceRdfaTest::testAllFormatters in core/modules/rdf/src/Tests/Field/EntityReferenceRdfaTest.php
Tests all the entity reference formatters.
FieldRdfaDatatypeCallbackTest::testDefaultFormatter in core/modules/rdf/src/Tests/Field/FieldRdfaDatatypeCallbackTest.php
Tests the default formatter.
LinkFieldRdfaTest::runTestAllFormatters in core/modules/rdf/src/Tests/Field/LinkFieldRdfaTest.php
Helper function to test all link formatters.

... See full list

File

core/modules/rdf/src/Tests/Field/FieldRdfaTestBase.php, line 87
Contains \Drupal\rdf\Tests\Field\FieldRdfaTestBase.

Class

FieldRdfaTestBase

Namespace

Drupal\rdf\Tests\Field

Code

protected function assertFormatterRdfa($formatter, $property, $expected_rdf_value) {
  $expected_rdf_value += array(
    'type' => 'literal',
  );

  // The field formatter will be rendered inside the entity. Set the field
  // formatter in the entity display options before rendering the entity.
  entity_get_display('entity_test', 'entity_test', 'default')
    ->setComponent($this->fieldName, $formatter)
    ->save();
  $build = entity_view($this->entity, 'default');
  $output = \Drupal::service('renderer')
    ->renderRoot($build);
  $graph = new \EasyRdf_Graph($this->uri, $output, 'rdfa');
  $this
    ->setRawContent($output);

  // If verbose debugging is turned on, display the HTML and parsed RDF
  // in the results.
  if ($this->debug) {
    debug($output);
    debug($graph
      ->toRdfPhp());
  }
  $this
    ->assertTrue($graph
    ->hasProperty($this->uri, $property, $expected_rdf_value), "Formatter {$formatter['type']} exposes data correctly for {$this->fieldType} fields.");
}