You are here

public function FileFieldAttributesTest::testNodeTeaser in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/rdf/tests/src/Functional/FileFieldAttributesTest.php \Drupal\Tests\rdf\Functional\FileFieldAttributesTest::testNodeTeaser()
  2. 10 core/modules/rdf/tests/src/Functional/FileFieldAttributesTest.php \Drupal\Tests\rdf\Functional\FileFieldAttributesTest::testNodeTeaser()

Tests if file fields in teasers have correct resources.

Ensure that file fields have the correct resource as the object in RDFa when displayed as a teaser.

File

core/modules/rdf/tests/src/Functional/FileFieldAttributesTest.php, line 96

Class

FileFieldAttributesTest
Tests the RDFa markup of filefields.

Namespace

Drupal\Tests\rdf\Functional

Code

public function testNodeTeaser() {

  // Render the teaser.
  $node_render_array = \Drupal::entityTypeManager()
    ->getViewBuilder('node')
    ->view($this->node, 'teaser');
  $html = \Drupal::service('renderer')
    ->renderRoot($node_render_array);
  $node_uri = $this->node
    ->toUrl('canonical', [
    'absolute' => TRUE,
  ])
    ->toString();
  $file_uri = $this->file
    ->createFileUrl(FALSE);

  // Node relation to attached file.
  $expected_value = [
    'type' => 'uri',
    'value' => $file_uri,
  ];
  $this
    ->assertTrue($this
    ->hasRdfProperty($html, $this->baseUri, $node_uri, 'http://www.w3.org/2000/01/rdf-schema#seeAlso', $expected_value), 'Node to file relation found in RDF output (rdfs:seeAlso).');
  $this
    ->drupalGet('node');
}