You are here

function FileFieldAttributesTest::testNodeTeaser in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/rdf/src/Tests/FileFieldAttributesTest.php \Drupal\rdf\Tests\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/src/Tests/FileFieldAttributesTest.php, line 81
Contains \Drupal\rdf\Tests\FileFieldAttributesTest.

Class

FileFieldAttributesTest
Tests the RDFa markup of filefields.

Namespace

Drupal\rdf\Tests

Code

function testNodeTeaser() {

  // Render the teaser.
  $node_render_array = entity_view_multiple(array(
    $this->node,
  ), 'teaser');
  $html = \Drupal::service('renderer')
    ->renderRoot($node_render_array);

  // Parses front page where the node is displayed in its teaser form.
  $parser = new \EasyRdf_Parser_Rdfa();
  $graph = new \EasyRdf_Graph();
  $base_uri = \Drupal::url('<front>', [], [
    'absolute' => TRUE,
  ]);
  $parser
    ->parse($graph, $html, 'rdfa', $base_uri);
  $node_uri = $this->node
    ->url('canonical', [
    'absolute' => TRUE,
  ]);
  $file_uri = file_create_url($this->file
    ->getFileUri());

  // Node relation to attached file.
  $expected_value = array(
    'type' => 'uri',
    'value' => $file_uri,
  );
  $this
    ->assertTrue($graph
    ->hasProperty($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');
}